package Parse; action code {: static Symbol.Symbol sym(String s) { return Symbol.Symbol.symbol(s); } :}; parser code {: Lexer lexer; public void syntax_error(token current) { report_error("Syntax error (" + current.sym + ")", (Token)current); } ErrorMsg.ErrorMsg errorMsg; public void report_error(String message, Token tok) { errorMsg.error(tok.left, message); } public Grm(Lexer l, ErrorMsg.ErrorMsg err) { this(); errorMsg=err; lexer=l; } :}; scan with {: return lexer.nextToken(); :}; terminal String ID, STRING; terminal Integer INT; terminal COMMA, COLON, SEMICOLON, LPAREN, RPAREN, LBRACK, RBRACK, LBRACE, RBRACE, DOT, PLUS, MINUS, TIMES, DIVIDE, EQ, NEQ, LT, LE, GT, GE, AND, OR, ASSIGN, ARRAY, IF, THEN, ELSE, WHILE, FOR, TO, DO, LET, IN, END, OF, BREAK, NIL, FUNCTION, VAR, TYPE; non terminal program; non terminal decs, dec, tydec, ty, tyfields, vardec, fundec; non terminal lvalue, exp, moretyfields; non terminal seqexp; start with program; program ::= exp; decs ::= dec decs | {: /* null production */ :}; dec ::= tydec | vardec | fundec; tydec ::= TYPE ID EQ ty; ty ::= ID | LBRACE tyfields RBRACE | ARRAY OF ID; tyfields ::= | ID COLON ID moretyfields; moretyfields ::= | COMMA ID COLON ID moretyfields; vardec ::= VAR ID ASSIGN exp | VAR ID COLON ID ASSIGN exp; fundec ::= FUNCTION ID LPAREN tyfields RPAREN EQ exp | FUNCTION ID COLON ID LPAREN tyfields RPAREN EQ exp; exp ::= lvalue | NIL | LPAREN seqexp RPAREN | LPAREN RPAREN | IF exp THEN exp | IF exp THEN exp ELSE exp; seqexp ::= exp SEMICOLON exp | exp SEMICOLON seqexp;