// $ANTLR start "group"
    // MathExpr.g:90:1: group : ( '(' term ')' | NUMBER | TRUE | FALSE | ident | call );
    public MathExprParser.group_return group() // throws RecognitionException [1]
    {   
        MathExprParser.group_return retval = new MathExprParser.group_return();
        retval.Start = input.LT(1);
        int group_StartIndex = input.Index();
        AstNode root_0 = null;

        IToken char_literal9 = null;
        IToken char_literal11 = null;
        IToken NUMBER12 = null;
        IToken TRUE13 = null;
        IToken FALSE14 = null;
        MathExprParser.term_return term10 = default(MathExprParser.term_return);

        MathExprParser.ident_return ident15 = default(MathExprParser.ident_return);

        MathExprParser.call_return call16 = default(MathExprParser.call_return);


        AstNode char_literal9_tree=null;
        AstNode char_literal11_tree=null;
        AstNode NUMBER12_tree=null;
        AstNode TRUE13_tree=null;
        AstNode FALSE14_tree=null;

        try 
    	{
    	    if ( (state.backtracking > 0) && AlreadyParsedRule(input, 4) ) 
    	    {
    	    	return retval; 
    	    }
            // MathExpr.g:90:6: ( '(' term ')' | NUMBER | TRUE | FALSE | ident | call )
            int alt3 = 6;
            switch ( input.LA(1) ) 
            {
            case 51:
            	{
                alt3 = 1;
                }
                break;
            case NUMBER:
            	{
                alt3 = 2;
                }
                break;
            case TRUE:
            	{
                alt3 = 3;
                }
                break;
            case FALSE:
            	{
                alt3 = 4;
                }
                break;
            case IDENT:
            	{
                int LA3_5 = input.LA(2);

                if ( (LA3_5 == EOF || (LA3_5 >= IF && LA3_5 <= UNTIL) || (LA3_5 >= AND && LA3_5 <= OR) || (LA3_5 >= INT_DIV && LA3_5 <= INT_MOD) || LA3_5 == RETURN || (LA3_5 >= IDENT && LA3_5 <= BIT_OR) || (LA3_5 >= GE && LA3_5 <= 50) || (LA3_5 >= 52 && LA3_5 <= 55)) )
                {
                    alt3 = 5;
                }
                else if ( (LA3_5 == 51) )
                {
                    alt3 = 6;
                }
                else 
                {
                    if ( state.backtracking > 0 ) {state.failed = true; return retval;}
                    NoViableAltException nvae_d3s5 =
                        new NoViableAltException("", 3, 5, input);

                    throw nvae_d3s5;
                }
                }
                break;
            	default:
            	    if ( state.backtracking > 0 ) {state.failed = true; return retval;}
            	    NoViableAltException nvae_d3s0 =
            	        new NoViableAltException("", 3, 0, input);

            	    throw nvae_d3s0;
            }

            switch (alt3) 
            {
                case 1 :
                    // MathExpr.g:91:3: '(' term ')'
                    {
                    	root_0 = (AstNode)adaptor.GetNilNode();

                    	char_literal9=(IToken)Match(input,51,FOLLOW_51_in_group938); if (state.failed) return retval;
                    	PushFollow(FOLLOW_term_in_group941);
                    	term10 = term();
                    	state.followingStackPointer--;
                    	if (state.failed) return retval;
                    	if ( state.backtracking == 0 ) adaptor.AddChild(root_0, term10.Tree);
                    	char_literal11=(IToken)Match(input,52,FOLLOW_52_in_group943); if (state.failed) return retval;

                    }
                    break;
                case 2 :
                    // MathExpr.g:92:3: NUMBER
                    {
                    	root_0 = (AstNode)adaptor.GetNilNode();

                    	NUMBER12=(IToken)Match(input,NUMBER,FOLLOW_NUMBER_in_group948); if (state.failed) return retval;
                    	if ( state.backtracking == 0 )
                    	{NUMBER12_tree = (AstNode)adaptor.Create(NUMBER12);
                    		adaptor.AddChild(root_0, NUMBER12_tree);
                    	}

                    }
                    break;
                case 3 :
                    // MathExpr.g:93:3: TRUE
                    {
                    	root_0 = (AstNode)adaptor.GetNilNode();

                    	TRUE13=(IToken)Match(input,TRUE,FOLLOW_TRUE_in_group952); if (state.failed) return retval;
                    	if ( state.backtracking == 0 )
                    	{TRUE13_tree = (AstNode)adaptor.Create(TRUE13);
                    		adaptor.AddChild(root_0, TRUE13_tree);
                    	}

                    }
                    break;
                case 4 :
                    // MathExpr.g:94:3: FALSE
                    {
                    	root_0 = (AstNode)adaptor.GetNilNode();

                    	FALSE14=(IToken)Match(input,FALSE,FOLLOW_FALSE_in_group956); if (state.failed) return retval;
                    	if ( state.backtracking == 0 )
                    	{FALSE14_tree = (AstNode)adaptor.Create(FALSE14);
                    		adaptor.AddChild(root_0, FALSE14_tree);
                    	}

                    }
                    break;
                case 5 :
                    // MathExpr.g:95:3: ident
                    {
                    	root_0 = (AstNode)adaptor.GetNilNode();

                    	PushFollow(FOLLOW_ident_in_group960);
                    	ident15 = ident();
                    	state.followingStackPointer--;
                    	if (state.failed) return retval;
                    	if ( state.backtracking == 0 ) adaptor.AddChild(root_0, ident15.Tree);

                    }
                    break;
                case 6 :
                    // MathExpr.g:96:3: call
                    {
                    	root_0 = (AstNode)adaptor.GetNilNode();

                    	PushFollow(FOLLOW_call_in_group964);
                    	call16 = call();
                    	state.followingStackPointer--;
                    	if (state.failed) return retval;
                    	if ( state.backtracking == 0 ) adaptor.AddChild(root_0, call16.Tree);

                    }
                    break;

            }
            retval.Stop = input.LT(-1);

            if ( (state.backtracking==0) )
            {	retval.Tree = (AstNode)adaptor.RulePostProcessing(root_0);
            	adaptor.SetTokenBoundaries(retval.Tree, (IToken) retval.Start, (IToken) retval.Stop);}
        }
        catch (RecognitionException re) 
    	{
            ReportError(re);
            Recover(input,re);
    	// Conversion of the second argument necessary, but harmless
    	retval.Tree = (AstNode)adaptor.ErrorNode(input, (IToken) retval.Start, input.LT(-1), re);

        }
        finally 
    	{
            if ( state.backtracking > 0 ) 
            {
            	Memoize(input, 4, group_StartIndex); 
            }
        }
        return retval;
    }
