⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 exprparser.cs

📁 antlr小例子 。
💻 CS
📖 第 1 页 / 共 2 页
字号:
        
        
        CommonTree char_literal10_tree=null;
        CommonTree char_literal11_tree=null;
    
        try 
    	{
            // Expr.g:24:9: ( multExpr ( ( '+'^^ | '-'^^ ) multExpr )* )
            // Expr.g:24:9: multExpr ( ( '+'^^ | '-'^^ ) multExpr )*
            {
            	root_0 = (CommonTree)adaptor.GetNilNode();
            
            	PushFollow(FOLLOW_multExpr_in_expr135);
            	multExpr9 = multExpr();
            	followingStackPointer_--;
            	
            	adaptor.AddChild(root_0, multExpr9.Tree);
            	// Expr.g:24:18: ( ( '+'^^ | '-'^^ ) multExpr )*
            	do 
            	{
            	    int alt4 = 2;
            	    int LA4_0 = input.LA(1);
            	    if ( ((LA4_0 >= 9 && LA4_0 <= 10)) )
            	    {
            	        alt4 = 1;
            	    }
            	    
            	
            	    switch (alt4) 
            		{
            			case 1 :
            			    // Expr.g:24:19: ( '+'^^ | '-'^^ ) multExpr
            			    {
            			    	CommonTree root_1 = (CommonTree)adaptor.GetNilNode();
            			    
            			    	// Expr.g:24:19: ( '+'^^ | '-'^^ )
            			    	int alt3 = 2;
            			    	int LA3_0 = input.LA(1);
            			    	if ( (LA3_0 == 9) )
            			    	{
            			    	    alt3 = 1;
            			    	}
            			    	else if ( (LA3_0 == 10) )
            			    	{
            			    	    alt3 = 2;
            			    	}
            			    	else 
            			    	{
            			    	    NoViableAltException nvae_d3s0 =
            			    	        new NoViableAltException("24:19: ( '+'^^ | '-'^^ )", 3, 0, input);
            			    	
            			    	    throw nvae_d3s0;
            			    	}
            			    	switch (alt3) 
            			    	{
            			    	    case 1 :
            			    	        // Expr.g:24:20: '+'^^
            			    	        {
            			    	        	CommonTree root_2 = (CommonTree)adaptor.GetNilNode();
            			    	        
            			    	        	char_literal10 = (IToken)input.LT(1);
            			    	        	Match(input,9,FOLLOW_9_in_expr139); 
            			    	        	char_literal10_tree = (CommonTree)adaptor.Create(char_literal10);
            			    	        	root_0 = (CommonTree)adaptor.BecomeRoot(char_literal10_tree, root_0);

            			    	        
            			    	        	adaptor.AddChild(root_1, root_2);
            			    	        
            			    	        }
            			    	        break;
            			    	    case 2 :
            			    	        // Expr.g:24:26: '-'^^
            			    	        {
            			    	        	CommonTree root_2 = (CommonTree)adaptor.GetNilNode();
            			    	        
            			    	        	char_literal11 = (IToken)input.LT(1);
            			    	        	Match(input,10,FOLLOW_10_in_expr142); 
            			    	        	char_literal11_tree = (CommonTree)adaptor.Create(char_literal11);
            			    	        	root_0 = (CommonTree)adaptor.BecomeRoot(char_literal11_tree, root_0);

            			    	        
            			    	        	adaptor.AddChild(root_1, root_2);
            			    	        
            			    	        }
            			    	        break;
            			    	
            			    	}

            			    	PushFollow(FOLLOW_multExpr_in_expr146);
            			    	multExpr12 = multExpr();
            			    	followingStackPointer_--;
            			    	
            			    	adaptor.AddChild(root_1, multExpr12.Tree);
            			    
            			    	adaptor.AddChild(root_0, root_1);
            			    
            			    }
            			    break;
            	
            			default:
            			    goto loop4;
            	    }
            	} while (true);
            	
            	loop4:
            		;	// Stops C# compiler whinging that label 'loop4' has no statements

            
            }
    
        }
        catch (RecognitionException re) 
    	{
            ReportError(re);
            Recover(input,re);
        }
        finally 
    	{
            retval.stop = input.LT(-1);
            
            	retval.tree = (CommonTree)adaptor.RulePostProcessing(root_0);
            	adaptor.SetTokenBoundaries(retval.Tree, retval.start, retval.stop);
    
        }
        return retval;
    }
    // $ANTLR end expr

    public class multExpr_return : ParserRuleReturnScope 
    {
        internal CommonTree tree;
        override public object Tree
        {
        	get { return tree; }
        }
    };
    
    // $ANTLR start multExpr
    // Expr.g:27:1: multExpr : atom ( '*'^^ atom )* ;
    public multExpr_return multExpr() // throws RecognitionException [1]
    {   
        multExpr_return retval = new multExpr_return();
        retval.start = input.LT(1);
        
        CommonTree root_0 = null;
    
        IToken char_literal14 = null;
        atom_return atom13 = null;

        atom_return atom15 = null;
        
        
        CommonTree char_literal14_tree=null;
    
        try 
    	{
            // Expr.g:28:9: ( atom ( '*'^^ atom )* )
            // Expr.g:28:9: atom ( '*'^^ atom )*
            {
            	root_0 = (CommonTree)adaptor.GetNilNode();
            
            	PushFollow(FOLLOW_atom_in_multExpr168);
            	atom13 = atom();
            	followingStackPointer_--;
            	
            	adaptor.AddChild(root_0, atom13.Tree);
            	// Expr.g:28:14: ( '*'^^ atom )*
            	do 
            	{
            	    int alt5 = 2;
            	    int LA5_0 = input.LA(1);
            	    if ( (LA5_0 == 11) )
            	    {
            	        alt5 = 1;
            	    }
            	    
            	
            	    switch (alt5) 
            		{
            			case 1 :
            			    // Expr.g:28:15: '*'^^ atom
            			    {
            			    	CommonTree root_1 = (CommonTree)adaptor.GetNilNode();
            			    
            			    	char_literal14 = (IToken)input.LT(1);
            			    	Match(input,11,FOLLOW_11_in_multExpr171); 
            			    	char_literal14_tree = (CommonTree)adaptor.Create(char_literal14);
            			    	root_0 = (CommonTree)adaptor.BecomeRoot(char_literal14_tree, root_0);

            			    	PushFollow(FOLLOW_atom_in_multExpr174);
            			    	atom15 = atom();
            			    	followingStackPointer_--;
            			    	
            			    	adaptor.AddChild(root_1, atom15.Tree);
            			    
            			    	adaptor.AddChild(root_0, root_1);
            			    
            			    }
            			    break;
            	
            			default:
            			    goto loop5;
            	    }
            	} while (true);
            	
            	loop5:
            		;	// Stops C# compiler whinging that label 'loop5' has no statements

            
            }
    
        }
        catch (RecognitionException re) 
    	{
            ReportError(re);
            Recover(input,re);
        }
        finally 
    	{
            retval.stop = input.LT(-1);
            
            	retval.tree = (CommonTree)adaptor.RulePostProcessing(root_0);
            	adaptor.SetTokenBoundaries(retval.Tree, retval.start, retval.stop);
    
        }
        return retval;
    }
    // $ANTLR end multExpr

    public class atom_return : ParserRuleReturnScope 
    {
        internal CommonTree tree;
        override public object Tree
        {
        	get { return tree; }
        }
    };
    
    // $ANTLR start atom
    // Expr.g:31:1: atom : ( INT | ID | '('! expr ')'! );
    public atom_return atom() // throws RecognitionException [1]
    {   
        atom_return retval = new atom_return();
        retval.start = input.LT(1);
        
        CommonTree root_0 = null;
    
        IToken INT16 = null;
        IToken ID17 = null;
        IToken char_literal18 = null;
        IToken char_literal20 = null;
        expr_return expr19 = null;
        
        
        CommonTree INT16_tree=null;
        CommonTree ID17_tree=null;
        CommonTree char_literal18_tree=null;
        CommonTree char_literal20_tree=null;
    
        try 
    	{
            // Expr.g:31:9: ( INT | ID | '('! expr ')'! )
            int alt6 = 3;
            switch ( input.LA(1) ) 
            {
            case INT:
                alt6 = 1;
                break;
            case ID:
                alt6 = 2;
                break;
            case 12:
                alt6 = 3;
                break;
            	default:
            	    NoViableAltException nvae_d6s0 =
            	        new NoViableAltException("31:1: atom : ( INT | ID | '('! expr ')'! );", 6, 0, input);
            
            	    throw nvae_d6s0;
            }
            
            switch (alt6) 
            {
                case 1 :
                    // Expr.g:31:9: INT
                    {
                    	root_0 = (CommonTree)adaptor.GetNilNode();
                    
                    	INT16 = (IToken)input.LT(1);
                    	Match(input,INT,FOLLOW_INT_in_atom191); 
                    	INT16_tree = (CommonTree)adaptor.Create(INT16);
                    	adaptor.AddChild(root_0, INT16_tree);

                    
                    }
                    break;
                case 2 :
                    // Expr.g:32:9: ID
                    {
                    	root_0 = (CommonTree)adaptor.GetNilNode();
                    
                    	ID17 = (IToken)input.LT(1);
                    	Match(input,ID,FOLLOW_ID_in_atom202); 
                    	ID17_tree = (CommonTree)adaptor.Create(ID17);
                    	adaptor.AddChild(root_0, ID17_tree);

                    
                    }
                    break;
                case 3 :
                    // Expr.g:33:9: '('! expr ')'!
                    {
                    	root_0 = (CommonTree)adaptor.GetNilNode();
                    
                    	char_literal18 = (IToken)input.LT(1);
                    	Match(input,12,FOLLOW_12_in_atom212); 
                    	PushFollow(FOLLOW_expr_in_atom215);
                    	expr19 = expr();
                    	followingStackPointer_--;
                    	
                    	adaptor.AddChild(root_0, expr19.Tree);
                    	char_literal20 = (IToken)input.LT(1);
                    	Match(input,13,FOLLOW_13_in_atom217); 
                    
                    }
                    break;
            
            }
        }
        catch (RecognitionException re) 
    	{
            ReportError(re);
            Recover(input,re);
        }
        finally 
    	{
            retval.stop = input.LT(-1);
            
            	retval.tree = (CommonTree)adaptor.RulePostProcessing(root_0);
            	adaptor.SetTokenBoundaries(retval.Tree, retval.start, retval.stop);
    
        }
        return retval;
    }
    // $ANTLR end atom


	private void InitializeCyclicDFAs()
	{
	}

 

    public static readonly BitSet FOLLOW_stat_in_prog43 = new BitSet(new ulong[]{0x0000000000001072UL});
    public static readonly BitSet FOLLOW_expr_in_stat66 = new BitSet(new ulong[]{0x0000000000000010UL});
    public static readonly BitSet FOLLOW_NEWLINE_in_stat68 = new BitSet(new ulong[]{0x0000000000000002UL});
    public static readonly BitSet FOLLOW_ID_in_stat89 = new BitSet(new ulong[]{0x0000000000000100UL});
    public static readonly BitSet FOLLOW_8_in_stat91 = new BitSet(new ulong[]{0x0000000000001060UL});
    public static readonly BitSet FOLLOW_expr_in_stat93 = new BitSet(new ulong[]{0x0000000000000010UL});
    public static readonly BitSet FOLLOW_NEWLINE_in_stat95 = new BitSet(new ulong[]{0x0000000000000002UL});
    public static readonly BitSet FOLLOW_NEWLINE_in_stat115 = new BitSet(new ulong[]{0x0000000000000002UL});
    public static readonly BitSet FOLLOW_multExpr_in_expr135 = new BitSet(new ulong[]{0x0000000000000602UL});
    public static readonly BitSet FOLLOW_9_in_expr139 = new BitSet(new ulong[]{0x0000000000001060UL});
    public static readonly BitSet FOLLOW_10_in_expr142 = new BitSet(new ulong[]{0x0000000000001060UL});
    public static readonly BitSet FOLLOW_multExpr_in_expr146 = new BitSet(new ulong[]{0x0000000000000602UL});
    public static readonly BitSet FOLLOW_atom_in_multExpr168 = new BitSet(new ulong[]{0x0000000000000802UL});
    public static readonly BitSet FOLLOW_11_in_multExpr171 = new BitSet(new ulong[]{0x0000000000001060UL});
    public static readonly BitSet FOLLOW_atom_in_multExpr174 = new BitSet(new ulong[]{0x0000000000000802UL});
    public static readonly BitSet FOLLOW_INT_in_atom191 = new BitSet(new ulong[]{0x0000000000000002UL});
    public static readonly BitSet FOLLOW_ID_in_atom202 = new BitSet(new ulong[]{0x0000000000000002UL});
    public static readonly BitSet FOLLOW_12_in_atom212 = new BitSet(new ulong[]{0x0000000000001060UL});
    public static readonly BitSet FOLLOW_expr_in_atom215 = new BitSet(new ulong[]{0x0000000000002000UL});
    public static readonly BitSet FOLLOW_13_in_atom217 = new BitSet(new ulong[]{0x0000000000000002UL});

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -