| Refresh | Home EGTry.com

lexer only


L1.g

lexer grammar L1;

ID: 'a' .. 'z'+;
WS: (' '|'\n'|'\r'|'\t')+;




L1.java

// $ANTLR 3.2 Sep 23, 2009 12:02:23 L1.g 2011-05-19 16:19:11

import org.antlr.runtime.*;
import java.util.Stack;
import java.util.List;
import java.util.ArrayList;

public class L1 extends Lexer {
    public static final int WS=5;
    public static final int ID=4;
    public static final int EOF=-1;

    // delegates
    // delegators

    public L1() {;} 
    public L1(CharStream input) {
        this(input, new RecognizerSharedState());
    }
    public L1(CharStream input, RecognizerSharedState state) {
        super(input,state);

    }
    public String getGrammarFileName() { return "L1.g"; }

    // $ANTLR start "ID"
    public final void mID() throws RecognitionException {
        try {
            int _type = ID;
            int _channel = DEFAULT_TOKEN_CHANNEL;
            // L1.g:3:3: ( ( 'a' .. 'z' )+ )
            // L1.g:3:5: ( 'a' .. 'z' )+
            {
            // L1.g:3:5: ( 'a' .. 'z' )+
            int cnt1=0;
            loop1:
            do {
                int alt1=2;
                int LA1_0 = input.LA(1);

                if ( ((LA1_0>='a' && LA1_0<='z')) ) {
                    alt1=1;
                }


                switch (alt1) {
            	case 1 :
            	    // L1.g:3:5: 'a' .. 'z'
            	    {
            	    matchRange('a','z'); 

            	    }
            	    break;

            	default :
            	    if ( cnt1 >= 1 ) break loop1;
                        EarlyExitException eee =
                            new EarlyExitException(1, input);
                        throw eee;
                }
                cnt1++;
            } while (true);


            }

            state.type = _type;
            state.channel = _channel;
        }
        finally {
        }
    }
    // $ANTLR end "ID"

    // $ANTLR start "WS"
    public final void mWS() throws RecognitionException {
        try {
            int _type = WS;
            int _channel = DEFAULT_TOKEN_CHANNEL;
            // L1.g:4:3: ( ( ' ' | '\\n' | '\\r' | '\\t' )+ )
            // L1.g:4:5: ( ' ' | '\\n' | '\\r' | '\\t' )+
            {
            // L1.g:4:5: ( ' ' | '\\n' | '\\r' | '\\t' )+
            int cnt2=0;
            loop2:
            do {
                int alt2=2;
                int LA2_0 = input.LA(1);

                if ( ((LA2_0>='\t' && LA2_0<='\n')||LA2_0=='\r'||LA2_0==' ') ) {
                    alt2=1;
                }


                switch (alt2) {
            	case 1 :
            	    // L1.g:
            	    {
            	    if ( (input.LA(1)>='\t' && input.LA(1)<='\n')||input.LA(1)=='\r'||input.LA(1)==' ' ) {
            	        input.consume();

            	    }
            	    else {
            	        MismatchedSetException mse = new MismatchedSetException(null,input);
            	        recover(mse);
            	        throw mse;}


            	    }
            	    break;

            	default :
            	    if ( cnt2 >= 1 ) break loop2;
                        EarlyExitException eee =
                            new EarlyExitException(2, input);
                        throw eee;
                }
                cnt2++;
            } while (true);


            }

            state.type = _type;
            state.channel = _channel;
        }
        finally {
        }
    }
    // $ANTLR end "WS"

    public void mTokens() throws RecognitionException {
        // L1.g:1:8: ( ID | WS )
        int alt3=2;
        int LA3_0 = input.LA(1);

        if ( ((LA3_0>='a' && LA3_0<='z')) ) {
            alt3=1;
        }
        else if ( ((LA3_0>='\t' && LA3_0<='\n')||LA3_0=='\r'||LA3_0==' ') ) {
            alt3=2;
        }
        else {
            NoViableAltException nvae =
                new NoViableAltException("", 3, 0, input);

            throw nvae;
        }
        switch (alt3) {
            case 1 :
                // L1.g:1:10: ID
                {
                mID(); 

                }
                break;
            case 2 :
                // L1.g:1:13: WS
                {
                mWS(); 

                }
                break;

        }

    }


 

}