Hello.<div><br></div><div>I'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've sucessfully implemented the lexer using Parsec. It has the type String -> Parser [MJVal], where MJVal are all the possible tokens.</div>
<div><br></div><div>However, I don'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 = "program" ident {ConstDecl | VarDecl | ClassDecl}<div> "{" {MethodDecl} "}".</div><div><br></div><div>The natural solution (for me) would be:</div><div><br></div>
<div>program = do</div><div> string "program"</div><div> programName <- identifier</div><div> ...</div><div><br></div><div>However, I can't do this because the file is already tokenized, what I have is something like:</div>
<div>[Program_, identifier_ "testProgram", 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 "Haskell way"?</div>
<div><br></div>Fernando Henrique Sanches<br>
</div>