options { IGNORE_CASE=true; MULTI=true; // This will generate one AST class for each non-suppressed non-terminal VISITOR=true; // This won't be used until the next assignment, but will be needed to make your assignment compile properly JJTREE_OUTPUT_DIRECTORY="AST"; // This will put all your AST classes in the AST directory } PARSER_BEGIN(HL) public class HL { } PARSER_END(HL) TOKEN_MGR_DECLS : { } SKIP : { " " | "\t" | "\n" | "\r" } TOKEN : { < PRINT:"PRINT"> | < ERR:"ERR"> | < INTEGER: (["0"-"9"])+ > } // =========================================================================== // P A R S E R // =========================================================================== SimpleNode start () #void : {} { statement() { return (SimpleNode) (jjtree.popNode()); } | < EOF > {throw new ParseException("End of File.");} } void statement() #void : {} { assignment() ";" | print_stat() ";" } void assignment () : {} { Identifier() "=" expression() } void print_stat() #void : {} { (print_stdout() | print_stderr()) } void print_stdout() #void : {} { expression() #print(1) } void print_stderr() #void: {} { expression() #print_err(1) } void expression() #void : {} { (product() ("+" product())*) #sum(>1) } void product() #void : {} { (term() ("*" term())*) #product(>1) } void term() #void : {} { Identifier() | Integer() } void Identifier() #void : {} { "a" #a | "b" #b | "c" #c } void Integer () : {Token t;} { t= {jjtThis.jjtSetValue(t.getValue());} }