示例#2
0
    // $ANTLR start "group"
    // antlr_temp_dir\\MathExpr.g:75:1: group : ( '(' term ')' | NUMBER -> NUMBER[double.Parse($NUMBER.text, NFI)] | ident );
    public MathExprParser.group_return group() // throws RecognitionException [1]
    {   
        MathExprParser.group_return retval = new MathExprParser.group_return();
        retval.Start = input.LT(1);

        object root_0 = null;

        IToken char_literal1 = null;
        IToken char_literal3 = null;
        IToken NUMBER4 = null;
        MathExprParser.term_return term2 = default(MathExprParser.term_return);

        MathExprParser.ident_return ident5 = default(MathExprParser.ident_return);


        object char_literal1_tree=null;
        object char_literal3_tree=null;
        object NUMBER4_tree=null;
        RewriteRuleTokenStream stream_NUMBER = new RewriteRuleTokenStream(adaptor,"token NUMBER");

        try 
    	{
            // antlr_temp_dir\\MathExpr.g:75:6: ( '(' term ')' | NUMBER -> NUMBER[double.Parse($NUMBER.text, NFI)] | ident )
            int alt1 = 3;
            switch ( input.LA(1) ) 
            {
            case 17:
            	{
                alt1 = 1;
                }
                break;
            case NUMBER:
            	{
                alt1 = 2;
                }
                break;
            case IDENT:
            	{
                alt1 = 3;
                }
                break;
            	default:
            	    NoViableAltException nvae_d1s0 =
            	        new NoViableAltException("", 1, 0, input);

            	    throw nvae_d1s0;
            }

            switch (alt1) 
            {
                case 1 :
                    // antlr_temp_dir\\MathExpr.g:76:3: '(' term ')'
                    {
                    	root_0 = (object)adaptor.GetNilNode();

                    	char_literal1=(IToken)Match(input,17,FOLLOW_17_in_group366); 
                    	PushFollow(FOLLOW_term_in_group369);
                    	term2 = term();
                    	state.followingStackPointer--;

                    	adaptor.AddChild(root_0, term2.Tree);
                    	char_literal3=(IToken)Match(input,18,FOLLOW_18_in_group371); 

                    }
                    break;
                case 2 :
                    // antlr_temp_dir\\MathExpr.g:77:3: NUMBER
                    {
                    	NUMBER4=(IToken)Match(input,NUMBER,FOLLOW_NUMBER_in_group376);  
                    	stream_NUMBER.Add(NUMBER4);



                    	// AST REWRITE
                    	// elements:          NUMBER
                    	// token labels:      
                    	// rule labels:       retval
                    	// token list labels: 
                    	// rule list labels:  
                    	// wildcard labels: 
                    	retval.Tree = root_0;
                    	RewriteRuleSubtreeStream stream_retval = new RewriteRuleSubtreeStream(adaptor, "rule retval", retval!=null ? retval.Tree : null);

                    	root_0 = (object)adaptor.GetNilNode();
                    	// 77:10: -> NUMBER[double.Parse($NUMBER.text, NFI)]
                    	{
                    	    adaptor.AddChild(root_0, new NumAstNode(NUMBER, double.Parse(((NUMBER4 != null) ? NUMBER4.Text : null), NFI)));

                    	}

                    	retval.Tree = root_0;retval.Tree = root_0;
                    }
                    break;
                case 3 :
                    // antlr_temp_dir\\MathExpr.g:78:3: ident
                    {
                    	root_0 = (object)adaptor.GetNilNode();

                    	PushFollow(FOLLOW_ident_in_group388);
                    	ident5 = ident();
                    	state.followingStackPointer--;

                    	adaptor.AddChild(root_0, ident5.Tree);

                    }
                    break;

            }
            retval.Stop = input.LT(-1);

            	retval.Tree = (object)adaptor.RulePostProcessing(root_0);
            	adaptor.SetTokenBoundaries(retval.Tree, (IToken) retval.Start, (IToken) retval.Stop);
        }
        catch (RecognitionException re) 
    	{
            ReportError(re);
            Recover(input,re);
    	// Conversion of the second argument necessary, but harmless
    	retval.Tree = (object)adaptor.ErrorNode(input, (IToken) retval.Start, input.LT(-1), re);

        }
        finally 
    	{
        }
        return retval;
    }
    // $ANTLR start "group"
    // MathExpr.g:153:1: group : ( groupExpr | groupInit );
    public MathExprParser.group_return group() // throws RecognitionException [1]
    {   
        MathExprParser.group_return retval = new MathExprParser.group_return();
        retval.Start = input.LT(1);
        int group_StartIndex = input.Index();
        AstNode root_0 = null;

        MathExprParser.groupExpr_return groupExpr68 = default(MathExprParser.groupExpr_return);

        MathExprParser.groupInit_return groupInit69 = default(MathExprParser.groupInit_return);



        try 
    	{
    	    if ( (state.backtracking > 0) && AlreadyParsedRule(input, 14) ) 
    	    {
    	    	return retval; 
    	    }
            // MathExpr.g:153:6: ( groupExpr | groupInit )
            int alt16 = 2;
            switch ( input.LA(1) ) 
            {
            case IDENT:
            	{
                int LA16_1 = input.LA(2);

                if ( (synpred30_MathExpr()) )
                {
                    alt16 = 1;
                }
                else if ( (true) )
                {
                    alt16 = 2;
                }
                else 
                {
                    if ( state.backtracking > 0 ) {state.failed = true; return retval;}
                    NoViableAltException nvae_d16s1 =
                        new NoViableAltException("", 16, 1, input);

                    throw nvae_d16s1;
                }
                }
                break;
            case INCR:
            case DECR:
            	{
                alt16 = 1;
                }
                break;
            case TRUE:
            case FALSE:
            case NUMBER:
            case STRINGVAL:
            case 74:
            	{
                alt16 = 2;
                }
                break;
            	default:
            	    if ( state.backtracking > 0 ) {state.failed = true; return retval;}
            	    NoViableAltException nvae_d16s0 =
            	        new NoViableAltException("", 16, 0, input);

            	    throw nvae_d16s0;
            }

            switch (alt16) 
            {
                case 1 :
                    // MathExpr.g:154:2: groupExpr
                    {
                    	root_0 = (AstNode)adaptor.GetNilNode();

                    	PushFollow(FOLLOW_groupExpr_in_group1458);
                    	groupExpr68 = groupExpr();
                    	state.followingStackPointer--;
                    	if (state.failed) return retval;
                    	if ( state.backtracking == 0 ) adaptor.AddChild(root_0, groupExpr68.Tree);

                    }
                    break;
                case 2 :
                    // MathExpr.g:154:15: groupInit
                    {
                    	root_0 = (AstNode)adaptor.GetNilNode();

                    	PushFollow(FOLLOW_groupInit_in_group1463);
                    	groupInit69 = groupInit();
                    	state.followingStackPointer--;
                    	if (state.failed) return retval;
                    	if ( state.backtracking == 0 ) adaptor.AddChild(root_0, groupInit69.Tree);

                    }
                    break;

            }
            retval.Stop = input.LT(-1);

            if ( (state.backtracking==0) )
            {	retval.Tree = (AstNode)adaptor.RulePostProcessing(root_0);
            	adaptor.SetTokenBoundaries(retval.Tree, (IToken) retval.Start, (IToken) retval.Stop);}
        }
        catch (RecognitionException re) 
    	{
            ReportError(re);
            Recover(input,re);
    	// Conversion of the second argument necessary, but harmless
    	retval.Tree = (AstNode)adaptor.ErrorNode(input, (IToken) retval.Start, input.LT(-1), re);

        }
        finally 
    	{
            if ( state.backtracking > 0 ) 
            {
            	Memoize(input, 14, group_StartIndex); 
            }
        }
        return retval;
    }