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

📄 antlrlexer.java

📁 antlr最新版本V3源代码
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
// $ANTLR 2.7.7 (2006-01-29): "antlr.g" -> "ANTLRLexer.java"$/* [The "BSD licence"] Copyright (c) 2005-2006 Terence Parr All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright    notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright    notice, this list of conditions and the following disclaimer in the    documentation and/or other materials provided with the distribution. 3. The name of the author may not be used to endorse or promote products    derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.*/package org.antlr.tool;import java.util.*;import java.io.*;import org.antlr.analysis.*;import org.antlr.misc.*;import antlr.*;import java.io.InputStream;import antlr.TokenStreamException;import antlr.TokenStreamIOException;import antlr.TokenStreamRecognitionException;import antlr.CharStreamException;import antlr.CharStreamIOException;import antlr.ANTLRException;import java.io.Reader;import java.util.Hashtable;import antlr.CharScanner;import antlr.InputBuffer;import antlr.ByteBuffer;import antlr.CharBuffer;import antlr.Token;import antlr.CommonToken;import antlr.RecognitionException;import antlr.NoViableAltForCharException;import antlr.MismatchedCharException;import antlr.TokenStream;import antlr.ANTLRHashString;import antlr.LexerSharedInputState;import antlr.collections.impl.BitSet;import antlr.SemanticException;public class ANTLRLexer extends antlr.CharScanner implements ANTLRTokenTypes, TokenStream {    /** advance the current column number by one; don't do tabs.     *  we want char position in line to be sent to AntlrWorks.     */    public void tab() {		setColumn( getColumn()+1 );    }public ANTLRLexer(InputStream in) {	this(new ByteBuffer(in));}public ANTLRLexer(Reader in) {	this(new CharBuffer(in));}public ANTLRLexer(InputBuffer ib) {	this(new LexerSharedInputState(ib));}public ANTLRLexer(LexerSharedInputState state) {	super(state);	caseSensitiveLiterals = true;	setCaseSensitive(true);	literals = new Hashtable();	literals.put(new ANTLRHashString("lexer", this), new Integer(40));	literals.put(new ANTLRHashString("scope", this), new Integer(32));	literals.put(new ANTLRHashString("finally", this), new Integer(64));	literals.put(new ANTLRHashString("throws", this), new Integer(58));	literals.put(new ANTLRHashString("fragment", this), new Integer(36));	literals.put(new ANTLRHashString("private", this), new Integer(54));	literals.put(new ANTLRHashString("grammar", this), new Integer(42));	literals.put(new ANTLRHashString("tokens", this), new Integer(5));	literals.put(new ANTLRHashString("options", this), new Integer(4));	literals.put(new ANTLRHashString("parser", this), new Integer(6));	literals.put(new ANTLRHashString("tree", this), new Integer(41));	literals.put(new ANTLRHashString("protected", this), new Integer(52));	literals.put(new ANTLRHashString("returns", this), new Integer(57));	literals.put(new ANTLRHashString("public", this), new Integer(53));	literals.put(new ANTLRHashString("catch", this), new Integer(63));}public Token nextToken() throws TokenStreamException {	Token theRetToken=null;tryAgain:	for (;;) {		Token _token = null;		int _ttype = Token.INVALID_TYPE;		resetText();		try {   // for char stream error handling			try {   // for lexical error handling				switch ( LA(1)) {				case '\t':  case '\n':  case '\r':  case ' ':				{					mWS(true);					theRetToken=_returnToken;					break;				}				case '/':				{					mCOMMENT(true);					theRetToken=_returnToken;					break;				}				case '>':				{					mCLOSE_ELEMENT_OPTION(true);					theRetToken=_returnToken;					break;				}				case '@':				{					mAMPERSAND(true);					theRetToken=_returnToken;					break;				}				case ',':				{					mCOMMA(true);					theRetToken=_returnToken;					break;				}				case '?':				{					mQUESTION(true);					theRetToken=_returnToken;					break;				}				case '(':				{					mLPAREN(true);					theRetToken=_returnToken;					break;				}				case ')':				{					mRPAREN(true);					theRetToken=_returnToken;					break;				}				case ':':				{					mCOLON(true);					theRetToken=_returnToken;					break;				}				case '*':				{					mSTAR(true);					theRetToken=_returnToken;					break;				}				case '-':				{					mREWRITE(true);					theRetToken=_returnToken;					break;				}				case ';':				{					mSEMI(true);					theRetToken=_returnToken;					break;				}				case '!':				{					mBANG(true);					theRetToken=_returnToken;					break;				}				case '|':				{					mOR(true);					theRetToken=_returnToken;					break;				}				case '~':				{					mNOT(true);					theRetToken=_returnToken;					break;				}				case '}':				{					mRCURLY(true);					theRetToken=_returnToken;					break;				}				case '$':				{					mDOLLAR(true);					theRetToken=_returnToken;					break;				}				case '\'':				{					mCHAR_LITERAL(true);					theRetToken=_returnToken;					break;				}				case '"':				{					mDOUBLE_QUOTE_STRING_LITERAL(true);					theRetToken=_returnToken;					break;				}				case '0':  case '1':  case '2':  case '3':				case '4':  case '5':  case '6':  case '7':				case '8':  case '9':				{					mINT(true);					theRetToken=_returnToken;					break;				}				case '[':				{					mARG_ACTION(true);					theRetToken=_returnToken;					break;				}				case '{':				{					mACTION(true);					theRetToken=_returnToken;					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':				{					mTOKEN_REF(true);					theRetToken=_returnToken;					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':				{					mRULE_REF(true);					theRetToken=_returnToken;					break;				}				default:					if ((LA(1)=='^') && (LA(2)=='(')) {						mTREE_BEGIN(true);						theRetToken=_returnToken;					}					else if ((LA(1)=='+') && (LA(2)=='=')) {						mPLUS_ASSIGN(true);						theRetToken=_returnToken;					}					else if ((LA(1)=='=') && (LA(2)=='>')) {						mIMPLIES(true);						theRetToken=_returnToken;					}					else if ((LA(1)=='.') && (LA(2)=='.')) {						mRANGE(true);						theRetToken=_returnToken;					}					else if ((LA(1)=='<') && (LA(2)=='<')) {						mDOUBLE_ANGLE_STRING_LITERAL(true);						theRetToken=_returnToken;					}					else if ((LA(1)=='<') && (true)) {						mOPEN_ELEMENT_OPTION(true);						theRetToken=_returnToken;					}					else if ((LA(1)=='+') && (true)) {						mPLUS(true);						theRetToken=_returnToken;					}					else if ((LA(1)=='=') && (true)) {						mASSIGN(true);						theRetToken=_returnToken;					}					else if ((LA(1)=='^') && (true)) {						mROOT(true);						theRetToken=_returnToken;					}					else if ((LA(1)=='.') && (true)) {						mWILDCARD(true);						theRetToken=_returnToken;					}				else {					if (LA(1)==EOF_CHAR) {uponEOF(); _returnToken = makeToken(Token.EOF_TYPE);}				else {throw new NoViableAltForCharException((char)LA(1), getFilename(), getLine(), getColumn());}				}				}				if ( _returnToken==null ) continue tryAgain; // found SKIP token				_ttype = _returnToken.getType();				_returnToken.setType(_ttype);				return _returnToken;			}			catch (RecognitionException e) {				throw new TokenStreamRecognitionException(e);			}		}		catch (CharStreamException cse) {			if ( cse instanceof CharStreamIOException ) {				throw new TokenStreamIOException(((CharStreamIOException)cse).io);			}			else {				throw new TokenStreamException(cse.getMessage());			}		}	}}	public final void mWS(boolean _createToken) throws RecognitionException, CharStreamException, TokenStreamException {		int _ttype; Token _token=null; int _begin=text.length();		_ttype = WS;		int _saveIndex;				{		switch ( LA(1)) {		case ' ':		{			match(' ');			break;		}		case '\t':		{			match('\t');			break;		}		case '\n':  case '\r':		{			{			switch ( LA(1)) {			case '\r':			{				match('\r');				break;			}			case '\n':			{				break;			}			default:			{				throw new NoViableAltForCharException((char)LA(1), getFilename(), getLine(), getColumn());			}			}			}			match('\n');			if ( inputState.guessing==0 ) {				newline();			}			break;		}		default:		{			throw new NoViableAltForCharException((char)LA(1), getFilename(), getLine(), getColumn());		}		}		}		if ( _createToken && _token==null && _ttype!=Token.SKIP ) {			_token = makeToken(_ttype);			_token.setText(new String(text.getBuffer(), _begin, text.length()-_begin));		}		_returnToken = _token;	}		public final void mCOMMENT(boolean _createToken) throws RecognitionException, CharStreamException, TokenStreamException {		int _ttype; Token _token=null; int _begin=text.length();		_ttype = COMMENT;		int _saveIndex;		Token t=null;				{		if ((LA(1)=='/') && (LA(2)=='/')) {			mSL_COMMENT(false);		}		else if ((LA(1)=='/') && (LA(2)=='*')) {			mML_COMMENT(true);			t=_returnToken;			if ( inputState.guessing==0 ) {				_ttype = t.getType();			}		}		else {			throw new NoViableAltForCharException((char)LA(1), getFilename(), getLine(), getColumn());		}				}		if ( _createToken && _token==null && _ttype!=Token.SKIP ) {			_token = makeToken(_ttype);			_token.setText(new String(text.getBuffer(), _begin, text.length()-_begin));		}		_returnToken = _token;	}		protected final void mSL_COMMENT(boolean _createToken) throws RecognitionException, CharStreamException, TokenStreamException {		int _ttype; Token _token=null; int _begin=text.length();		_ttype = SL_COMMENT;		int _saveIndex;				match("//");		{		boolean synPredMatched139 = false;		if (((LA(1)==' ') && (LA(2)=='$'))) {			int _m139 = mark();			synPredMatched139 = true;			inputState.guessing++;			try {				{				match(" $ANTLR");				}			}			catch (RecognitionException pe) {				synPredMatched139 = false;			}			rewind(_m139);inputState.guessing--;		}		if ( synPredMatched139 ) {			match(" $ANTLR ");			mSRC(false);			{			switch ( LA(1)) {			case '\r':			{				match('\r');

⌨️ 快捷键说明

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