Hello,<br>See the following code. It allows you to compute multiple attributes and access them too. I don't know a better and simpler method than this to serve this purpose. Waiting for inputs from experts.<br>---------------------------------<br>
<span style="font-family:courier new,monospace">{</span><br style="font-family:courier new,monospace">
<span style="font-family:courier new,monospace">module BitsParser (parse) where</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace">test = parse "1011\n"</span><br style="font-family:courier new,monospace">
<br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace">-- how to write the list attribute to a file here?</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace">test2 = writeFile "testOutFile" (show $ snd test)</span><br style="font-family:courier new,monospace">
<span style="font-family:courier new,monospace"> </span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace">data Dirs = MyLeft | MyRight deriving Show</span><br style="font-family:courier new,monospace">
<span style="font-family:courier new,monospace">fun a b = a^b</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace">}</span><br style="font-family:courier new,monospace"><br style="font-family:courier new,monospace">
<span style="font-family:courier new,monospace">%tokentype { Char }</span><br style="font-family:courier new,monospace"><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace">%token minus { '-' }</span><br style="font-family:courier new,monospace">
<span style="font-family:courier new,monospace">%token plus { '+' }</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace">%token one { '1' }</span><br style="font-family:courier new,monospace">
<span style="font-family:courier new,monospace">%token zero { '0' }</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace">%token newline { '\n' }</span><br style="font-family:courier new,monospace">
<br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace">%attributetype { Attrs }</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace">%attribute value { (Integer, [Dirs]) }</span><br style="font-family:courier new,monospace">
<span style="font-family:courier new,monospace">%attribute pos { Int }</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace">%attribute list { [Dirs] }</span><br style="font-family:courier new,monospace">
<br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace">%name parse start</span><br style="font-family:courier new,monospace"><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace">%%</span><br style="font-family:courier new,monospace">
<br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace">start</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace"> : num newline { $$ = $1 }</span><br style="font-family:courier new,monospace">
<br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace">num</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace"> : bits { $$ = $1 ; $1.pos = 0 ; $1.list = [] }</span><br style="font-family:courier new,monospace">
<span style="font-family:courier new,monospace"> | plus bits { $$ = $2 ; $2.pos = 0 ; $2.list = [] }</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace"> | minus bits { $$ = (negate (fst $2), snd $2) ; $2.pos = 0 ; $2.list = [] }</span><br style="font-family:courier new,monospace">
<br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace">bits</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace"> : bit { $$ = $1</span><br style="font-family:courier new,monospace">
<span style="font-family:courier new,monospace"> ; $1.pos = $$.pos ; $1.list = $$.list</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace"> }</span><br style="font-family:courier new,monospace">
<br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace"> | bits bit { $$ = myComputeAttrFun $1 $2; $$.list = $1.list ++ $2.list</span><br style="font-family:courier new,monospace">
<span style="font-family:courier new,monospace"> ; $1.pos = $$.pos + 1</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace"> ; $2.pos = $$.pos</span><br style="font-family:courier new,monospace">
<span style="font-family:courier new,monospace"> }</span><br style="font-family:courier new,monospace"><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace">bit</span><br style="font-family:courier new,monospace">
<span style="font-family:courier new,monospace"> : zero { $$ = (0, [MyLeft]) ; $$.list = [MyLeft] }</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace"> | one { $$ = (fun 2 ($$.pos), [MyRight]) ; $$.list = [MyRight] }</span><br style="font-family:courier new,monospace">
<span style="font-family:courier new,monospace"> </span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace">{</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace">myComputeAttrFun a b = (c, d)</span><br style="font-family:courier new,monospace">
<span style="font-family:courier new,monospace"> where </span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace"> c = fst a + fst b</span><br style="font-family:courier new,monospace">
<span style="font-family:courier new,monospace"> d = snd a ++ snd b </span><br style="font-family:courier new,monospace"><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace">happyError = error "parse error"</span><br style="font-family:courier new,monospace">
<span style="font-family:courier new,monospace">}</span><br style="font-family:courier new,monospace">---------------------------------<br><span style="font-family:courier new,monospace"></span><br><span class="HOEnZb"><font color="#888888">-- <br>
Thanks and regards,<br>-Damodar Kulkarni</font></span><br><br><br>