PARSER_BEGIN(Q3) public class Q3 { /*** Main routine - just call parser ***/ public static void main(String args[]) throws ParseException { Q3 parser = new Q3(System.in); try { String res = parser.s(); if (res != null) System.out.println("Answer is: " + res); } catch (ParseException x) { System.out.println("Exiting due to parse error."); throw x; } } } PARSER_END(Q3) SKIP : /*** Ignoring spaces/tabs/newlines ***/ { " " | "\t" | "\n" | "\r" | "\f" } TOKEN : { < CONCAT : "+" > | < TAIL : "-" > | < LBR : "(" > | < RBR : ")" > | < STRING : ()+ > | < #LETTER : ["a"-"z","A"-"Z"] > } /*************************/ /***** GRAMMAR RULES *****/ /*************************/ String s() : { String s; } { s=e() { return s; } } String e() : { String s1, s2; } { s1=t() ( s2=t() { s1 = s1+s2;} )* { return s1; } } String t() : { String s; Token t ; } { s=t() { return s.substring(1,s.length()); } | t= { return t.image; } | s=e() { return s; } }