//---------------------------------------------------- // The following code was generated by CUP v0.11b 20150326 (SVN rev 63) //---------------------------------------------------- package ar.com.javacuriosities.calculator.parser; import java_cup.runtime.*; import ar.com.javacuriosities.calculator.model.*; import java_cup.runtime.XMLElement; /** CUP v0.11b 20150326 (SVN rev 63) generated parser. */ @SuppressWarnings({"rawtypes"}) public class ArithmeticParser extends java_cup.runtime.lr_parser { public final Class getSymbolContainer() { return ArithmeticSymbols.class; } /** Default constructor. */ @Deprecated public ArithmeticParser() {super();} /** Constructor which sets the default scanner. */ @Deprecated public ArithmeticParser(java_cup.runtime.Scanner s) {super(s);} /** Constructor which sets the default scanner. */ public ArithmeticParser(java_cup.runtime.Scanner s, java_cup.runtime.SymbolFactory sf) {super(s,sf);} /** Production table. */ protected static final short _production_table[][] = unpackFromStrings(new String[] { "\000\014\000\002\002\004\000\002\002\004\000\002\002" + "\003\000\002\003\004\000\002\004\005\000\002\004\005" + "\000\002\004\003\000\002\005\005\000\002\005\005\000" + "\002\005\003\000\002\006\005\000\002\006\003" }); /** Access to production table. */ public short[][] production_table() {return _production_table;} /** Parse-action table. */ protected static final short[][] _action_table = unpackFromStrings(new String[] { "\000\025\000\006\004\011\011\004\001\002\000\006\004" + "\011\011\004\001\002\000\010\002\025\004\011\011\004" + "\001\002\000\010\002\uffff\004\uffff\011\uffff\001\002\000" + "\010\005\020\006\021\013\017\001\002\000\016\005\ufff8" + "\006\ufff8\007\ufff8\010\ufff8\012\ufff8\013\ufff8\001\002\000" + "\016\005\ufff6\006\ufff6\007\ufff6\010\ufff6\012\ufff6\013\ufff6" + "\001\002\000\016\005\ufffb\006\ufffb\007\013\010\014\012" + "\ufffb\013\ufffb\001\002\000\006\004\011\011\004\001\002" + "\000\006\004\011\011\004\001\002\000\016\005\ufff9\006" + "\ufff9\007\ufff9\010\ufff9\012\ufff9\013\ufff9\001\002\000\016" + "\005\ufffa\006\ufffa\007\ufffa\010\ufffa\012\ufffa\013\ufffa\001" + "\002\000\010\002\ufffe\004\ufffe\011\ufffe\001\002\000\006" + "\004\011\011\004\001\002\000\006\004\011\011\004\001" + "\002\000\016\005\ufffc\006\ufffc\007\013\010\014\012\ufffc" + "\013\ufffc\001\002\000\016\005\ufffd\006\ufffd\007\013\010" + "\014\012\ufffd\013\ufffd\001\002\000\010\002\000\004\000" + "\011\000\001\002\000\004\002\001\001\002\000\010\005" + "\020\006\021\012\027\001\002\000\016\005\ufff7\006\ufff7" + "\007\ufff7\010\ufff7\012\ufff7\013\ufff7\001\002" }); /** Access to parse-action table. */ public short[][] action_table() {return _action_table;} /** <code>reduce_goto</code> table. */ protected static final short[][] _reduce_table = unpackFromStrings(new String[] { "\000\025\000\014\002\004\003\005\004\006\005\011\006" + "\007\001\001\000\010\004\025\005\011\006\007\001\001" + "\000\012\003\023\004\006\005\011\006\007\001\001\000" + "\002\001\001\000\002\001\001\000\002\001\001\000\002" + "\001\001\000\002\001\001\000\004\006\015\001\001\000" + "\004\006\014\001\001\000\002\001\001\000\002\001\001" + "\000\002\001\001\000\006\005\022\006\007\001\001\000" + "\006\005\021\006\007\001\001\000\002\001\001\000\002" + "\001\001\000\002\001\001\000\002\001\001\000\002\001" + "\001\000\002\001\001" }); /** Access to <code>reduce_goto</code> table. */ public short[][] reduce_table() {return _reduce_table;} /** Instance of action encapsulation class. */ protected CUP$ArithmeticParser$actions action_obj; /** Action encapsulation object initializer. */ protected void init_actions() { action_obj = new CUP$ArithmeticParser$actions(this); } /** Invoke a user supplied parse action. */ public java_cup.runtime.Symbol do_action( int act_num, java_cup.runtime.lr_parser parser, java.util.Stack stack, int top) throws java.lang.Exception { /* call code in generated class */ return action_obj.CUP$ArithmeticParser$do_action(act_num, parser, stack, top); } /** Indicates start state. */ public int start_state() {return 0;} /** Indicates start production. */ public int start_production() {return 0;} /** <code>EOF</code> Symbol index. */ public int EOF_sym() {return 0;} /** <code>error</code> Symbol index. */ public int error_sym() {return 1;} // public static void main(String args[]) throws Exception { // new parser(new ArithmeticLexer(System.in)).parse(); // } /** Cup generated class to encapsulate user supplied action code.*/ @SuppressWarnings({"rawtypes", "unchecked", "unused"}) class CUP$ArithmeticParser$actions { private final ArithmeticParser parser; /** Constructor */ CUP$ArithmeticParser$actions(ArithmeticParser parser) { this.parser = parser; } /** Method 0 with the actual generated action code for actions 0 to 300. */ public final java_cup.runtime.Symbol CUP$ArithmeticParser$do_action_part00000000( int CUP$ArithmeticParser$act_num, java_cup.runtime.lr_parser CUP$ArithmeticParser$parser, java.util.Stack CUP$ArithmeticParser$stack, int CUP$ArithmeticParser$top) throws java.lang.Exception { /* Symbol object for return from actions */ java_cup.runtime.Symbol CUP$ArithmeticParser$result; /* select the action based on the action number */ switch (CUP$ArithmeticParser$act_num) { /*. . . . . . . . . . . . . . . . . . . .*/ case 0: // $START ::= Document EOF { Object RESULT =null; int start_valleft = ((java_cup.runtime.Symbol)CUP$ArithmeticParser$stack.elementAt(CUP$ArithmeticParser$top-1)).left; int start_valright = ((java_cup.runtime.Symbol)CUP$ArithmeticParser$stack.elementAt(CUP$ArithmeticParser$top-1)).right; Document start_val = (Document)((java_cup.runtime.Symbol) CUP$ArithmeticParser$stack.elementAt(CUP$ArithmeticParser$top-1)).value; RESULT = start_val; CUP$ArithmeticParser$result = parser.getSymbolFactory().newSymbol("$START",0, ((java_cup.runtime.Symbol)CUP$ArithmeticParser$stack.elementAt(CUP$ArithmeticParser$top-1)), ((java_cup.runtime.Symbol)CUP$ArithmeticParser$stack.peek()), RESULT); } /* ACCEPT */ CUP$ArithmeticParser$parser.done_parsing(); return CUP$ArithmeticParser$result; /*. . . . . . . . . . . . . . . . . . . .*/ case 1: // Document ::= Document ExpressionLine { Document RESULT =null; int prevDocumentleft = ((java_cup.runtime.Symbol)CUP$ArithmeticParser$stack.elementAt(CUP$ArithmeticParser$top-1)).left; int prevDocumentright = ((java_cup.runtime.Symbol)CUP$ArithmeticParser$stack.elementAt(CUP$ArithmeticParser$top-1)).right; Document prevDocument = (Document)((java_cup.runtime.Symbol) CUP$ArithmeticParser$stack.elementAt(CUP$ArithmeticParser$top-1)).value; int exprleft = ((java_cup.runtime.Symbol)CUP$ArithmeticParser$stack.peek()).left; int exprright = ((java_cup.runtime.Symbol)CUP$ArithmeticParser$stack.peek()).right; Expression expr = (Expression)((java_cup.runtime.Symbol) CUP$ArithmeticParser$stack.peek()).value; Document document = new Document(prevDocument); document.addExpression(expr); RESULT = document; CUP$ArithmeticParser$result = parser.getSymbolFactory().newSymbol("Document",0, ((java_cup.runtime.Symbol)CUP$ArithmeticParser$stack.elementAt(CUP$ArithmeticParser$top-1)), ((java_cup.runtime.Symbol)CUP$ArithmeticParser$stack.peek()), RESULT); } return CUP$ArithmeticParser$result; /*. . . . . . . . . . . . . . . . . . . .*/ case 2: // Document ::= ExpressionLine { Document RESULT =null; int exprleft = ((java_cup.runtime.Symbol)CUP$ArithmeticParser$stack.peek()).left; int exprright = ((java_cup.runtime.Symbol)CUP$ArithmeticParser$stack.peek()).right; Expression expr = (Expression)((java_cup.runtime.Symbol) CUP$ArithmeticParser$stack.peek()).value; Document document = new Document(); document.addExpression(expr); RESULT = document; CUP$ArithmeticParser$result = parser.getSymbolFactory().newSymbol("Document",0, ((java_cup.runtime.Symbol)CUP$ArithmeticParser$stack.peek()), ((java_cup.runtime.Symbol)CUP$ArithmeticParser$stack.peek()), RESULT); } return CUP$ArithmeticParser$result; /*. . . . . . . . . . . . . . . . . . . .*/ case 3: // ExpressionLine ::= PlusOrSubtractExpression SEMICOLON { Expression RESULT =null; int exprleft = ((java_cup.runtime.Symbol)CUP$ArithmeticParser$stack.elementAt(CUP$ArithmeticParser$top-1)).left; int exprright = ((java_cup.runtime.Symbol)CUP$ArithmeticParser$stack.elementAt(CUP$ArithmeticParser$top-1)).right; Expression expr = (Expression)((java_cup.runtime.Symbol) CUP$ArithmeticParser$stack.elementAt(CUP$ArithmeticParser$top-1)).value; RESULT = expr; CUP$ArithmeticParser$result = parser.getSymbolFactory().newSymbol("ExpressionLine",1, ((java_cup.runtime.Symbol)CUP$ArithmeticParser$stack.elementAt(CUP$ArithmeticParser$top-1)), ((java_cup.runtime.Symbol)CUP$ArithmeticParser$stack.peek()), RESULT); } return CUP$ArithmeticParser$result; /*. . . . . . . . . . . . . . . . . . . .*/ case 4: // PlusOrSubtractExpression ::= PlusOrSubtractExpression PLUS MultiplicationOrDivisionExpression { Expression RESULT =null; int lhsleft = ((java_cup.runtime.Symbol)CUP$ArithmeticParser$stack.elementAt(CUP$ArithmeticParser$top-2)).left; int lhsright = ((java_cup.runtime.Symbol)CUP$ArithmeticParser$stack.elementAt(CUP$ArithmeticParser$top-2)).right; Expression lhs = (Expression)((java_cup.runtime.Symbol) CUP$ArithmeticParser$stack.elementAt(CUP$ArithmeticParser$top-2)).value; int rhsleft = ((java_cup.runtime.Symbol)CUP$ArithmeticParser$stack.peek()).left; int rhsright = ((java_cup.runtime.Symbol)CUP$ArithmeticParser$stack.peek()).right; Expression rhs = (Expression)((java_cup.runtime.Symbol) CUP$ArithmeticParser$stack.peek()).value; RESULT = new PlusExpression(lhs, rhs); CUP$ArithmeticParser$result = parser.getSymbolFactory().newSymbol("PlusOrSubtractExpression",2, ((java_cup.runtime.Symbol)CUP$ArithmeticParser$stack.elementAt(CUP$ArithmeticParser$top-2)), ((java_cup.runtime.Symbol)CUP$ArithmeticParser$stack.peek()), RESULT); } return CUP$ArithmeticParser$result; /*. . . . . . . . . . . . . . . . . . . .*/ case 5: // PlusOrSubtractExpression ::= PlusOrSubtractExpression SUBTRACT MultiplicationOrDivisionExpression { Expression RESULT =null; int lhsleft = ((java_cup.runtime.Symbol)CUP$ArithmeticParser$stack.elementAt(CUP$ArithmeticParser$top-2)).left; int lhsright = ((java_cup.runtime.Symbol)CUP$ArithmeticParser$stack.elementAt(CUP$ArithmeticParser$top-2)).right; Expression lhs = (Expression)((java_cup.runtime.Symbol) CUP$ArithmeticParser$stack.elementAt(CUP$ArithmeticParser$top-2)).value; int rhsleft = ((java_cup.runtime.Symbol)CUP$ArithmeticParser$stack.peek()).left; int rhsright = ((java_cup.runtime.Symbol)CUP$ArithmeticParser$stack.peek()).right; Expression rhs = (Expression)((java_cup.runtime.Symbol) CUP$ArithmeticParser$stack.peek()).value; RESULT = new SubtractExpression(lhs, rhs); CUP$ArithmeticParser$result = parser.getSymbolFactory().newSymbol("PlusOrSubtractExpression",2, ((java_cup.runtime.Symbol)CUP$ArithmeticParser$stack.elementAt(CUP$ArithmeticParser$top-2)), ((java_cup.runtime.Symbol)CUP$ArithmeticParser$stack.peek()), RESULT); } return CUP$ArithmeticParser$result; /*. . . . . . . . . . . . . . . . . . . .*/ case 6: // PlusOrSubtractExpression ::= MultiplicationOrDivisionExpression { Expression RESULT =null; int exprleft = ((java_cup.runtime.Symbol)CUP$ArithmeticParser$stack.peek()).left; int exprright = ((java_cup.runtime.Symbol)CUP$ArithmeticParser$stack.peek()).right; Expression expr = (Expression)((java_cup.runtime.Symbol) CUP$ArithmeticParser$stack.peek()).value; RESULT = expr; CUP$ArithmeticParser$result = parser.getSymbolFactory().newSymbol("PlusOrSubtractExpression",2, ((java_cup.runtime.Symbol)CUP$ArithmeticParser$stack.peek()), ((java_cup.runtime.Symbol)CUP$ArithmeticParser$stack.peek()), RESULT); } return CUP$ArithmeticParser$result; /*. . . . . . . . . . . . . . . . . . . .*/ case 7: // MultiplicationOrDivisionExpression ::= MultiplicationOrDivisionExpression MULTIPLICATION NumberExpression { Expression RESULT =null; int lhsleft = ((java_cup.runtime.Symbol)CUP$ArithmeticParser$stack.elementAt(CUP$ArithmeticParser$top-2)).left; int lhsright = ((java_cup.runtime.Symbol)CUP$ArithmeticParser$stack.elementAt(CUP$ArithmeticParser$top-2)).right; Expression lhs = (Expression)((java_cup.runtime.Symbol) CUP$ArithmeticParser$stack.elementAt(CUP$ArithmeticParser$top-2)).value; int rhsleft = ((java_cup.runtime.Symbol)CUP$ArithmeticParser$stack.peek()).left; int rhsright = ((java_cup.runtime.Symbol)CUP$ArithmeticParser$stack.peek()).right; Expression rhs = (Expression)((java_cup.runtime.Symbol) CUP$ArithmeticParser$stack.peek()).value; RESULT = new MultiplicationExpression(lhs, rhs); CUP$ArithmeticParser$result = parser.getSymbolFactory().newSymbol("MultiplicationOrDivisionExpression",3, ((java_cup.runtime.Symbol)CUP$ArithmeticParser$stack.elementAt(CUP$ArithmeticParser$top-2)), ((java_cup.runtime.Symbol)CUP$ArithmeticParser$stack.peek()), RESULT); } return CUP$ArithmeticParser$result; /*. . . . . . . . . . . . . . . . . . . .*/ case 8: // MultiplicationOrDivisionExpression ::= MultiplicationOrDivisionExpression DIVISION NumberExpression { Expression RESULT =null; int lhsleft = ((java_cup.runtime.Symbol)CUP$ArithmeticParser$stack.elementAt(CUP$ArithmeticParser$top-2)).left; int lhsright = ((java_cup.runtime.Symbol)CUP$ArithmeticParser$stack.elementAt(CUP$ArithmeticParser$top-2)).right; Expression lhs = (Expression)((java_cup.runtime.Symbol) CUP$ArithmeticParser$stack.elementAt(CUP$ArithmeticParser$top-2)).value; int rhsleft = ((java_cup.runtime.Symbol)CUP$ArithmeticParser$stack.peek()).left; int rhsright = ((java_cup.runtime.Symbol)CUP$ArithmeticParser$stack.peek()).right; Expression rhs = (Expression)((java_cup.runtime.Symbol) CUP$ArithmeticParser$stack.peek()).value; RESULT = new DivisionExpression(lhs, rhs); CUP$ArithmeticParser$result = parser.getSymbolFactory().newSymbol("MultiplicationOrDivisionExpression",3, ((java_cup.runtime.Symbol)CUP$ArithmeticParser$stack.elementAt(CUP$ArithmeticParser$top-2)), ((java_cup.runtime.Symbol)CUP$ArithmeticParser$stack.peek()), RESULT); } return CUP$ArithmeticParser$result; /*. . . . . . . . . . . . . . . . . . . .*/ case 9: // MultiplicationOrDivisionExpression ::= NumberExpression { Expression RESULT =null; int exprleft = ((java_cup.runtime.Symbol)CUP$ArithmeticParser$stack.peek()).left; int exprright = ((java_cup.runtime.Symbol)CUP$ArithmeticParser$stack.peek()).right; Expression expr = (Expression)((java_cup.runtime.Symbol) CUP$ArithmeticParser$stack.peek()).value; RESULT = expr; CUP$ArithmeticParser$result = parser.getSymbolFactory().newSymbol("MultiplicationOrDivisionExpression",3, ((java_cup.runtime.Symbol)CUP$ArithmeticParser$stack.peek()), ((java_cup.runtime.Symbol)CUP$ArithmeticParser$stack.peek()), RESULT); } return CUP$ArithmeticParser$result; /*. . . . . . . . . . . . . . . . . . . .*/ case 10: // NumberExpression ::= L_PARENTHESIS PlusOrSubtractExpression R_PARENTHESIS { Expression RESULT =null; int exprleft = ((java_cup.runtime.Symbol)CUP$ArithmeticParser$stack.elementAt(CUP$ArithmeticParser$top-1)).left; int exprright = ((java_cup.runtime.Symbol)CUP$ArithmeticParser$stack.elementAt(CUP$ArithmeticParser$top-1)).right; Expression expr = (Expression)((java_cup.runtime.Symbol) CUP$ArithmeticParser$stack.elementAt(CUP$ArithmeticParser$top-1)).value; RESULT = new EnclosedExpression(expr); CUP$ArithmeticParser$result = parser.getSymbolFactory().newSymbol("NumberExpression",4, ((java_cup.runtime.Symbol)CUP$ArithmeticParser$stack.elementAt(CUP$ArithmeticParser$top-2)), ((java_cup.runtime.Symbol)CUP$ArithmeticParser$stack.peek()), RESULT); } return CUP$ArithmeticParser$result; /*. . . . . . . . . . . . . . . . . . . .*/ case 11: // NumberExpression ::= NUMBER { Expression RESULT =null; int valueleft = ((java_cup.runtime.Symbol)CUP$ArithmeticParser$stack.peek()).left; int valueright = ((java_cup.runtime.Symbol)CUP$ArithmeticParser$stack.peek()).right; Integer value = (Integer)((java_cup.runtime.Symbol) CUP$ArithmeticParser$stack.peek()).value; RESULT = new NumberExpression(value); CUP$ArithmeticParser$result = parser.getSymbolFactory().newSymbol("NumberExpression",4, ((java_cup.runtime.Symbol)CUP$ArithmeticParser$stack.peek()), ((java_cup.runtime.Symbol)CUP$ArithmeticParser$stack.peek()), RESULT); } return CUP$ArithmeticParser$result; /* . . . . . .*/ default: throw new Exception( "Invalid action number "+CUP$ArithmeticParser$act_num+"found in internal parse table"); } } /* end of method */ /** Method splitting the generated action code into several parts. */ public final java_cup.runtime.Symbol CUP$ArithmeticParser$do_action( int CUP$ArithmeticParser$act_num, java_cup.runtime.lr_parser CUP$ArithmeticParser$parser, java.util.Stack CUP$ArithmeticParser$stack, int CUP$ArithmeticParser$top) throws java.lang.Exception { return CUP$ArithmeticParser$do_action_part00000000( CUP$ArithmeticParser$act_num, CUP$ArithmeticParser$parser, CUP$ArithmeticParser$stack, CUP$ArithmeticParser$top); } } }