PARSER_BEGIN(Q3) class Q3 { /** Standard code to call the parser */ public static void main(String args[]) { Q3 parser; System.out.println("Reading from standard input . . ."); parser = new Q3(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(Q3) /******************/ /***** TOKENS *****/ /******************/ SKIP : /* WHITE SPACE */ { " " | "\t" | "\n" | "\r" } TOKEN : { < AND : "and" > | < OR : "or" > | < TRUE : "true" > | < FALSE : "false" > | < LBR : "(" > | < RBR : ")" > } /*************************/ /***** GRAMMAR RULES *****/ /*************************/ boolean s() : { boolean b; } { b=e() { return b; } } boolean e() : { boolean b1, b2=false; } { b1=t() [ b2=t() ] { return (b1 || b2); } } boolean t() : { boolean b1, b2=true; } { b1=f() [ b2=f() ] { return (b1 && b2); } } boolean f() : { boolean b; } { { return true; } | { return false; } | b=e() { return b; } }