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

📄 antlrparser.java

📁 ANTLR(ANother Tool for Language Recognition)它是这样的一种工具
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
			{			int _cnt101=0;			_loop101:			do {				if ((LA(1)==OR)) {					match(OR);					setElement();					astFactory.addASTChild(currentAST, returnAST);				}				else {					if ( _cnt101>=1 ) { break _loop101; } else {throw new NoViableAltException(LT(1), getFilename());}				}								_cnt101++;			} while (true);			}			if ( inputState.guessing==0 ) {				setNoParens_AST = (GrammarAST)currentAST.root;								GrammarAST ast = new GrammarAST();						ast.initialize(new TokenWithIndex(SET, "SET"));						((TokenWithIndex)ast.token)							.setIndex(((TokenWithIndex)startingToken).getIndex());				setNoParens_AST = (GrammarAST)astFactory.make( (new ASTArray(2)).add(ast).add(setNoParens_AST));								currentAST.root = setNoParens_AST;				currentAST.child = setNoParens_AST!=null &&setNoParens_AST.getFirstChild()!=null ?					setNoParens_AST.getFirstChild() : setNoParens_AST;				currentAST.advanceChildToEnd();			}			setNoParens_AST = (GrammarAST)currentAST.root;		}		catch (RecognitionException ex) {			if (inputState.guessing==0) {				reportError(ex);				recover(ex,_tokenSet_17);			} else {			  throw ex;			}		}		returnAST = setNoParens_AST;	}		public final void altList(		Map opts	) throws RecognitionException, TokenStreamException {				returnAST = null;		ASTPair currentAST = new ASTPair();		GrammarAST altList_AST = null;		GrammarAST a1_AST = null;		GrammarAST a2_AST = null;					GrammarAST blkRoot = (GrammarAST)astFactory.create(BLOCK,"BLOCK");			blkRoot.options = opts;			blkRoot.setLine(LT(1).getLine());			blkRoot.setColumn(LT(1).getColumn());			GrammarAST save = currentBlockAST;			currentBlockAST = blkRoot;						try {      // for error handling			alternative();			a1_AST = (GrammarAST)returnAST;			astFactory.addASTChild(currentAST, returnAST);			rewrite();			astFactory.addASTChild(currentAST, returnAST);			if ( inputState.guessing==0 ) {				if (LA(1)==OR||(LA(2)==QUESTION||LA(2)==PLUS||LA(2)==STAR)) prefixWithSynPred(a1_AST);			}			{			_loop67:			do {				if ((LA(1)==OR)) {					match(OR);					alternative();					a2_AST = (GrammarAST)returnAST;					astFactory.addASTChild(currentAST, returnAST);					rewrite();					astFactory.addASTChild(currentAST, returnAST);					if ( inputState.guessing==0 ) {						if (LA(1)==OR||(LA(2)==QUESTION||LA(2)==PLUS||LA(2)==STAR)) prefixWithSynPred(a2_AST);					}				}				else {					break _loop67;				}							} while (true);			}			if ( inputState.guessing==0 ) {				altList_AST = (GrammarAST)currentAST.root;								altList_AST = (GrammarAST)astFactory.make( (new ASTArray(3)).add(blkRoot).add(altList_AST).add((GrammarAST)astFactory.create(EOB,"<end-of-block>")));				currentBlockAST = save;								currentAST.root = altList_AST;				currentAST.child = altList_AST!=null &&altList_AST.getFirstChild()!=null ?					altList_AST.getFirstChild() : altList_AST;				currentAST.advanceChildToEnd();			}			altList_AST = (GrammarAST)currentAST.root;		}		catch (RecognitionException ex) {			if (inputState.guessing==0) {				reportError(ex);				recover(ex,_tokenSet_9);			} else {			  throw ex;			}		}		returnAST = altList_AST;	}		public final void exceptionGroup() throws RecognitionException, TokenStreamException {				returnAST = null;		ASTPair currentAST = new ASTPair();		GrammarAST exceptionGroup_AST = null;				try {      // for error handling			{			int _cnt74=0;			_loop74:			do {				if ((LA(1)==LITERAL_exception)) {					exceptionSpec();					astFactory.addASTChild(currentAST, returnAST);				}				else {					if ( _cnt74>=1 ) { break _loop74; } else {throw new NoViableAltException(LT(1), getFilename());}				}								_cnt74++;			} while (true);			}			exceptionGroup_AST = (GrammarAST)currentAST.root;		}		catch (RecognitionException ex) {			if (inputState.guessing==0) {				reportError(ex);				recover(ex,_tokenSet_14);			} else {			  throw ex;			}		}		returnAST = exceptionGroup_AST;	}	/** Match stuff like @init {int i;} */	public final void ruleAction() throws RecognitionException, TokenStreamException {				returnAST = null;		ASTPair currentAST = new ASTPair();		GrammarAST ruleAction_AST = null;				try {      // for error handling			GrammarAST tmp35_AST = null;			tmp35_AST = (GrammarAST)astFactory.create(LT(1));			astFactory.makeASTRoot(currentAST, tmp35_AST);			match(AMPERSAND);			id();			astFactory.addASTChild(currentAST, returnAST);			GrammarAST tmp36_AST = null;			tmp36_AST = (GrammarAST)astFactory.create(LT(1));			astFactory.addASTChild(currentAST, tmp36_AST);			match(ACTION);			ruleAction_AST = (GrammarAST)currentAST.root;		}		catch (RecognitionException ex) {			if (inputState.guessing==0) {				reportError(ex);				recover(ex,_tokenSet_16);			} else {			  throw ex;			}		}		returnAST = ruleAction_AST;	}		public final void idList() throws RecognitionException, TokenStreamException {				returnAST = null;		ASTPair currentAST = new ASTPair();		GrammarAST idList_AST = null;				try {      // for error handling			{			int _cnt129=0;			_loop129:			do {				if ((LA(1)==TOKEN_REF||LA(1)==RULE_REF)) {					id();					astFactory.addASTChild(currentAST, returnAST);				}				else {					if ( _cnt129>=1 ) { break _loop129; } else {throw new NoViableAltException(LT(1), getFilename());}				}								_cnt129++;			} while (true);			}			idList_AST = (GrammarAST)currentAST.root;		}		catch (RecognitionException ex) {			if (inputState.guessing==0) {				reportError(ex);				recover(ex,_tokenSet_9);			} else {			  throw ex;			}		}		returnAST = idList_AST;	}	/** Build #(BLOCK ( #(ALT ...) EOB )+ ) */	public final void block() throws RecognitionException, TokenStreamException {				returnAST = null;		ASTPair currentAST = new ASTPair();		GrammarAST block_AST = null;		GrammarAST s_AST = null;		Token  lp = null;		GrammarAST lp_AST = null;		GrammarAST a1_AST = null;		GrammarAST a2_AST = null;		Token  rp = null;		GrammarAST rp_AST = null;				GrammarAST save = currentBlockAST;		Map opts=null;						try {      // for error handling			boolean synPredMatched59 = false;			if (((LA(1)==LPAREN) && (LA(2)==STRING_LITERAL||LA(2)==CHAR_LITERAL||LA(2)==TOKEN_REF))) {				int _m59 = mark();				synPredMatched59 = true;				inputState.guessing++;				try {					{					set();					}				}				catch (RecognitionException pe) {					synPredMatched59 = false;				}				rewind(_m59);inputState.guessing--;			}			if ( synPredMatched59 ) {				set();				s_AST = (GrammarAST)returnAST;				astFactory.addASTChild(currentAST, returnAST);				block_AST = (GrammarAST)currentAST.root;			}			else if ((LA(1)==LPAREN) && (_tokenSet_18.member(LA(2)))) {				lp = LT(1);				lp_AST = (GrammarAST)astFactory.create(lp);				astFactory.makeASTRoot(currentAST, lp_AST);				match(LPAREN);				if ( inputState.guessing==0 ) {					lp_AST.setType(BLOCK); lp_AST.setText("BLOCK");				}				{				if ((LA(1)==OPTIONS||LA(1)==AMPERSAND||LA(1)==COLON)) {					{					switch ( LA(1)) {					case OPTIONS:					{						opts=optionsSpec();						astFactory.addASTChild(currentAST, returnAST);						if ( inputState.guessing==0 ) {							block_AST = (GrammarAST)currentAST.root;							block_AST.setOptions(grammar,opts);						}						break;					}					case AMPERSAND:					case COLON:					{						break;					}					default:					{						throw new NoViableAltException(LT(1), getFilename());					}					}					}					{					switch ( LA(1)) {					case AMPERSAND:					{						ruleActions();						astFactory.addASTChild(currentAST, returnAST);						break;					}					case COLON:					{						break;					}					default:					{						throw new NoViableAltException(LT(1), getFilename());					}					}					}					match(COLON);				}				else if ((LA(1)==ACTION) && (LA(2)==COLON)) {					GrammarAST tmp38_AST = null;					tmp38_AST = (GrammarAST)astFactory.create(LT(1));					astFactory.addASTChild(currentAST, tmp38_AST);					match(ACTION);					match(COLON);				}				else if ((_tokenSet_19.member(LA(1))) && (_tokenSet_20.member(LA(2)))) {				}				else {					throw new NoViableAltException(LT(1), getFilename());				}								}				if ( inputState.guessing==0 ) {					currentBlockAST = lp_AST;				}				alternative();				a1_AST = (GrammarAST)returnAST;				astFactory.addASTChild(currentAST, returnAST);				rewrite();				astFactory.addASTChild(currentAST, returnAST);				if ( inputState.guessing==0 ) {					if (LA(1)==OR||(LA(2)==QUESTION||LA(2)==PLUS||LA(2)==STAR)) prefixWithSynPred(a1_AST);				}				{				_loop64:				do {					if ((LA(1)==OR)) {						match(OR);						alternative();						a2_AST = (GrammarAST)returnAST;						astFactory.addASTChild(currentAST, returnAST);						rewrite();						astFactory.addASTChild(currentAST, returnAST);						if ( inputState.guessing==0 ) {							if (LA(1)==OR||(LA(2)==QUESTION||LA(2)==PLUS||LA(2)==STAR)) prefixWithSynPred(a2_AST);						}					}					else {						break _loop64;					}									} while (true);				}				rp = LT(1);				rp_AST = (GrammarAST)astFactory.create(rp);				match(RPAREN);				if ( inputState.guessing==0 ) {					block_AST = (GrammarAST)currentAST.root;												currentBlockAST = save;					GrammarAST eob = (GrammarAST)astFactory.create(EOB,"<end-of-block>");					eob.setLine(rp.getLine());					eob.setColumn(rp.getColumn());					block_AST.addChild(eob);									}				block_AST = (GrammarAST)currentAST.root;			}			else {				throw new NoViableAltException(LT(1), getFilename());			}					}		catch (RecognitionException ex) {			if (inputState.guessing==0) {				reportError(ex);				recover(ex,_tokenSet_21);			} else {			  throw ex;			}		}		returnAST = block_AST;	}	/** Match two or more set elements */	public final void set() throws RecognitionException, TokenStreamException {				returnAST = null;		ASTPair currentAST = new ASTPair();		GrammarAST set_AST = null;		GrammarAST s_AST = null;		GrammarAST ast_AST = null;				try {      // for error handling			match(LPAREN);			setNoParens();			s_AST = (GrammarAST)returnAST;			astFactory.addASTChild(currentAST, returnAST);			match(RPAREN);			{			switch ( LA(1)) {			case BANG:			case ROOT:			case RULEROOT:			{				ast_suffix();				ast_AST = (GrammarAST)returnAST;				if ( inputState.guessing==0 ) {					s_AST.addChild(ast_AST);				}				break;			}			case ACTION:			case SEMI:			case STRING_LITERAL:			case CHAR_LITERAL:			case STAR:			case TOKEN_REF:			case LPAREN:			case OR:			case RPAREN:			case LITERAL_exception:			case SEMPRED:			case IMPLIES:			case NOT:			case TREE_BEGIN:			case QUESTION:			case PLUS:			case RULE_REF:			case WILDCARD:			case REWRITE:			{				break;			}			default:			{				throw new NoViableAltException(LT(1), getFilename());			}			}			}			set_AST = (GrammarAST)currentAST.root;		}		catch (RecognitionException ex) {			if (inputState.guessing==0) {				reportError(ex);				recover(ex,_tokenSet_21);			} else {			  throw ex;			}		}		returnAST = set_AST;	}		public final void alternative() throws RecognitionException, TokenStreamException {				returnAST = null;		ASTPair currentAST = new ASTPair();		GrammarAST alternative_AST = null;		GrammarAST el_AST = null;				GrammarAST eoa = (GrammarAST)astFactory.create(EOA,"<end-of-alt>");		GrammarAST altRoot = (GrammarAST)astFactory.create(ALT,"ALT");		altRoot.setLine(LT(1).getLine());		altRoot.setColumn(LT(1).getColumn());						try {      // for error handling			switch ( LA(1)) {			case ACTION:			case STRING_LITERAL:			case CHAR_LITERAL:			case TOKEN_REF:			case LPAREN:			case SEMPRED:			case NOT:			case TREE_BEGIN:			case RULE_REF:			case WILDCARD:			{				{				int _cnt70=0;				_loop70:				do {					if ((_tokenSet_22.member(LA(1)))) {						element();						el_AST = (GrammarAST)returnAST;						astFactory.addASTChild(currentAST, returnAST);					}					else {						if ( _cnt70>=1 ) { break _loop70; } else {throw new NoViableAltException(LT(1), getFilename());}					}										_cnt70++;				} while (true);				}				{				switch ( LA(1)) {				case LITERAL_exception:				{					exceptionSpecNoLabel();					break;				}				case SEMI:				case OR:				case RPAREN:				case REWRITE:				{					break;				}				default:				{					throw new NoViableAltException(LT(1), getFilename());				}				}				}				if ( inputState.guessing==0 ) {					alternative_AST = (GrammarAST)currentAST.root;										if ( alternative_AST==null ) {					alternative_AST = (GrammarAST)astFactory.make( (new ASTArray(3)).add(altRoot).add((GrammarAST)astFactory.create(EPSILON,"epsilon")).add(eoa));					}					else {						// we have a real list of stuff						alternative_AST = (GrammarAST)astFactory.make( (new ASTArray(3)).add(altRoot).add(alternative_AST).add(eoa));					}										currentAST.root = alternative_AST;					currentAST.child = alternative_AST!=null &&alternative_AST.getFirstChild()!=null ?						alternative_AST.getFirstChild() : alternative_AST;					currentAST.advanceChildToEnd();				}				alternative_AST = (GrammarAST)currentAST.root;

⌨️ 快捷键说明

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