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

📄 exprlexer.cs

📁 antlr小例子 。
💻 CS
📖 第 1 页 / 共 2 页
字号:
// $ANTLR 3.0b5 Expr.g 2006-12-27 11:42:28

using System;
using Antlr.Runtime;
using IList 		= System.Collections.IList;
using ArrayList 	= System.Collections.ArrayList;
using Stack 		= Antlr.Runtime.Collections.StackList;



public class ExprLexer : Lexer 
{
    public const int T10 = 10;
    public const int T11 = 11;
    public const int T9 = 9;
    public const int INT = 6;
    public const int EOF = -1;
    public const int WS = 7;
    public const int T12 = 12;
    public const int Tokens = 14;
    public const int T8 = 8;
    public const int T13 = 13;
    public const int NEWLINE = 4;
    public const int ID = 5;

    public ExprLexer() 
    {
		InitializeCyclicDFAs();
    }
    public ExprLexer(ICharStream input) 
		: base(input)
	{
		InitializeCyclicDFAs();
    }
    
    override public string GrammarFileName
    {
    	get { return "Expr.g";} 
    }

    // $ANTLR start T8 
    public void mT8() // throws RecognitionException [2]
    {
		try {
			ruleNestingLevel++;
			int _type = T8;
			int _start = CharIndex;
			int _line = Line;
			int _charPosition = CharPositionInLine;
			int _channel = Token.DEFAULT_CHANNEL;
			// Expr.g:7:6: ( '=' )
			// Expr.g:7:6: '='
			{
				Match('=');
			}

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

    // $ANTLR end T8

    // $ANTLR start T9 
    public void mT9() // throws RecognitionException [2]
    {
        try 
    	{
            ruleNestingLevel++;
            int _type = T9;
            int _start = CharIndex;
            int _line = Line;
            int _charPosition = CharPositionInLine;
            int _channel = Token.DEFAULT_CHANNEL;
            // Expr.g:8:6: ( '+' )
            // Expr.g:8:6: '+'
            {
            	Match('+'); 
            
            }
    
    
            
                    if ( (token == null) && (ruleNestingLevel == 1) )
                    {
                        Emit(_type, _line, _charPosition, _channel, _start, CharIndex-1);
                    }
            
                        }
        finally 
    	{
            ruleNestingLevel--;
        }
    }
    // $ANTLR end T9

    // $ANTLR start T10 
    public void mT10() // throws RecognitionException [2]
    {
        try 
    	{
            ruleNestingLevel++;
            int _type = T10;
            int _start = CharIndex;
            int _line = Line;
            int _charPosition = CharPositionInLine;
            int _channel = Token.DEFAULT_CHANNEL;
            // Expr.g:9:7: ( '-' )
            // Expr.g:9:7: '-'
            {
            	Match('-'); 
            
            }
    
    
            
                    if ( (token == null) && (ruleNestingLevel == 1) )
                    {
                        Emit(_type, _line, _charPosition, _channel, _start, CharIndex-1);
                    }
            
                        }
        finally 
    	{
            ruleNestingLevel--;
        }
    }
    // $ANTLR end T10

    // $ANTLR start T11 
    public void mT11() // throws RecognitionException [2]
    {
        try 
    	{
            ruleNestingLevel++;
            int _type = T11;
            int _start = CharIndex;
            int _line = Line;
            int _charPosition = CharPositionInLine;
            int _channel = Token.DEFAULT_CHANNEL;
            // Expr.g:10:7: ( '*' )
            // Expr.g:10:7: '*'
            {
            	Match('*'); 
            
            }
    
    
            
                    if ( (token == null) && (ruleNestingLevel == 1) )
                    {
                        Emit(_type, _line, _charPosition, _channel, _start, CharIndex-1);
                    }
            
                        }
        finally 
    	{
            ruleNestingLevel--;
        }
    }
    // $ANTLR end T11

    // $ANTLR start T12 
    public void mT12() // throws RecognitionException [2]
    {
        try 
    	{
            ruleNestingLevel++;
            int _type = T12;
            int _start = CharIndex;
            int _line = Line;
            int _charPosition = CharPositionInLine;
            int _channel = Token.DEFAULT_CHANNEL;
            // Expr.g:11:7: ( '(' )
            // Expr.g:11:7: '('
            {
            	Match('('); 
            
            }
    
    
            
                    if ( (token == null) && (ruleNestingLevel == 1) )
                    {
                        Emit(_type, _line, _charPosition, _channel, _start, CharIndex-1);
                    }
            
                        }
        finally 
    	{
            ruleNestingLevel--;
        }
    }
    // $ANTLR end T12

    // $ANTLR start T13 
    public void mT13() // throws RecognitionException [2]
    {
        try 
    	{
            ruleNestingLevel++;
            int _type = T13;
            int _start = CharIndex;
            int _line = Line;
            int _charPosition = CharPositionInLine;
            int _channel = Token.DEFAULT_CHANNEL;
            // Expr.g:12:7: ( ')' )
            // Expr.g:12:7: ')'
            {
            	Match(')'); 
            
            }
    
    
            
                    if ( (token == null) && (ruleNestingLevel == 1) )
                    {
                        Emit(_type, _line, _charPosition, _channel, _start, CharIndex-1);
                    }
            
                        }
        finally 
    	{
            ruleNestingLevel--;
        }
    }
    // $ANTLR end T13

    // $ANTLR start ID 
    public void mID() // throws RecognitionException [2]
    {
        try 
    	{
            ruleNestingLevel++;
            int _type = ID;
            int _start = CharIndex;
            int _line = Line;
            int _charPosition = CharPositionInLine;
            int _channel = Token.DEFAULT_CHANNEL;
            // Expr.g:36:9: ( ( ('a'..'z'|'A'..'Z'))+ )
            // Expr.g:36:9: ( ('a'..'z'|'A'..'Z'))+
            {
            	// Expr.g:36:9: ( ('a'..'z'|'A'..'Z'))+
            	int cnt1 = 0;
            	do 
            	{
            	    int alt1 = 2;
            	    int LA1_0 = input.LA(1);
            	    if ( ((LA1_0 >= 'A' && LA1_0 <= 'Z') || (LA1_0 >= 'a' && LA1_0 <= 'z')) )
            	    {
            	        alt1 = 1;
            	    }
            	    
            	
            	    switch (alt1) 
            		{
            			case 1 :
            			    // Expr.g:36:10: ('a'..'z'|'A'..'Z')
            			    {
            			    	if ( (input.LA(1) >= 'A' && input.LA(1) <= 'Z') || (input.LA(1) >= 'a' && input.LA(1) <= 'z') ) 
            			    	{
            			    	    input.Consume();
            			    	
            			    	}
            			    	else 
            			    	{
            			    	    MismatchedSetException mse =
            			    	        new MismatchedSetException(null,input);
            			    	    Recover(mse);    throw mse;
            			    	}

            			    
            			    }
            			    break;
            	
            			default:
            			    if ( cnt1 >= 1 ) goto loop1;
            		            EarlyExitException eee =
            		                new EarlyExitException(1, input);
            		            throw eee;
            	    }
            	    cnt1++;
            	} while (true);
            	
            	loop1:
            		;	// Stops C# compiler whinging that label 'loop1' has no statements

⌨️ 快捷键说明

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