# $ANTLR 3.0 orangescape/model/engine/util/enginegrammar.g 2011-04-01 18:30:41

from antlr_python_runtime import *
from antlrExceptions import *
        
from orangescape.model.engine.operation.function import functions
from parserUtil import pushParseThing, addParenthesis, addWS, getBooleanConstantValue, resolveSugar3dCell, getIncrementVal



# for convenience in actions
HIDDEN = BaseRecognizer.HIDDEN

# token types
PUB_CELL=13
WS=4
NEWLINE=14
CELL_REF_3D_PUBLIC=9
CELL_REF=11
CELL_REF_3D_SUGAR=10
FNNAME=15
STR_CONST=8
INT=5
FLOAT=6
BOOLEAN_CONST=7
AREA_REF=12
EOF=-1

# token names
tokenNames = [
    "<invalid>", "<EOR>", "<DOWN>", "<UP>", 
    "WS", "INT", "FLOAT", "BOOLEAN_CONST", "STR_CONST", "CELL_REF_3D_PUBLIC", 
    "CELL_REF_3D_SUGAR", "CELL_REF", "AREA_REF", "PUB_CELL", "NEWLINE", 
    "FNNAME", "'='", "'<>'", "'>'", "'<'", "'>='", "'<='", "'&'", "'+'", 
    "'-'", "'*'", "'/'", "'^'", "'%'", "'('", "')'", "','"
]



