/* expr/javacc/Exprparlex.jj in JavaCC format. Build with javacc Exprparlex.jj javac *.java Run as java Expr Enter e.g. 4 * 3 followed on Unix or on Windows. You get a response from the program only if you make a syntax error. */ PARSER_BEGIN(Expr) public class Expr { public static void main(String args[]) throws ParseException { Expr parser = new Expr(System.in); System.out.print("Enter Expression: "); parser.Main(); } } PARSER_END(Expr) SKIP : { " " | "\r" | "\n" | "\t" } TOKEN : { < PLUS : "+" > | < MINUS : "-" > | < TIMES : "*" > } TOKEN : { < LET : "let" > | < IN : "in" > | < END : "end" > } TOKEN : /* constants and variables */ { < CSTINT : ( )+ > | < #DIGIT : ["0" - "9"] > | < NAME : ( | )* > | < #LETTER : ["a"-"z", "A"-"Z"] > } void Main() : {} { Expr() } void Expr() : {} { Term() ( ( | ) Term() )* } void Term() : { } { Factor() ( Factor() )* } void Factor() : { } { | | | "(" Expr() ")" | "=" Expr() Expr() }