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

📄 exprlexer.cs

📁 antlr小例子 。
💻 CS
📖 第 1 页 / 共 2 页
字号:

            
            }
    
    
            
                    if ( (token == null) && (ruleNestingLevel == 1) )
                    {
                        Emit(_type, _line, _charPosition, _channel, _start, CharIndex-1);
                    }
            
                        }
        finally 
    	{
            ruleNestingLevel--;
        }
    }
    // $ANTLR end ID

    // $ANTLR start INT 
    public void mINT() // throws RecognitionException [2]
    {
        try 
    	{
            ruleNestingLevel++;
            int _type = INT;
            int _start = CharIndex;
            int _line = Line;
            int _charPosition = CharPositionInLine;
            int _channel = Token.DEFAULT_CHANNEL;
            // Expr.g:37:9: ( ( '0' .. '9' )+ )
            // Expr.g:37:9: ( '0' .. '9' )+
            {
            	// Expr.g:37:9: ( '0' .. '9' )+
            	int cnt2 = 0;
            	do 
            	{
            	    int alt2 = 2;
            	    int LA2_0 = input.LA(1);
            	    if ( ((LA2_0 >= '0' && LA2_0 <= '9')) )
            	    {
            	        alt2 = 1;
            	    }
            	    
            	
            	    switch (alt2) 
            		{
            			case 1 :
            			    // Expr.g:37:9: '0' .. '9'
            			    {
            			    	MatchRange('0','9'); 
            			    
            			    }
            			    break;
            	
            			default:
            			    if ( cnt2 >= 1 ) goto loop2;
            		            EarlyExitException eee =
            		                new EarlyExitException(2, input);
            		            throw eee;
            	    }
            	    cnt2++;
            	} while (true);
            	
            	loop2:
            		;	// Stops C# compiler whinging that label 'loop2' has no statements

            
            }
    
    
            
                    if ( (token == null) && (ruleNestingLevel == 1) )
                    {
                        Emit(_type, _line, _charPosition, _channel, _start, CharIndex-1);
                    }
            
                        }
        finally 
    	{
            ruleNestingLevel--;
        }
    }
    // $ANTLR end INT

    // $ANTLR start NEWLINE 
    public void mNEWLINE() // throws RecognitionException [2]
    {
        try 
    	{
            ruleNestingLevel++;
            int _type = NEWLINE;
            int _start = CharIndex;
            int _line = Line;
            int _charPosition = CharPositionInLine;
            int _channel = Token.DEFAULT_CHANNEL;
            // Expr.g:38:9: ( ( '\\r' )? '\\n' )
            // Expr.g:38:9: ( '\\r' )? '\\n'
            {
            	// Expr.g:38:9: ( '\\r' )?
            	int alt3 = 2;
            	int LA3_0 = input.LA(1);
            	if ( (LA3_0 == '\r') )
            	{
            	    alt3 = 1;
            	}
            	switch (alt3) 
            	{
            	    case 1 :
            	        // Expr.g:38:9: '\\r'
            	        {
            	        	Match('\r'); 
            	        
            	        }
            	        break;
            	
            	}

            	Match('\n'); 
            
            }
    
    
            
                    if ( (token == null) && (ruleNestingLevel == 1) )
                    {
                        Emit(_type, _line, _charPosition, _channel, _start, CharIndex-1);
                    }
            
                        }
        finally 
    	{
            ruleNestingLevel--;
        }
    }
    // $ANTLR end NEWLINE

    // $ANTLR start WS 
    public void mWS() // throws RecognitionException [2]
    {
        try {
            ruleNestingLevel++;
            int _type = WS;
            int _start = CharIndex;
            int _line = Line;
            int _charPosition = CharPositionInLine;
            int _channel = Token.DEFAULT_CHANNEL;
            // Expr.g:39:9: ( ( (' '|'\\t'))+ )
            // Expr.g:39:9: ( (' '|'\\t'))+
            {
            	// Expr.g:39:9: ( (' '|'\\t'))+
            	int cnt4 = 0;
            	do 
            	{
            	    int alt4 = 2;
            	    int LA4_0 = input.LA(1);
            	    if ( (LA4_0 == '\t' || LA4_0 == ' ') ){
            	        alt4 = 1;
            	    }
            	    
            	
            	    switch (alt4) 
            		{
            			case 1 :
            			    // Expr.g:39:10: (' '|'\\t')
            			    {
            			    	if ( input.LA(1) == '\t' || input.LA(1) == ' ' ) {
            			    	    input.Consume();
            			    	
            			    	} else  {
            			    	    MismatchedSetException mse =
            			    	        new MismatchedSetException(null,input);
            			    	    Recover(mse);    throw mse;
            			    	}
            			    }
            			    break;
            	
            			default:
            			    if ( cnt4 >= 1 ) goto loop4;
            		            EarlyExitException eee =
            		                new EarlyExitException(4, input);
            		            throw eee;
            	    }
            	    cnt4++;
            	} while (true);
            	
            	loop4:
            		;	// Stops C# compiler whinging that label 'loop4' has no statements

            	 Skip(); 
            }
          
			if ( (token == null) && (ruleNestingLevel == 1) ){
				Emit(_type, _line, _charPosition, _channel, _start, CharIndex-1);
			}
        } finally {
            ruleNestingLevel--;
        }
    }
    // $ANTLR end WS

    override public void mTokens() // throws RecognitionException 
    {
        // Expr.g:1:10: ( T8 | T9 | T10 | T11 | T12 | T13 | ID | INT | NEWLINE | WS )
        int alt5 = 10;
        switch ( input.LA(1) ) 
        {
        case '=':
            alt5 = 1; break;
        case '+':
            alt5 = 2; break;
        case '-':
            alt5 = 3; break;
        case '*':
            alt5 = 4; break;
        case '(':
            alt5 = 5; break;
        case ')':
            alt5 = 6; break;
        case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': case 'G': case 'H': case 'I': 
		case 'J': case 'K': case 'L': case 'M': case 'N': case 'O': case 'P': case 'Q': case 'R': 
		case 'S': case 'T': case 'U': case 'V': case 'W': case 'X': case 'Y': case 'Z':
        case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': case 'g': case 'h': case 'i':
        case 'j': case 'k': case 'l': case 'm': case 'n': case 'o': case 'p': case 'q': case 'r':
        case 's': case 't': case 'u': case 'v': case 'w': case 'x': case 'y': case 'z':
            alt5 = 7;
            break;
        case '0': case '1': case '2': case '3': case '4': 
		case '5': case '6': case '7': case '8': case '9':
            alt5 = 8;
            break;
        case '\n': case '\r':
            alt5 = 9;
            break;
        case '\t': case ' ':
            alt5 = 10;
            break;
        	default:
        	    NoViableAltException nvae_d5s0 =
        	        new NoViableAltException("1:1: Tokens : ( T8 | T9 | T10 | T11 | T12 | T13 | ID | INT | NEWLINE | WS );", 5, 0, input);
        
        	    throw nvae_d5s0;
        }
        
        switch (alt5) 
        {
            case 1 :
                // Expr.g:1:10: T8
                { mT8(); } break;
            case 2 :
                // Expr.g:1:13: T9
                { mT9(); } break;
            case 3 :
                // Expr.g:1:16: T10
                { mT10(); } break;
            case 4 :
                // Expr.g:1:20: T11
                { mT11(); } break;
            case 5 :
                // Expr.g:1:24: T12
                { mT12(); } break;
            case 6 :
                // Expr.g:1:28: T13
                { mT13(); } break;
            case 7 :
                // Expr.g:1:32: ID
                { mID(); } break;
            case 8 :
                // Expr.g:1:35: INT
                { mINT(); } break;
            case 9 :
                // Expr.g:1:39: NEWLINE
                { mNEWLINE(); } break;
            case 10 :
                // Expr.g:1:47: WS
                { mWS(); } break;
        }
    }


	private void InitializeCyclicDFAs()
	{
	}

 
    
}

⌨️ 快捷键说明

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