class enginegrammarParser(Parser):
    grammarFileName = "orangescape/model/engine/util/enginegrammar.g"
    tokenNames = tokenNames

    def __init__(self, input):
        Parser.__init__(self, input)
        self.dfa9 = self.DFA9(
            self, 9,
            eot = self.DFA9_eot,
            eof = self.DFA9_eof,
            min = self.DFA9_min,
            max = self.DFA9_max,
            accept = self.DFA9_accept,
            special = self.DFA9_special,
            transition = self.DFA9_transition
            )




                
        self.adaptor = CommonTreeAdaptor()



                      
    rpn = '';
    argNo = 0.0;
    rpnList = [None]


    class formula_return(object):
        def __init__(self):
            self.start = None
            self.stop = None

            self.tree = None


    # $ANTLR start formula
    # orangescape/model/engine/util/enginegrammar.g:19:1: formula : expr ;
    def formula(self, ):

        retval = self.formula_return()
        retval.start = self.input.LT(1)

        root_0 = None

        expr1 = None



        try:
            try:
                # orangescape/model/engine/util/enginegrammar.g:20:7: ( expr )
                # orangescape/model/engine/util/enginegrammar.g:20:7: expr
                root_0 = self.adaptor.nil()

                self.following.append(self.FOLLOW_expr_in_formula53)
                expr1 = self.expr()
                self.following.pop()

                self.adaptor.addChild(root_0, expr1.tree)
                #action start
                           
                self.rpn = self.rpn.replace(',', '',1)
                		
                #action end



                retval.stop = self.input.LT(-1)


                retval.tree = self.adaptor.rulePostProcessing(root_0)
                self.adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop)

            except RecognitionException, re:
                self.reportError(re)
                self.recover(self.input, re)
        finally:

            pass

        return retval

    # $ANTLR end formula

    class expr_return(object):
        def __init__(self):
            self.start = None
            self.stop = None

            self.tree = None


    # $ANTLR start expr
    # orangescape/model/engine/util/enginegrammar.g:25:1: expr : prec0_expr ( ( '=' | '<>' | '>' | '<' | '>=' | '<=' ) prec0_expr )* ;
    def expr(self, ):

        retval = self.expr_return()
        retval.start = self.input.LT(1)

        root_0 = None

        char_literal3 = None
        string_literal4 = None
        char_literal5 = None
        char_literal6 = None
        string_literal7 = None
        string_literal8 = None
        prec0_expr2 = None

        prec0_expr9 = None


        char_literal3_tree = None
        string_literal4_tree = None
        char_literal5_tree = None
        char_literal6_tree = None
        string_literal7_tree = None
        string_literal8_tree = None

        try:
            try:
                # orangescape/model/engine/util/enginegrammar.g:26:7: ( prec0_expr ( ( '=' | '<>' | '>' | '<' | '>=' | '<=' ) prec0_expr )* )
                # orangescape/model/engine/util/enginegrammar.g:26:7: prec0_expr ( ( '=' | '<>' | '>' | '<' | '>=' | '<=' ) prec0_expr )*
                root_0 = self.adaptor.nil()

                self.following.append(self.FOLLOW_prec0_expr_in_expr71)
                prec0_expr2 = self.prec0_expr()
                self.following.pop()

                self.adaptor.addChild(root_0, prec0_expr2.tree)
                # orangescape/model/engine/util/enginegrammar.g:27:9: ( ( '=' | '<>' | '>' | '<' | '>=' | '<=' ) prec0_expr )*
                while True: #loop2
                    alt2 = 2
                    LA2_0 = self.input.LA(1)

                    if ((LA2_0 >= 16 and LA2_0 <= 21)) :
                        alt2 = 1


                    if alt2 == 1:
                        # orangescape/model/engine/util/enginegrammar.g:28:13: ( '=' | '<>' | '>' | '<' | '>=' | '<=' ) prec0_expr
                        # orangescape/model/engine/util/enginegrammar.g:28:13: ( '=' | '<>' | '>' | '<' | '>=' | '<=' )
                        alt1 = 6
                        LA1 = self.input.LA(1)
                        if LA1 == 16:
                            alt1 = 1
                        elif LA1 == 17:
                            alt1 = 2
                        elif LA1 == 18:
                            alt1 = 3
                        elif LA1 == 19:
                            alt1 = 4
                        elif LA1 == 20:
                            alt1 = 5
                        elif LA1 == 21:
                            alt1 = 6
                        else:
                            nvae = NoViableAltException("28:13: ( '=' | '<>' | '>' | '<' | '>=' | '<=' )", 1, 0, self.input)

                            raise nvae

                        if alt1 == 1:
                            # orangescape/model/engine/util/enginegrammar.g:29:19: '='
                            char_literal3 = self.input.LT(1)
                            self.match(self.input, 16, self.FOLLOW_16_in_expr115)


                            char_literal3_tree = self.adaptor.createWithPayload(char_literal3)
                            self.adaptor.addChild(root_0, char_literal3_tree)

                            #action start
                            op = 'eqOper' 
                            #action end


                        elif alt1 == 2:
                            # orangescape/model/engine/util/enginegrammar.g:30:19: '<>'
                            string_literal4 = self.input.LT(1)
                            self.match(self.input, 17, self.FOLLOW_17_in_expr137)


                            string_literal4_tree = self.adaptor.createWithPayload(string_literal4)
                            self.adaptor.addChild(root_0, string_literal4_tree)

                            #action start
                            op = 'notEqOper' 
                            #action end


                        elif alt1 == 3:
                            # orangescape/model/engine/util/enginegrammar.g:31:19: '>'
                            char_literal5 = self.input.LT(1)
                            self.match(self.input, 18, self.FOLLOW_18_in_expr159)


                            char_literal5_tree = self.adaptor.createWithPayload(char_literal5)
                            self.adaptor.addChild(root_0, char_literal5_tree)

                            #action start
                            op = 'gtOper' 
                            #action end


                        elif alt1 == 4:
                            # orangescape/model/engine/util/enginegrammar.g:32:19: '<'
                            char_literal6 = self.input.LT(1)
                            self.match(self.input, 19, self.FOLLOW_19_in_expr181)


                            char_literal6_tree = self.adaptor.createWithPayload(char_literal6)
                            self.adaptor.addChild(root_0, char_literal6_tree)

                            #action start
                            op = 'ltOper' 
                            #action end


                        elif alt1 == 5:
                            # orangescape/model/engine/util/enginegrammar.g:33:19: '>='
                            string_literal7 = self.input.LT(1)
                            self.match(self.input, 20, self.FOLLOW_20_in_expr203)


                            string_literal7_tree = self.adaptor.createWithPayload(string_literal7)
                            self.adaptor.addChild(root_0, string_literal7_tree)

                            #action start
                            op = 'gtEqOper' 
                            #action end


                        elif alt1 == 6:
                            # orangescape/model/engine/util/enginegrammar.g:34:19: '<='
                            string_literal8 = self.input.LT(1)
                            self.match(self.input, 21, self.FOLLOW_21_in_expr225)


                            string_literal8_tree = self.adaptor.createWithPayload(string_literal8)
                            self.adaptor.addChild(root_0, string_literal8_tree)

                            #action start
                            op = 'ltEqOper' 
                            #action end



                        self.following.append(self.FOLLOW_prec0_expr_in_expr255)
                        prec0_expr9 = self.prec0_expr()
                        self.following.pop()

                        self.adaptor.addChild(root_0, prec0_expr9.tree)
                        #action start
                                                
                        self.argNo+=1
                        nextElement = "{'nodeType': 'Function', 'isStr':0.0, 'arguments': 2, 'value': '"+op+"', 'argNo':"+str(self.argNo)+"}"
                        self.rpn += ","+nextElement
                        pushParseThing(self.rpnList,nextElement)
                                    			
                        #action end


                    else:
                        break #loop2





                retval.stop = self.input.LT(-1)


                retval.tree = self.adaptor.rulePostProcessing(root_0)
                self.adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop)

            except RecognitionException, re:
                self.reportError(re)
                self.recover(self.input, re)
        finally:

            pass

        return retval

    # $ANTLR end expr

    class prec0_expr_return(object):
        def __init__(self):
            self.start = None
            self.stop = None

            self.tree = None


    # $ANTLR start prec0_expr
    # orangescape/model/engine/util/enginegrammar.g:45:1: prec0_expr : prec1_expr ( ( '&' ) prec1_expr )* ;
    def prec0_expr(self, ):

        retval = self.prec0_expr_return()
        retval.start = self.input.LT(1)

        root_0 = None

        char_literal11 = None
        prec1_expr10 = None

        prec1_expr12 = None


        char_literal11_tree = None

        try:
            try:
                # orangescape/model/engine/util/enginegrammar.g:46:7: ( prec1_expr ( ( '&' ) prec1_expr )* )
                # orangescape/model/engine/util/enginegrammar.g:46:7: prec1_expr ( ( '&' ) prec1_expr )*
                root_0 = self.adaptor.nil()

                self.following.append(self.FOLLOW_prec1_expr_in_prec0_expr285)
                prec1_expr10 = self.prec1_expr()
                self.following.pop()

                self.adaptor.addChild(root_0, prec1_expr10.tree)
                # orangescape/model/engine/util/enginegrammar.g:47:9: ( ( '&' ) prec1_expr )*
                while True: #loop3
                    alt3 = 2
                    LA3_0 = self.input.LA(1)

                    if (LA3_0 == 22) :
                        alt3 = 1


                    if alt3 == 1:
                        # orangescape/model/engine/util/enginegrammar.g:48:13: ( '&' ) prec1_expr
                        # orangescape/model/engine/util/enginegrammar.g:48:13: ( '&' )
                        # orangescape/model/engine/util/enginegrammar.g:49:17: '&'
                        char_literal11 = self.input.LT(1)
                        self.match(self.input, 22, self.FOLLOW_22_in_prec0_expr327)


                        char_literal11_tree = self.adaptor.createWithPayload(char_literal11)
                        self.adaptor.addChild(root_0, char_literal11_tree)

                        #action start
                        op = 'ampersandOper' 
                        #action end



                        self.following.append(self.FOLLOW_prec1_expr_in_prec0_expr357)
                        prec1_expr12 = self.prec1_expr()
                        self.following.pop()

                        self.adaptor.addChild(root_0, prec1_expr12.tree)
                        #action start
                                                
                        self.argNo+=1
                        nextElement = "{'nodeType': 'Function', 'isStr':'1.0', 'arguments': 2, 'value': '"+op+"', 'argNo':"+str(self.argNo)+"}"
                        self.rpn += ","+nextElement
                        pushParseThing(self.rpnList,nextElement)
                                    			
                        #action end


                    else:
                        break #loop3





                retval.stop = self.input.LT(-1)


                retval.tree = self.adaptor.rulePostProcessing(root_0)
                self.adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop)

            except RecognitionException, re:
                self.reportError(re)
                self.recover(self.input, re)
        finally:

            pass

        return retval

    # $ANTLR end prec0_expr

    class prec1_expr_return(object):
        def __init__(self):
            self.start = None
            self.stop = None

            self.tree = None


    # $ANTLR start prec1_expr
    # orangescape/model/engine/util/enginegrammar.g:60:1: prec1_expr : prec2_expr ( ( '+' | '-' ) prec2_expr )* ;
    def prec1_expr(self, ):

        retval = self.prec1_expr_return()
        retval.start = self.input.LT(1)

        root_0 = None

        char_literal14 = None
        char_literal15 = None
        prec2_expr13 = None

        prec2_expr16 = None


        char_literal14_tree = None
        char_literal15_tree = None

        try:
            try:
                # orangescape/model/engine/util/enginegrammar.g:61:7: ( prec2_expr ( ( '+' | '-' ) prec2_expr )* )
                # orangescape/model/engine/util/enginegrammar.g:61:7: prec2_expr ( ( '+' | '-' ) prec2_expr )*
                root_0 = self.adaptor.nil()

                self.following.append(self.FOLLOW_prec2_expr_in_prec1_expr387)
                prec2_expr13 = self.prec2_expr()
                self.following.pop()

                self.adaptor.addChild(root_0, prec2_expr13.tree)
                # orangescape/model/engine/util/enginegrammar.g:62:9: ( ( '+' | '-' ) prec2_expr )*
                while True: #loop5
                    alt5 = 2
                    LA5_0 = self.input.LA(1)

                    if ((LA5_0 >= 23 and LA5_0 <= 24)) :
                        alt5 = 1


                    if alt5 == 1:
                        # orangescape/model/engine/util/enginegrammar.g:63:13: ( '+' | '-' ) prec2_expr
                        # orangescape/model/engine/util/enginegrammar.g:63:13: ( '+' | '-' )
                        alt4 = 2
                        LA4_0 = self.input.LA(1)

                        if (LA4_0 == 23) :
                            alt4 = 1
                        elif (LA4_0 == 24) :
                            alt4 = 2
                        else:
                            nvae = NoViableAltException("63:13: ( '+' | '-' )", 4, 0, self.input)

                            raise nvae

                        if alt4 == 1:
                            # orangescape/model/engine/util/enginegrammar.g:64:19: '+'
                            char_literal14 = self.input.LT(1)
                            self.match(self.input, 23, self.FOLLOW_23_in_prec1_expr431)


                            char_literal14_tree = self.adaptor.createWithPayload(char_literal14)
                            self.adaptor.addChild(root_0, char_literal14_tree)

                            #action start
                            op = 'addOper' 
                            #action end


                        elif alt4 == 2:
                            # orangescape/model/engine/util/enginegrammar.g:65:19: '-'
                            char_literal15 = self.input.LT(1)
                            self.match(self.input, 24, self.FOLLOW_24_in_prec1_expr453)


                            char_literal15_tree = self.adaptor.createWithPayload(char_literal15)
                            self.adaptor.addChild(root_0, char_literal15_tree)

                            #action start
                            op = 'subOper' 
                            #action end



                        self.following.append(self.FOLLOW_prec2_expr_in_prec1_expr483)
                        prec2_expr16 = self.prec2_expr()
                        self.following.pop()

                        self.adaptor.addChild(root_0, prec2_expr16.tree)
                        #action start
                                                
                        self.argNo+=1
                        nextElement = "{'nodeType': 'Function', 'isStr':0.0, 'arguments': 2, 'value': '"+op+"', 'argNo':"+str(self.argNo)+"}"
                        self.rpn += ","+nextElement
                        pushParseThing(self.rpnList,nextElement)
                                    			
                        #action end


                    else:
                        break #loop5





                retval.stop = self.input.LT(-1)


                retval.tree = self.adaptor.rulePostProcessing(root_0)
                self.adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop)

            except RecognitionException, re:
                self.reportError(re)
                self.recover(self.input, re)
        finally:

            pass

        return retval

    # $ANTLR end prec1_expr

    class prec2_expr_return(object):
        def __init__(self):
            self.start = None
            self.stop = None

            self.tree = None


    # $ANTLR start prec2_expr
    # orangescape/model/engine/util/enginegrammar.g:76:1: prec2_expr : prec3_expr ( ( WS )* ( '*' | '/' ) ( WS )* prec3_expr )* ;
    def prec2_expr(self, ):

        retval = self.prec2_expr_return()
        retval.start = self.input.LT(1)

        root_0 = None

        WS18 = None
        char_literal19 = None
        char_literal20 = None
        WS21 = None
        prec3_expr17 = None

        prec3_expr22 = None


        WS18_tree = None
        char_literal19_tree = None
        char_literal20_tree = None
        WS21_tree = None

        try:
            try:
                # orangescape/model/engine/util/enginegrammar.g:77:7: ( prec3_expr ( ( WS )* ( '*' | '/' ) ( WS )* prec3_expr )* )
                # orangescape/model/engine/util/enginegrammar.g:77:7: prec3_expr ( ( WS )* ( '*' | '/' ) ( WS )* prec3_expr )*
                root_0 = self.adaptor.nil()

                self.following.append(self.FOLLOW_prec3_expr_in_prec2_expr513)
                prec3_expr17 = self.prec3_expr()
                self.following.pop()

                self.adaptor.addChild(root_0, prec3_expr17.tree)
                # orangescape/model/engine/util/enginegrammar.g:78:9: ( ( WS )* ( '*' | '/' ) ( WS )* prec3_expr )*
                while True: #loop9
                    alt9 = 2
                    alt9 = self.dfa9.predict(self.input)
                    if alt9 == 1:
                        # orangescape/model/engine/util/enginegrammar.g:79:12: ( WS )* ( '*' | '/' ) ( WS )* prec3_expr
                        # orangescape/model/engine/util/enginegrammar.g:79:12: ( WS )*
                        while True: #loop6
                            alt6 = 2
                            LA6_0 = self.input.LA(1)

                            if (LA6_0 == WS) :
                                alt6 = 1


                            if alt6 == 1:
                                # orangescape/model/engine/util/enginegrammar.g:79:13: WS
                                WS18 = self.input.LT(1)
                                self.match(self.input, WS, self.FOLLOW_WS_in_prec2_expr537)


                                WS18_tree = self.adaptor.createWithPayload(WS18)
                                self.adaptor.addChild(root_0, WS18_tree)



                            else:
                                break #loop6


                        # orangescape/model/engine/util/enginegrammar.g:79:18: ( '*' | '/' )
                        alt7 = 2
                        LA7_0 = self.input.LA(1)

                        if (LA7_0 == 25) :
                            alt7 = 1
                        elif (LA7_0 == 26) :
                            alt7 = 2
                        else:
                            nvae = NoViableAltException("79:18: ( '*' | '/' )", 7, 0, self.input)

                            raise nvae

                        if alt7 == 1:
                            # orangescape/model/engine/util/enginegrammar.g:80:19: '*'
                            char_literal19 = self.input.LT(1)
                            self.match(self.input, 25, self.FOLLOW_25_in_prec2_expr561)


                            char_literal19_tree = self.adaptor.createWithPayload(char_literal19)
                            self.adaptor.addChild(root_0, char_literal19_tree)

                            #action start
                            op = 'mulOper' 
                            #action end


                        elif alt7 == 2:
                            # orangescape/model/engine/util/enginegrammar.g:81:19: '/'
                            char_literal20 = self.input.LT(1)
                            self.match(self.input, 26, self.FOLLOW_26_in_prec2_expr583)


                            char_literal20_tree = self.adaptor.createWithPayload(char_literal20)
                            self.adaptor.addChild(root_0, char_literal20_tree)

                            #action start
                            op = 'divOper' 
                            #action end



                        # orangescape/model/engine/util/enginegrammar.g:82:14: ( WS )*
                        while True: #loop8
                            alt8 = 2
                            LA8_0 = self.input.LA(1)

                            if (LA8_0 == WS) :
                                alt8 = 1


                            if alt8 == 1:
                                # orangescape/model/engine/util/enginegrammar.g:82:15: WS
                                WS21 = self.input.LT(1)
                                self.match(self.input, WS, self.FOLLOW_WS_in_prec2_expr601)


                                WS21_tree = self.adaptor.createWithPayload(WS21)
                                self.adaptor.addChild(root_0, WS21_tree)



                            else:
                                break #loop8


                        self.following.append(self.FOLLOW_prec3_expr_in_prec2_expr617)
                        prec3_expr22 = self.prec3_expr()
                        self.following.pop()

                        self.adaptor.addChild(root_0, prec3_expr22.tree)
                        #action start
                                                
                        self.argNo+=1
                        nextElement = "{'nodeType': 'Function', 'isStr':0.0, 'arguments': 2, 'value': '"+op+"', 'argNo':"+str(self.argNo)+"}"
                        self.rpn += ","+nextElement
                        pushParseThing(self.rpnList,nextElement)
                        						
                        #action end


                    else:
                        break #loop9





                retval.stop = self.input.LT(-1)


                retval.tree = self.adaptor.rulePostProcessing(root_0)
                self.adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop)

            except RecognitionException, re:
                self.reportError(re)
                self.recover(self.input, re)
        finally:

            pass

        return retval

    # $ANTLR end prec2_expr

    class prec3_expr_return(object):
        def __init__(self):
            self.start = None
            self.stop = None

            self.tree = None


    # $ANTLR start prec3_expr
    # orangescape/model/engine/util/enginegrammar.g:92:1: prec3_expr : prec4_expr ( ( '^' ) prec4_expr )* ;
    def prec3_expr(self, ):

        retval = self.prec3_expr_return()
        retval.start = self.input.LT(1)

        root_0 = None

        char_literal24 = None
        prec4_expr23 = None

        prec4_expr25 = None


        char_literal24_tree = None

        try:
            try:
                # orangescape/model/engine/util/enginegrammar.g:93:7: ( prec4_expr ( ( '^' ) prec4_expr )* )
                # orangescape/model/engine/util/enginegrammar.g:93:7: prec4_expr ( ( '^' ) prec4_expr )*
                root_0 = self.adaptor.nil()

                self.following.append(self.FOLLOW_prec4_expr_in_prec3_expr647)
                prec4_expr23 = self.prec4_expr()
                self.following.pop()

                self.adaptor.addChild(root_0, prec4_expr23.tree)
                # orangescape/model/engine/util/enginegrammar.g:94:9: ( ( '^' ) prec4_expr )*
                while True: #loop10
                    alt10 = 2
                    LA10_0 = self.input.LA(1)

                    if (LA10_0 == 27) :
                        alt10 = 1


                    if alt10 == 1:
                        # orangescape/model/engine/util/enginegrammar.g:95:13: ( '^' ) prec4_expr
                        # orangescape/model/engine/util/enginegrammar.g:95:13: ( '^' )
                        # orangescape/model/engine/util/enginegrammar.g:96:17: '^'
                        char_literal24 = self.input.LT(1)
                        self.match(self.input, 27, self.FOLLOW_27_in_prec3_expr689)


                        char_literal24_tree = self.adaptor.createWithPayload(char_literal24)
                        self.adaptor.addChild(root_0, char_literal24_tree)

                        #action start
                        op = 'powerOper' 
                        #action end



                        self.following.append(self.FOLLOW_prec4_expr_in_prec3_expr719)
                        prec4_expr25 = self.prec4_expr()
                        self.following.pop()

                        self.adaptor.addChild(root_0, prec4_expr25.tree)
                        #action start
                                                
                        self.argNo+=1
                        nextElement = "{'nodeType': 'Function', 'isStr':0.0, 'arguments': 2, 'value': '"+op+"', 'argNo':"+str(self.argNo)+"}"
                        self.rpn += ","+nextElement
                        pushParseThing(self.rpnList,nextElement)
                        						
                        #action end


                    else:
                        break #loop10





                retval.stop = self.input.LT(-1)


                retval.tree = self.adaptor.rulePostProcessing(root_0)
                self.adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop)

            except RecognitionException, re:
                self.reportError(re)
                self.recover(self.input, re)
        finally:

            pass

        return retval

    # $ANTLR end prec3_expr

    class prec4_expr_return(object):
        def __init__(self):
            self.start = None
            self.stop = None

            self.tree = None


    # $ANTLR start prec4_expr
    # orangescape/model/engine/util/enginegrammar.g:107:1: prec4_expr : prec5_expr ( '%' )? ;
    def prec4_expr(self, ):

        retval = self.prec4_expr_return()
        retval.start = self.input.LT(1)

        root_0 = None

        char_literal27 = None
        prec5_expr26 = None


        char_literal27_tree = None

        try:
            try:
                # orangescape/model/engine/util/enginegrammar.g:108:7: ( prec5_expr ( '%' )? )
                # orangescape/model/engine/util/enginegrammar.g:108:7: prec5_expr ( '%' )?
                root_0 = self.adaptor.nil()

                self.following.append(self.FOLLOW_prec5_expr_in_prec4_expr749)
                prec5_expr26 = self.prec5_expr()
                self.following.pop()

                self.adaptor.addChild(root_0, prec5_expr26.tree)
                # orangescape/model/engine/util/enginegrammar.g:109:6: ( '%' )?
                alt11 = 2
                LA11_0 = self.input.LA(1)

                if (LA11_0 == 28) :
                    alt11 = 1
                if alt11 == 1:
                    # orangescape/model/engine/util/enginegrammar.g:111:13: '%'
                    char_literal27 = self.input.LT(1)
                    self.match(self.input, 28, self.FOLLOW_28_in_prec4_expr771)


                    char_literal27_tree = self.adaptor.createWithPayload(char_literal27)
                    self.adaptor.addChild(root_0, char_literal27_tree)

                    #action start
                                     
                    self.argNo+=1
                    nextElement = "{'nodeType': 'Function', 'isStr':0.0, 'arguments': 1, 'value': 'percentageOper', 'argNo':"+str(self.argNo)+"}"
                    self.rpn += ","+nextElement
                    pushParseThing(self.rpnList,nextElement)
                    				
                    #action end






                retval.stop = self.input.LT(-1)


                retval.tree = self.adaptor.rulePostProcessing(root_0)
                self.adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop)

            except RecognitionException, re:
                self.reportError(re)
                self.recover(self.input, re)
        finally:

            pass

        return retval

    # $ANTLR end prec4_expr

    class prec5_expr_return(object):
        def __init__(self):
            self.start = None
            self.stop = None

            self.tree = None


    # $ANTLR start prec5_expr
    # orangescape/model/engine/util/enginegrammar.g:120:1: prec5_expr : ( leadingTrailingWSAtom | ( '-' | '+' ) leadingTrailingWSAtom );
    def prec5_expr(self, ):

        retval = self.prec5_expr_return()
        retval.start = self.input.LT(1)

        root_0 = None

        char_literal29 = None
        char_literal30 = None
        leadingTrailingWSAtom28 = None

        leadingTrailingWSAtom31 = None


        char_literal29_tree = None
        char_literal30_tree = None

        try:
            try:
                # orangescape/model/engine/util/enginegrammar.g:121:7: ( leadingTrailingWSAtom | ( '-' | '+' ) leadingTrailingWSAtom )
                alt13 = 2
                LA13_0 = self.input.LA(1)

                if ((LA13_0 >= WS and LA13_0 <= PUB_CELL) or LA13_0 == FNNAME or LA13_0 == 29) :
                    alt13 = 1
                elif ((LA13_0 >= 23 and LA13_0 <= 24)) :
                    alt13 = 2
                else:
                    nvae = NoViableAltException("120:1: prec5_expr : ( leadingTrailingWSAtom | ( '-' | '+' ) leadingTrailingWSAtom );", 13, 0, self.input)

                    raise nvae

                if alt13 == 1:
                    # orangescape/model/engine/util/enginegrammar.g:121:7: leadingTrailingWSAtom
                    root_0 = self.adaptor.nil()

                    self.following.append(self.FOLLOW_leadingTrailingWSAtom_in_prec5_expr801)
                    leadingTrailingWSAtom28 = self.leadingTrailingWSAtom()
                    self.following.pop()

                    self.adaptor.addChild(root_0, leadingTrailingWSAtom28.tree)


                elif alt13 == 2:
                    # orangescape/model/engine/util/enginegrammar.g:121:31: ( '-' | '+' ) leadingTrailingWSAtom
                    root_0 = self.adaptor.nil()

                    # orangescape/model/engine/util/enginegrammar.g:121:31: ( '-' | '+' )
                    alt12 = 2
                    LA12_0 = self.input.LA(1)

                    if (LA12_0 == 24) :
                        alt12 = 1
                    elif (LA12_0 == 23) :
                        alt12 = 2
                    else:
                        nvae = NoViableAltException("121:31: ( '-' | '+' )", 12, 0, self.input)

                        raise nvae

                    if alt12 == 1:
                        # orangescape/model/engine/util/enginegrammar.g:121:32: '-'
                        char_literal29 = self.input.LT(1)
                        self.match(self.input, 24, self.FOLLOW_24_in_prec5_expr806)


                        char_literal29_tree = self.adaptor.createWithPayload(char_literal29)
                        self.adaptor.addChild(root_0, char_literal29_tree)

                        #action start
                        op='-'
                        #action end


                    elif alt12 == 2:
                        # orangescape/model/engine/util/enginegrammar.g:121:48: '+'
                        char_literal30 = self.input.LT(1)
                        self.match(self.input, 23, self.FOLLOW_23_in_prec5_expr812)


                        char_literal30_tree = self.adaptor.createWithPayload(char_literal30)
                        self.adaptor.addChild(root_0, char_literal30_tree)

                        #action start
                        op='+'
                        #action end



                    self.following.append(self.FOLLOW_leadingTrailingWSAtom_in_prec5_expr817)
                    leadingTrailingWSAtom31 = self.leadingTrailingWSAtom()
                    self.following.pop()

                    self.adaptor.addChild(root_0, leadingTrailingWSAtom31.tree)
                    #action start
                              
                    nextElement = "{'nodeType': 'UnaryOperator', 'isStr':0.0, 'arguments': 1, 'value': '"+op+"', 'argNo':"+str(self.argNo)+"}"
                    self.rpn += ","+nextElement
                    pushParseThing(self.rpnList,nextElement)
                    						
                    #action end


                retval.stop = self.input.LT(-1)


                retval.tree = self.adaptor.rulePostProcessing(root_0)
                self.adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop)

            except RecognitionException, re:
                self.reportError(re)
                self.recover(self.input, re)
        finally:

            pass

        return retval

    # $ANTLR end prec5_expr

    class leadingTrailingWSAtom_return(object):
        def __init__(self):
            self.start = None
            self.stop = None

            self.tree = None


    # $ANTLR start leadingTrailingWSAtom
    # orangescape/model/engine/util/enginegrammar.g:129:1: leadingTrailingWSAtom : ( WS )* atom ( WS )* ;
    def leadingTrailingWSAtom(self, ):

        retval = self.leadingTrailingWSAtom_return()
        retval.start = self.input.LT(1)

        root_0 = None

        WS32 = None
        WS34 = None
        atom33 = None


        WS32_tree = None
        WS34_tree = None

        try:
            try:
                # orangescape/model/engine/util/enginegrammar.g:129:25: ( ( WS )* atom ( WS )* )
                # orangescape/model/engine/util/enginegrammar.g:129:25: ( WS )* atom ( WS )*
                root_0 = self.adaptor.nil()

                # orangescape/model/engine/util/enginegrammar.g:129:25: ( WS )*
                while True: #loop14
                    alt14 = 2
                    LA14_0 = self.input.LA(1)

                    if (LA14_0 == WS) :
                        alt14 = 1


                    if alt14 == 1:
                        # orangescape/model/engine/util/enginegrammar.g:129:26: WS
                        WS32 = self.input.LT(1)
                        self.match(self.input, WS, self.FOLLOW_WS_in_leadingTrailingWSAtom842)


                        WS32_tree = self.adaptor.createWithPayload(WS32)
                        self.adaptor.addChild(root_0, WS32_tree)



                    else:
                        break #loop14


                self.following.append(self.FOLLOW_atom_in_leadingTrailingWSAtom846)
                atom33 = self.atom()
                self.following.pop()

                self.adaptor.addChild(root_0, atom33.tree)
                # orangescape/model/engine/util/enginegrammar.g:129:36: ( WS )*
                while True: #loop15
                    alt15 = 2
                    LA15_0 = self.input.LA(1)

                    if (LA15_0 == WS) :
                        alt15 = 1


                    if alt15 == 1:
                        # orangescape/model/engine/util/enginegrammar.g:129:37: WS
                        WS34 = self.input.LT(1)
                        self.match(self.input, WS, self.FOLLOW_WS_in_leadingTrailingWSAtom849)


                        WS34_tree = self.adaptor.createWithPayload(WS34)
                        self.adaptor.addChild(root_0, WS34_tree)



                    else:
                        break #loop15


                #action start
                         
                addWS(self.rpnList,self.input.toString(retval.start, self.input.LT(-1)))
                								
                #action end



                retval.stop = self.input.LT(-1)


                retval.tree = self.adaptor.rulePostProcessing(root_0)
                self.adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop)

            except RecognitionException, re:
                self.reportError(re)
                self.recover(self.input, re)
        finally:

            pass

        return retval

    # $ANTLR end leadingTrailingWSAtom

    class atom_return(object):
        def __init__(self):
            self.start = None
            self.stop = None

            self.tree = None


    # $ANTLR start atom
    # orangescape/model/engine/util/enginegrammar.g:136:1: atom : (integer= INT | decimal= FLOAT | boolean_const= BOOLEAN_CONST | str_const= STR_CONST | cell_ref_3d_public= CELL_REF_3D_PUBLIC | cell_ref_3d_sugar= CELL_REF_3D_SUGAR | cell_ref= CELL_REF | area_ref= AREA_REF | pub_cell= PUB_CELL | fn= fname | parenthesis );
    def atom(self, ):

        retval = self.atom_return()
        retval.start = self.input.LT(1)

        root_0 = None

        integer = None
        decimal = None
        boolean_const = None
        str_const = None
        cell_ref_3d_public = None
        cell_ref_3d_sugar = None
        cell_ref = None
        area_ref = None
        pub_cell = None
        fn = None

        parenthesis35 = None


        integer_tree = None
        decimal_tree = None
        boolean_const_tree = None
        str_const_tree = None
        cell_ref_3d_public_tree = None
        cell_ref_3d_sugar_tree = None
        cell_ref_tree = None
        area_ref_tree = None
        pub_cell_tree = None

        try:
            try:
                # orangescape/model/engine/util/enginegrammar.g:136:9: (integer= INT | decimal= FLOAT | boolean_const= BOOLEAN_CONST | str_const= STR_CONST | cell_ref_3d_public= CELL_REF_3D_PUBLIC | cell_ref_3d_sugar= CELL_REF_3D_SUGAR | cell_ref= CELL_REF | area_ref= AREA_REF | pub_cell= PUB_CELL | fn= fname | parenthesis )
                alt16 = 11
                LA16 = self.input.LA(1)
                if LA16 == INT:
                    alt16 = 1
                elif LA16 == FLOAT:
                    alt16 = 2
                elif LA16 == BOOLEAN_CONST:
                    alt16 = 3
                elif LA16 == STR_CONST:
                    alt16 = 4
                elif LA16 == CELL_REF_3D_PUBLIC:
                    alt16 = 5
                elif LA16 == CELL_REF_3D_SUGAR:
                    alt16 = 6
                elif LA16 == CELL_REF:
                    alt16 = 7
                elif LA16 == AREA_REF:
                    alt16 = 8
                elif LA16 == PUB_CELL:
                    alt16 = 9
                elif LA16 == FNNAME:
                    alt16 = 10
                elif LA16 == 29:
                    alt16 = 11
                else:
                    nvae = NoViableAltException("136:1: atom : (integer= INT | decimal= FLOAT | boolean_const= BOOLEAN_CONST | str_const= STR_CONST | cell_ref_3d_public= CELL_REF_3D_PUBLIC | cell_ref_3d_sugar= CELL_REF_3D_SUGAR | cell_ref= CELL_REF | area_ref= AREA_REF | pub_cell= PUB_CELL | fn= fname | parenthesis );", 16, 0, self.input)

                    raise nvae

                if alt16 == 1:
                    # orangescape/model/engine/util/enginegrammar.g:136:9: integer= INT
                    root_0 = self.adaptor.nil()

                    integer = self.input.LT(1)
                    self.match(self.input, INT, self.FOLLOW_INT_in_atom880)


                    integer_tree = self.adaptor.createWithPayload(integer)
                    self.adaptor.addChild(root_0, integer_tree)

                    #action start
                         
                    self.argNo+=1
                    nextElement = "{'nodeType': 'Constant', 'isStr':0.0, 'value': '"+integer.text+"', 'nodeFloatValue': "+integer.text+", 'argNo':"+str(self.argNo)+"}"
                    self.rpn += ","+nextElement
                    pushParseThing(self.rpnList,nextElement)
                    				
                    #action end


                elif alt16 == 2:
                    # orangescape/model/engine/util/enginegrammar.g:143:3: decimal= FLOAT
                    root_0 = self.adaptor.nil()

                    decimal = self.input.LT(1)
                    self.match(self.input, FLOAT, self.FOLLOW_FLOAT_in_atom896)


                    decimal_tree = self.adaptor.createWithPayload(decimal)
                    self.adaptor.addChild(root_0, decimal_tree)

                    #action start
                         
                    self.argNo+=1
                    nextElement = "{'nodeType': 'Constant', 'isStr':0.0, 'value': '"+decimal.text+"', 'nodeFloatValue': "+decimal.text+", 'argNo':"+str(self.argNo)+"}"
                    self.rpn += ","+nextElement
                    pushParseThing(self.rpnList,nextElement)
                    				
                    #action end


                elif alt16 == 3:
                    # orangescape/model/engine/util/enginegrammar.g:150:3: boolean_const= BOOLEAN_CONST
                    root_0 = self.adaptor.nil()

                    boolean_const = self.input.LT(1)
                    self.match(self.input, BOOLEAN_CONST, self.FOLLOW_BOOLEAN_CONST_in_atom912)


                    boolean_const_tree = self.adaptor.createWithPayload(boolean_const)
                    self.adaptor.addChild(root_0, boolean_const_tree)

                    #action start
                         
                    self.argNo+=1
                    nextElement = "{'nodeType': 'Constant', 'isStr':0.0, 'value': '"+boolean_const.text.upper()+"', 'nodeFloatValue':"+getBooleanConstantValue(boolean_const.text.upper())+", 'argNo':"+str(self.argNo)+"}"
                    self.rpn += ","+nextElement
                    pushParseThing(self.rpnList,nextElement)
                    				
                    #action end


                elif alt16 == 4:
                    # orangescape/model/engine/util/enginegrammar.g:158:3: str_const= STR_CONST
                    root_0 = self.adaptor.nil()

                    str_const = self.input.LT(1)
                    self.match(self.input, STR_CONST, self.FOLLOW_STR_CONST_in_atom929)


                    str_const_tree = self.adaptor.createWithPayload(str_const)
                    self.adaptor.addChild(root_0, str_const_tree)

                    #action start
                         
                    self.argNo+=1
                    nextElement = "{'nodeType': 'Constant', 'isStr':1.0, 'value': "+str_const.text+", 'argNo':"+str(self.argNo)+"}"
                    self.rpn += ","+nextElement
                    pushParseThing(self.rpnList,nextElement)
                    				
                    #action end


                elif alt16 == 5:
                    # orangescape/model/engine/util/enginegrammar.g:165:3: cell_ref_3d_public= CELL_REF_3D_PUBLIC
                    root_0 = self.adaptor.nil()

                    cell_ref_3d_public = self.input.LT(1)
                    self.match(self.input, CELL_REF_3D_PUBLIC, self.FOLLOW_CELL_REF_3D_PUBLIC_in_atom942)


                    cell_ref_3d_public_tree = self.adaptor.createWithPayload(cell_ref_3d_public)
                    self.adaptor.addChild(root_0, cell_ref_3d_public_tree)

                    #action start
                                                             
                    self.argNo+=1
                    nextElement = "{'nodeType': '3dCellReference', 'isPublicRef': 1.0, 'value': '"+cell_ref_3d_public.text+"', 'argNo':"+str(self.argNo)+"}"
                    self.rpn += ","+nextElement
                    pushParseThing(self.rpnList,nextElement)
                    				
                    #action end


                elif alt16 == 6:
                    # orangescape/model/engine/util/enginegrammar.g:171:3: cell_ref_3d_sugar= CELL_REF_3D_SUGAR
                    root_0 = self.adaptor.nil()

                    cell_ref_3d_sugar = self.input.LT(1)
                    self.match(self.input, CELL_REF_3D_SUGAR, self.FOLLOW_CELL_REF_3D_SUGAR_in_atom952)


                    cell_ref_3d_sugar_tree = self.adaptor.createWithPayload(cell_ref_3d_sugar)
                    self.adaptor.addChild(root_0, cell_ref_3d_sugar_tree)

                    #action start
                                                           
                    refCellName, fetchCellName = resolveSugar3dCell(cell_ref_3d_sugar.text)
                    self.argNo+=1
                    nextElement = "{'nodeType': '3dCellReference', 'isPublicRef': 1.0, 'value': '"+refCellName+"', 'argNo':"+str(self.argNo)+", 'IsSyntacticSugar': 1.0}"
                    self.rpn += ","+nextElement
                    pushParseThing(self.rpnList,nextElement)
                    
                    self.argNo+=1
                    nextElement = "{'nodeType': '3dCellReference', 'isPublicRef': 1.0, 'value': '"+fetchCellName+"', 'argNo':"+str(self.argNo)+", 'IsSyntacticSugar': 1.0}"
                    self.rpn += ","+nextElement
                    pushParseThing(self.rpnList,nextElement)
                    				
                    #action end


                elif alt16 == 7:
                    # orangescape/model/engine/util/enginegrammar.g:184:3: cell_ref= CELL_REF
                    root_0 = self.adaptor.nil()

                    cell_ref = self.input.LT(1)
                    self.match(self.input, CELL_REF, self.FOLLOW_CELL_REF_in_atom963)


                    cell_ref_tree = self.adaptor.createWithPayload(cell_ref)
                    self.adaptor.addChild(root_0, cell_ref_tree)

                    #action start
                         
                    self.argNo+=1
                    nextElement = "{'nodeType': 'CellReference', 'isPublicRef': 0.0, 'value': '"+cell_ref.text.upper()+"', 'argNo':"+str(self.argNo)+"}"
                    self.rpn += ","+nextElement
                    pushParseThing(self.rpnList,nextElement)
                    				
                    #action end


                elif alt16 == 8:
                    # orangescape/model/engine/util/enginegrammar.g:192:3: area_ref= AREA_REF
                    root_0 = self.adaptor.nil()

                    area_ref = self.input.LT(1)
                    self.match(self.input, AREA_REF, self.FOLLOW_AREA_REF_in_atom979)


                    area_ref_tree = self.adaptor.createWithPayload(area_ref)
                    self.adaptor.addChild(root_0, area_ref_tree)

                    #action start
                         
                    self.argNo+=1
                    nextElement = "{'nodeType': 'AreaReference', 'isPublicRef': 0.0, 'value': '"+area_ref.text+"', 'argNo':"+str(self.argNo)+"}"
                    self.rpn += ","+nextElement
                    pushParseThing(self.rpnList,nextElement)
                    				
                    #action end


                elif alt16 == 9:
                    # orangescape/model/engine/util/enginegrammar.g:200:3: pub_cell= PUB_CELL
                    root_0 = self.adaptor.nil()

                    pub_cell = self.input.LT(1)
                    self.match(self.input, PUB_CELL, self.FOLLOW_PUB_CELL_in_atom993)


                    pub_cell_tree = self.adaptor.createWithPayload(pub_cell)
                    self.adaptor.addChild(root_0, pub_cell_tree)

                    #action start
                         
                    self.argNo+=1
                    nextElement = "{'nodeType': 'CellReference', 'isPublicRef': 1.0, 'value': '"+pub_cell.text+"', 'argNo':"+str(self.argNo)+"}"
                    self.rpn += ","+nextElement
                    pushParseThing(self.rpnList,nextElement)
                    				
                    #action end


                elif alt16 == 10:
                    # orangescape/model/engine/util/enginegrammar.g:207:3: fn= fname
                    root_0 = self.adaptor.nil()

                    self.following.append(self.FOLLOW_fname_in_atom1009)
                    fn = self.fname()
                    self.following.pop()

                    self.adaptor.addChild(root_0, fn.tree)
                    #action start
                         
                    self.argNo+=1
                    nextElement = "{'nodeType': '"+str(fn.type)+"', 'isStr':"+str(fn.datatype)+", 'arguments': "+str(fn.noOfArgs)+", 'value': '"+str(self.input.toString(fn.start,fn.stop).split('(')[0].upper())+"', 'argNo':"+str(self.argNo)+"}"
                    self.rpn += ","+nextElement
                    pushParseThing(self.rpnList,nextElement)
                    				
                    #action end


                elif alt16 == 11:
                    # orangescape/model/engine/util/enginegrammar.g:214:3: parenthesis
                    root_0 = self.adaptor.nil()

                    self.following.append(self.FOLLOW_parenthesis_in_atom1021)
                    parenthesis35 = self.parenthesis()
                    self.following.pop()

                    self.adaptor.addChild(root_0, parenthesis35.tree)
                    #action start
                         
                    addParenthesis(self.rpnList,self.input.toString(parenthesis35.start,parenthesis35.stop))
                    				
                    #action end


                retval.stop = self.input.LT(-1)


                retval.tree = self.adaptor.rulePostProcessing(root_0)
                self.adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop)

            except RecognitionException, re:
                self.reportError(re)
                self.recover(self.input, re)
        finally:

            pass

        return retval

    # $ANTLR end atom

    class parenthesis_return(object):
        def __init__(self):
            self.start = None
            self.stop = None

            self.tree = None


    # $ANTLR start parenthesis
    # orangescape/model/engine/util/enginegrammar.g:231:1: parenthesis : '(' ( WS )* expr ( WS )* ')' ;
    def parenthesis(self, ):

        retval = self.parenthesis_return()
        retval.start = self.input.LT(1)

        root_0 = None

        char_literal36 = None
        WS37 = None
        WS39 = None
        char_literal40 = None
        expr38 = None


        char_literal36_tree = None
        WS37_tree = None
        WS39_tree = None
        char_literal40_tree = None

        try:
            try:
                # orangescape/model/engine/util/enginegrammar.g:231:14: ( '(' ( WS )* expr ( WS )* ')' )
                # orangescape/model/engine/util/enginegrammar.g:231:14: '(' ( WS )* expr ( WS )* ')'
                root_0 = self.adaptor.nil()

                char_literal36 = self.input.LT(1)
                self.match(self.input, 29, self.FOLLOW_29_in_parenthesis1412)


                char_literal36_tree = self.adaptor.createWithPayload(char_literal36)
                self.adaptor.addChild(root_0, char_literal36_tree)

                # orangescape/model/engine/util/enginegrammar.g:231:18: ( WS )*
                while True: #loop17
                    alt17 = 2
                    LA17_0 = self.input.LA(1)

                    if (LA17_0 == WS) :
                        alt17 = 1


                    if alt17 == 1:
                        # orangescape/model/engine/util/enginegrammar.g:231:19: WS
                        WS37 = self.input.LT(1)
                        self.match(self.input, WS, self.FOLLOW_WS_in_parenthesis1415)


                        WS37_tree = self.adaptor.createWithPayload(WS37)
                        self.adaptor.addChild(root_0, WS37_tree)



                    else:
                        break #loop17


                self.following.append(self.FOLLOW_expr_in_parenthesis1419)
                expr38 = self.expr()
                self.following.pop()

                self.adaptor.addChild(root_0, expr38.tree)
                # orangescape/model/engine/util/enginegrammar.g:231:29: ( WS )*
                while True: #loop18
                    alt18 = 2
                    LA18_0 = self.input.LA(1)

                    if (LA18_0 == WS) :
                        alt18 = 1


                    if alt18 == 1:
                        # orangescape/model/engine/util/enginegrammar.g:231:30: WS
                        WS39 = self.input.LT(1)
                        self.match(self.input, WS, self.FOLLOW_WS_in_parenthesis1422)


                        WS39_tree = self.adaptor.createWithPayload(WS39)
                        self.adaptor.addChild(root_0, WS39_tree)



                    else:
                        break #loop18


                char_literal40 = self.input.LT(1)
                self.match(self.input, 30, self.FOLLOW_30_in_parenthesis1426)


                char_literal40_tree = self.adaptor.createWithPayload(char_literal40)
                self.adaptor.addChild(root_0, char_literal40_tree)




                retval.stop = self.input.LT(-1)


                retval.tree = self.adaptor.rulePostProcessing(root_0)
                self.adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop)

            except RecognitionException, re:
                self.reportError(re)
                self.recover(self.input, re)
        finally:

            pass

        return retval

    # $ANTLR end parenthesis

    class fname_return(object):
        def __init__(self):
            self.start = None
            self.stop = None

            self.datatype = None
            self.noOfArgs = None
            self.type = None
            self.tree = None


    # $ANTLR start fname
    # orangescape/model/engine/util/enginegrammar.g:233:1: fname returns [datatype, noOfArgs, type] : func= FNNAME arg_count= expr_list ')' ;
    def fname(self, ):

        retval = self.fname_return()
        retval.start = self.input.LT(1)

        root_0 = None

        func = None
        char_literal41 = None
        arg_count = None


        func_tree = None
        char_literal41_tree = None

        try:
            try:
                # orangescape/model/engine/util/enginegrammar.g:233:43: (func= FNNAME arg_count= expr_list ')' )
                # orangescape/model/engine/util/enginegrammar.g:233:43: func= FNNAME arg_count= expr_list ')'
                root_0 = self.adaptor.nil()

                func = self.input.LT(1)
                self.match(self.input, FNNAME, self.FOLLOW_FNNAME_in_fname1441)


                func_tree = self.adaptor.createWithPayload(func)
                self.adaptor.addChild(root_0, func_tree)

                #action start
                   
                if func.text.split('(')[0]:
                	fn = functions[func.text.split('(')[0].upper()]
                	if fn:
                		code =func.text.split('(')[0].upper()
                		retval.type = fn["Type"]
                		minarg = fn["Min_Arg"]
                		maxarg = fn["Max_Arg"]
                		isStr = fn['IsString']
                		retval.datatype = isStr
                	else:
                		raise Exception, "unknown function: "+func.text.split('(')[0]
                		
                #action end
                self.following.append(self.FOLLOW_expr_list_in_fname1451)
                arg_count = self.expr_list()
                self.following.pop()

                self.adaptor.addChild(root_0, arg_count.tree)
                char_literal41 = self.input.LT(1)
                self.match(self.input, 30, self.FOLLOW_30_in_fname1453)


                char_literal41_tree = self.adaptor.createWithPayload(char_literal41)
                self.adaptor.addChild(root_0, char_literal41_tree)

                #action start
                   
                retval.noOfArgs = arg_count.arg_cnt
                		
                #action end



                retval.stop = self.input.LT(-1)


                retval.tree = self.adaptor.rulePostProcessing(root_0)
                self.adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop)

            except RecognitionException, re:
                self.reportError(re)
                self.recover(self.input, re)
        finally:

            pass

        return retval

    # $ANTLR end fname

    class expr_list_return(object):
        def __init__(self):
            self.start = None
            self.stop = None

            self.arg_cnt = None
            self.tree = None


    # $ANTLR start expr_list
    # orangescape/model/engine/util/enginegrammar.g:251:1: expr_list returns [arg_cnt] : ( expr )? ( ',' expr )* ;
    def expr_list(self, ):

        retval = self.expr_list_return()
        retval.start = self.input.LT(1)

        root_0 = None

        char_literal43 = None
        expr42 = None

        expr44 = None


        char_literal43_tree = None

        try:
            try:
                # orangescape/model/engine/util/enginegrammar.g:253:7: ( ( expr )? ( ',' expr )* )
                # orangescape/model/engine/util/enginegrammar.g:253:7: ( expr )? ( ',' expr )*
                root_0 = self.adaptor.nil()

                #action start
                retval.arg_cnt = 0
                #action end
                # orangescape/model/engine/util/enginegrammar.g:253:22: ( expr )?
                alt19 = 2
                LA19_0 = self.input.LA(1)

                if ((LA19_0 >= WS and LA19_0 <= PUB_CELL) or LA19_0 == FNNAME or (LA19_0 >= 23 and LA19_0 <= 24) or LA19_0 == 29) :
                    alt19 = 1
                if alt19 == 1:
                    # orangescape/model/engine/util/enginegrammar.g:253:23: expr
                    self.following.append(self.FOLLOW_expr_in_expr_list1477)
                    expr42 = self.expr()
                    self.following.pop()

                    self.adaptor.addChild(root_0, expr42.tree)
                    #action start
                    retval.arg_cnt += getIncrementVal(self.rpnList)
                    #action end



                # orangescape/model/engine/util/enginegrammar.g:253:75: ( ',' expr )*
                while True: #loop20
                    alt20 = 2
                    LA20_0 = self.input.LA(1)

                    if (LA20_0 == 31) :
                        alt20 = 1


                    if alt20 == 1:
                        # orangescape/model/engine/util/enginegrammar.g:253:76: ',' expr
                        char_literal43 = self.input.LT(1)
                        self.match(self.input, 31, self.FOLLOW_31_in_expr_list1484)


                        char_literal43_tree = self.adaptor.createWithPayload(char_literal43)
                        self.adaptor.addChild(root_0, char_literal43_tree)

                        self.following.append(self.FOLLOW_expr_in_expr_list1486)
                        expr44 = self.expr()
                        self.following.pop()

                        self.adaptor.addChild(root_0, expr44.tree)
                        #action start
                        retval.arg_cnt += getIncrementVal(self.rpnList)
                        #action end


                    else:
                        break #loop20





                retval.stop = self.input.LT(-1)


                retval.tree = self.adaptor.rulePostProcessing(root_0)
                self.adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop)

            except RecognitionException, re:
                self.reportError(re)
                self.recover(self.input, re)
        finally:

            pass

        return retval

    # $ANTLR end expr_list


    # lookup tables for DFA #9

    DFA9_eot = DFA.unpack(
        u"\4\uffff"
        )

    DFA9_eof = DFA.unpack(
        u"\1\1\3\uffff"
        )

    DFA9_min = DFA.unpack(
        u"\1\4\1\uffff\1\4\1\uffff"
        )

    DFA9_max = DFA.unpack(
        u"\1\37\1\uffff\1\36\1\uffff"
        )

    DFA9_accept = DFA.unpack(
        u"\1\uffff\1\2\1\uffff\1\1"
        )

    DFA9_special = DFA.unpack(
        u"\4\uffff"
        )

            
    DFA9_transition = [
        DFA.unpack(u"\1\2\13\uffff\11\1\2\3\3\uffff\2\1"),
        DFA.unpack(u""),
        DFA.unpack(u"\1\2\24\uffff\2\3\3\uffff\1\1"),
        DFA.unpack(u"")
    ]

    # class definition for DFA #9

    DFA9 = DFA
 

    FOLLOW_expr_in_formula53 = frozenset([1])
    FOLLOW_prec0_expr_in_expr71 = frozenset([1, 16, 17, 18, 19, 20, 21])
    FOLLOW_16_in_expr115 = frozenset([4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 15, 23, 24, 29])
    FOLLOW_17_in_expr137 = frozenset([4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 15, 23, 24, 29])
    FOLLOW_18_in_expr159 = frozenset([4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 15, 23, 24, 29])
    FOLLOW_19_in_expr181 = frozenset([4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 15, 23, 24, 29])
    FOLLOW_20_in_expr203 = frozenset([4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 15, 23, 24, 29])
    FOLLOW_21_in_expr225 = frozenset([4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 15, 23, 24, 29])
    FOLLOW_prec0_expr_in_expr255 = frozenset([1, 16, 17, 18, 19, 20, 21])
    FOLLOW_prec1_expr_in_prec0_expr285 = frozenset([1, 22])
    FOLLOW_22_in_prec0_expr327 = frozenset([4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 15, 23, 24, 29])
    FOLLOW_prec1_expr_in_prec0_expr357 = frozenset([1, 22])
    FOLLOW_prec2_expr_in_prec1_expr387 = frozenset([1, 23, 24])
    FOLLOW_23_in_prec1_expr431 = frozenset([4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 15, 23, 24, 29])
    FOLLOW_24_in_prec1_expr453 = frozenset([4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 15, 23, 24, 29])
    FOLLOW_prec2_expr_in_prec1_expr483 = frozenset([1, 23, 24])
    FOLLOW_prec3_expr_in_prec2_expr513 = frozenset([1, 4, 25, 26])
    FOLLOW_WS_in_prec2_expr537 = frozenset([4, 25, 26])
    FOLLOW_25_in_prec2_expr561 = frozenset([4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 15, 23, 24, 29])
    FOLLOW_26_in_prec2_expr583 = frozenset([4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 15, 23, 24, 29])
    FOLLOW_WS_in_prec2_expr601 = frozenset([4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 15, 23, 24, 29])
    FOLLOW_prec3_expr_in_prec2_expr617 = frozenset([1, 4, 25, 26])
    FOLLOW_prec4_expr_in_prec3_expr647 = frozenset([1, 27])
    FOLLOW_27_in_prec3_expr689 = frozenset([4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 15, 23, 24, 29])
    FOLLOW_prec4_expr_in_prec3_expr719 = frozenset([1, 27])
    FOLLOW_prec5_expr_in_prec4_expr749 = frozenset([1, 28])
    FOLLOW_28_in_prec4_expr771 = frozenset([1])
    FOLLOW_leadingTrailingWSAtom_in_prec5_expr801 = frozenset([1])
    FOLLOW_24_in_prec5_expr806 = frozenset([4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 15, 29])
    FOLLOW_23_in_prec5_expr812 = frozenset([4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 15, 29])
    FOLLOW_leadingTrailingWSAtom_in_prec5_expr817 = frozenset([1])
    FOLLOW_WS_in_leadingTrailingWSAtom842 = frozenset([4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 15, 29])
    FOLLOW_atom_in_leadingTrailingWSAtom846 = frozenset([1, 4])
    FOLLOW_WS_in_leadingTrailingWSAtom849 = frozenset([1, 4])
    FOLLOW_INT_in_atom880 = frozenset([1])
    FOLLOW_FLOAT_in_atom896 = frozenset([1])
    FOLLOW_BOOLEAN_CONST_in_atom912 = frozenset([1])
    FOLLOW_STR_CONST_in_atom929 = frozenset([1])
    FOLLOW_CELL_REF_3D_PUBLIC_in_atom942 = frozenset([1])
    FOLLOW_CELL_REF_3D_SUGAR_in_atom952 = frozenset([1])
    FOLLOW_CELL_REF_in_atom963 = frozenset([1])
    FOLLOW_AREA_REF_in_atom979 = frozenset([1])
    FOLLOW_PUB_CELL_in_atom993 = frozenset([1])
    FOLLOW_fname_in_atom1009 = frozenset([1])
    FOLLOW_parenthesis_in_atom1021 = frozenset([1])
    FOLLOW_29_in_parenthesis1412 = frozenset([4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 15, 23, 24, 29])
    FOLLOW_WS_in_parenthesis1415 = frozenset([4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 15, 23, 24, 29])
    FOLLOW_expr_in_parenthesis1419 = frozenset([4, 30])
    FOLLOW_WS_in_parenthesis1422 = frozenset([4, 30])
    FOLLOW_30_in_parenthesis1426 = frozenset([1])
    FOLLOW_FNNAME_in_fname1441 = frozenset([4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 15, 23, 24, 29, 30, 31])
    FOLLOW_expr_list_in_fname1451 = frozenset([30])
    FOLLOW_30_in_fname1453 = frozenset([1])
    FOLLOW_expr_in_expr_list1477 = frozenset([1, 31])
    FOLLOW_31_in_expr_list1484 = frozenset([4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 15, 23, 24, 29])
    FOLLOW_expr_in_expr_list1486 = frozenset([1, 31])

