PARSER_BEGIN(Q2) class Q2 { /** Standard code to call the parser */ public static void main(String args[]) { Q2 parser; System.out.println("Reading from standard input . . ."); parser = new Q2(System.in); try { boolean res = parser.s(); System.out.println("The answer is: "+res); } catch (ParseException e) { System.out.println("Encountered errors during parse."); } } /* End of function "main" */ } PARSER_END(Q2) /******************/ /***** TOKENS *****/ /******************/ SKIP : /* WHITE SPACE */ { " " | "\t" | "\n" | "\r" | "\f" } TOKEN : { < AND : "and" > | < IMPLIES : "=>" > | < TRUE : "true" > | < FALSE : "false" > | < LBR : "(" > | < RBR : ")" > } /*************************/ /***** GRAMMAR RULES *****/ /*************************/ boolean s() : { boolean b; } { b=e() { return b; } } boolean e() : { boolean b1, b2; } { b1=t() ( b2=t() { b1 = b1 & b2; } )* { return b1; } } boolean t() : { boolean b1, b2; } { b1=f() ( b2=f() { b1 = !(b1 & !b2); } )* { return b1; } } boolean f() : { boolean b; } { { return true; } | { return false; } | b=e() { return b; } }