Hello.<div><br></div><div>I&#39;m currently implementing a MicroJava compiler for a college assignment (the implemented language was defined, the implementation language was of free choice).</div><div><br></div><div>I&#39;ve sucessfully implemented the lexer using Parsec. It has the type String -&gt; Parser [MJVal], where MJVal are all the possible tokens.</div>
<div><br></div><div>However, I don&#39;t know how to implement the parser, or at least how to do it keeping it distinguished from the lexer.</div><div><br></div><div>For example, the MicroJava grammar specifies:</div><div>
<br></div><div>Program = &quot;program&quot; ident {ConstDecl | VarDecl | ClassDecl}<div>          &quot;{&quot; {MethodDecl} &quot;}&quot;.</div><div><br></div><div>The natural solution (for me) would be:</div><div><br></div>
<div>program = do</div><div>  string &quot;program&quot;</div><div>  programName &lt;- identifier</div><div>  ...</div><div><br></div><div>However, I can&#39;t do this because the file is already tokenized, what I have is something like:</div>
<div>[Program_, identifier_ &quot;testProgram&quot;, lBrace_, ...]</div><div>for the example program:</div><div><br></div><div>program testProgram {</div><div>...</div><div><br></div><div>How should I implement the parser separated from the lexer? That is, how should I parse Tokens instead of Strings in the &quot;Haskell way&quot;?</div>
<div><br></div>Fernando Henrique Sanches<br>
</div>