import java_cup.runtime.*; import java.util.*; parser code {: public LinkedList lst = new LinkedList(); public void report_error(String message, Object info) { StringBuffer m = new StringBuffer("Error"); if (info instanceof java_cup.runtime.Symbol) { java_cup.runtime.Symbol s = ((java_cup.runtime.Symbol) info); if (s.left >= 0) { m.append(" in line "+(s.left+1)); if (s.right >= 0) m.append(", column "+(s.right+1)); } } m.append(" : "+message); System.err.println(m); } public void report_fatal_error(String message, Object info) throws Exception { report_error(message, info); Exception e=null; throw e; //System.exit(1); } :}; terminal COMMA, BAR, LPAREN, RPAREN, LBRACE, RBRACE, ERROR, EXISTS, FORALL, AND, OR, NOT; terminal String COMPARISON, NUMBER, STRING, NAME; non terminal DRCNode Query, Formula,AtomicFormula; non terminal Vector ArgList, VarList, Arg; /* -------------Precedence and Associatively of Terminals Section----------- */ precedence right AND, OR; /* ----------------------------Grammar Section-------------------- */ /* The grammar for our parser. Query ::= LBRACE VarList BAR Formula RBRACE; VarList ::= NAME | VarList COMMA NAME; Formula ::= AtomicFormula |Formula AND Formula |Formula OR Formula | NOT LPAREN Formula RPAREN |LPAREN EXISTS VarList RPAREN LPAREN Formula RPAREN | LPAREN FORALL VarList RPAREN LPAREN Formula RPAREN ; AtomicFormula ::= NAME LPAREN ArgList RPAREN |Arg COMPARISON Arg; ArgList ::= Arg | ArgList COMMA Arg; Arg ::= NAME | STRING | NUMBER; */ Query ::= LBRACE VarList:vlval BAR Formula:fval RBRACE {: DRCNode rnode = new DRCNode(); rnode.setRnodetype("query"); rnode.setVarlist(vlval); rnode.setLchild(fval); RESULT = rnode; :} ; VarList ::= NAME:nval {: Vector v = new Vector(); v.addElement(nval); RESULT = v; :} | VarList:vlval COMMA NAME:nval {: vlval.addElement(nval); RESULT = vlval; :} ; Formula ::= AtomicFormula:atval {: RESULT = atval; :} | //LPAREN Formula:fval1 AND Formula:fval2 RPAREN Formula:fval1 AND Formula:fval2 {: DRCNode rnode = new DRCNode(); rnode.setRnodetype("and"); rnode.setLchild(fval1); rnode.setRchild(fval2); RESULT = rnode; :} | //LPAREN Formula:fval1 OR Formula:fval2 RPAREN Formula:fval1 OR Formula:fval2 {: DRCNode rnode = new DRCNode(); rnode.setRnodetype("or"); rnode.setLchild(fval1); rnode.setRchild(fval2); RESULT = rnode; :} | NOT LPAREN Formula:fval RPAREN {: DRCNode rnode = new DRCNode(); rnode.setRnodetype("not"); rnode.setLchild(fval); RESULT = rnode; :} | LPAREN EXISTS VarList:vlval RPAREN LPAREN Formula:fval RPAREN {: DRCNode rnode = new DRCNode(); rnode.setRnodetype("exists"); rnode.setVarlist(vlval); rnode.setLchild(fval); RESULT = rnode; :} | LPAREN FORALL VarList:vlval RPAREN LPAREN Formula:fval RPAREN {: DRCNode rnode = new DRCNode(); DRCNode rnode2 = new DRCNode(); DRCNode rnode3 = new DRCNode(); rnode3.setRnodetype("not"); rnode3.setLchild(fval); rnode2.setRnodetype("exists"); rnode2.setVarlist(vlval); rnode2.setLchild(rnode3); rnode.setRnodetype("not"); rnode.setLchild(rnode2); RESULT = rnode; :} ; AtomicFormula ::= NAME:nval LPAREN ArgList:alval RPAREN {: DRCNode rnode = new DRCNode(); rnode.setRnodetype("predicate"); rnode.setRelationName(nval); rnode.setArguments(alval); RESULT = rnode; :} | Arg:aval1 COMPARISON:cval Arg:aval2 {: DRCNode rnode = new DRCNode(); rnode.setRnodetype("comp"); rnode.addLeftOperand((String)aval1.get(0)); rnode.addLeftDataType((String)aval1.get(1)); rnode.addOperator(cval); rnode.addRightOperand((String)aval2.get(0)); rnode.addRightDataType((String)aval2.get(1)); RESULT = rnode; :} ; ArgList ::= Arg:aval {: Vector v = new Vector(); v.addElement(aval); RESULT = v; :} | ArgList:alval COMMA Arg:aval {: alval.addElement(aval); RESULT = alval; :} ; Arg ::= NAME:nval {: Vector ov = new Vector(); ov.addElement(nval); ov.addElement("col"); RESULT = ov; :} | STRING:sval {: Vector ov = new Vector(); ov.addElement(sval); ov.addElement("str"); RESULT = ov; :} | NUMBER:xval {: Vector ov = new Vector(); ov.addElement(xval); ov.addElement("num"); RESULT = ov; :} ;