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

📄 antlrparser.java

📁 ANTLR(ANother Tool for Language Recognition)它是这样的一种工具
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
				break;			}			case SEMI:			case OR:			case RPAREN:			case REWRITE:			{				if ( inputState.guessing==0 ) {					alternative_AST = (GrammarAST)currentAST.root;											GrammarAST eps = (GrammarAST)astFactory.create(EPSILON,"epsilon");							eps.setLine(LT(0).getLine()); // get line/col of '|' or ':' (prev token)							eps.setColumn(LT(0).getColumn());						alternative_AST = (GrammarAST)astFactory.make( (new ASTArray(3)).add(altRoot).add(eps).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;				break;			}			default:			{				throw new NoViableAltException(LT(1), getFilename());			}			}		}		catch (RecognitionException ex) {			if (inputState.guessing==0) {				reportError(ex);				recover(ex,_tokenSet_23);			} else {			  throw ex;			}		}		returnAST = alternative_AST;	}		public final void rewrite() throws RecognitionException, TokenStreamException {				returnAST = null;		ASTPair currentAST = new ASTPair();		GrammarAST rewrite_AST = null;		Token  rew = null;		GrammarAST rew_AST = null;		Token  pred = null;		GrammarAST pred_AST = null;		GrammarAST alt_AST = null;		Token  rew2 = null;		GrammarAST rew2_AST = null;		GrammarAST alt2_AST = null;				GrammarAST root = new GrammarAST();						try {      // for error handling			switch ( LA(1)) {			case REWRITE:			{				{				_loop134:				do {					if ((LA(1)==REWRITE) && (LA(2)==SEMPRED)) {						rew = LT(1);						rew_AST = (GrammarAST)astFactory.create(rew);						match(REWRITE);						pred = LT(1);						pred_AST = (GrammarAST)astFactory.create(pred);						match(SEMPRED);						rewrite_alternative();						alt_AST = (GrammarAST)returnAST;						if ( inputState.guessing==0 ) {							root.addChild( (GrammarAST)astFactory.make( (new ASTArray(3)).add(rew_AST).add(pred_AST).add(alt_AST)) );						}						if ( inputState.guessing==0 ) {							pred_AST.setEnclosingRule(currentRuleName);						}					}					else {						break _loop134;					}									} while (true);				}				rew2 = LT(1);				rew2_AST = (GrammarAST)astFactory.create(rew2);				match(REWRITE);				rewrite_alternative();				alt2_AST = (GrammarAST)returnAST;				if ( inputState.guessing==0 ) {					rewrite_AST = (GrammarAST)currentAST.root;										root.addChild( (GrammarAST)astFactory.make( (new ASTArray(2)).add(rew2_AST).add(alt2_AST)) );					rewrite_AST = (GrammarAST)root.getFirstChild();										currentAST.root = rewrite_AST;					currentAST.child = rewrite_AST!=null &&rewrite_AST.getFirstChild()!=null ?						rewrite_AST.getFirstChild() : rewrite_AST;					currentAST.advanceChildToEnd();				}				break;			}			case SEMI:			case OR:			case RPAREN:			{				rewrite_AST = (GrammarAST)currentAST.root;				break;			}			default:			{				throw new NoViableAltException(LT(1), getFilename());			}			}		}		catch (RecognitionException ex) {			if (inputState.guessing==0) {				reportError(ex);				recover(ex,_tokenSet_24);			} else {			  throw ex;			}		}		returnAST = rewrite_AST;	}		public final void element() throws RecognitionException, TokenStreamException {				returnAST = null;		ASTPair currentAST = new ASTPair();		GrammarAST element_AST = null;				try {      // for error handling			elementNoOptionSpec();			astFactory.addASTChild(currentAST, returnAST);			element_AST = (GrammarAST)currentAST.root;		}		catch (RecognitionException ex) {			if (inputState.guessing==0) {				reportError(ex);				recover(ex,_tokenSet_25);			} else {			  throw ex;			}		}		returnAST = element_AST;	}		public final void exceptionSpecNoLabel() throws RecognitionException, TokenStreamException {				returnAST = null;		ASTPair currentAST = new ASTPair();		GrammarAST exceptionSpecNoLabel_AST = null;				try {      // for error handling			GrammarAST tmp43_AST = null;			tmp43_AST = (GrammarAST)astFactory.create(LT(1));			astFactory.addASTChild(currentAST, tmp43_AST);			match(LITERAL_exception);			{			_loop81:			do {				if ((LA(1)==LITERAL_catch)) {					exceptionHandler();					astFactory.addASTChild(currentAST, returnAST);				}				else {					break _loop81;				}							} while (true);			}			exceptionSpecNoLabel_AST = (GrammarAST)currentAST.root;		}		catch (RecognitionException ex) {			if (inputState.guessing==0) {				reportError(ex);				recover(ex,_tokenSet_23);			} else {			  throw ex;			}		}		returnAST = exceptionSpecNoLabel_AST;	}		public final void exceptionSpec() throws RecognitionException, TokenStreamException {				returnAST = null;		ASTPair currentAST = new ASTPair();		GrammarAST exceptionSpec_AST = null;				try {      // for error handling			GrammarAST tmp44_AST = null;			tmp44_AST = (GrammarAST)astFactory.create(LT(1));			astFactory.makeASTRoot(currentAST, tmp44_AST);			match(LITERAL_exception);			{			switch ( LA(1)) {			case ARG_ACTION:			{				GrammarAST tmp45_AST = null;				tmp45_AST = (GrammarAST)astFactory.create(LT(1));				astFactory.addASTChild(currentAST, tmp45_AST);				match(ARG_ACTION);				break;			}			case EOF:			case FRAGMENT:			case DOC_COMMENT:			case TOKEN_REF:			case LITERAL_protected:			case LITERAL_public:			case LITERAL_private:			case LITERAL_exception:			case LITERAL_catch:			case RULE_REF:			{				break;			}			default:			{				throw new NoViableAltException(LT(1), getFilename());			}			}			}			{			_loop78:			do {				if ((LA(1)==LITERAL_catch)) {					exceptionHandler();					astFactory.addASTChild(currentAST, returnAST);				}				else {					break _loop78;				}							} while (true);			}			exceptionSpec_AST = (GrammarAST)currentAST.root;		}		catch (RecognitionException ex) {			if (inputState.guessing==0) {				reportError(ex);				recover(ex,_tokenSet_26);			} else {			  throw ex;			}		}		returnAST = exceptionSpec_AST;	}		public final void exceptionHandler() throws RecognitionException, TokenStreamException {				returnAST = null;		ASTPair currentAST = new ASTPair();		GrammarAST exceptionHandler_AST = null;				try {      // for error handling			GrammarAST tmp46_AST = null;			tmp46_AST = (GrammarAST)astFactory.create(LT(1));			astFactory.makeASTRoot(currentAST, tmp46_AST);			match(LITERAL_catch);			GrammarAST tmp47_AST = null;			tmp47_AST = (GrammarAST)astFactory.create(LT(1));			astFactory.addASTChild(currentAST, tmp47_AST);			match(ARG_ACTION);			GrammarAST tmp48_AST = null;			tmp48_AST = (GrammarAST)astFactory.create(LT(1));			astFactory.addASTChild(currentAST, tmp48_AST);			match(ACTION);			exceptionHandler_AST = (GrammarAST)currentAST.root;		}		catch (RecognitionException ex) {			if (inputState.guessing==0) {				reportError(ex);				recover(ex,_tokenSet_27);			} else {			  throw ex;			}		}		returnAST = exceptionHandler_AST;	}		public final void elementNoOptionSpec() throws RecognitionException, TokenStreamException {				returnAST = null;		ASTPair currentAST = new ASTPair();		GrammarAST elementNoOptionSpec_AST = null;		Token  a = null;		GrammarAST a_AST = null;		Token  p = null;		GrammarAST p_AST = null;		GrammarAST t3_AST = null;				IntSet elements=null;						try {      // for error handling			switch ( LA(1)) {			case ACTION:			{				a = LT(1);				a_AST = (GrammarAST)astFactory.create(a);				astFactory.addASTChild(currentAST, a_AST);				match(ACTION);				elementNoOptionSpec_AST = (GrammarAST)currentAST.root;				break;			}			case SEMPRED:			{				p = LT(1);				p_AST = (GrammarAST)astFactory.create(p);				astFactory.addASTChild(currentAST, p_AST);				match(SEMPRED);				{				switch ( LA(1)) {				case IMPLIES:				{					match(IMPLIES);					if ( inputState.guessing==0 ) {						p_AST.setType(GATED_SEMPRED);					}					break;				}				case ACTION:				case SEMI:				case STRING_LITERAL:				case CHAR_LITERAL:				case TOKEN_REF:				case LPAREN:				case OR:				case RPAREN:				case LITERAL_exception:				case SEMPRED:				case NOT:				case TREE_BEGIN:				case RULE_REF:				case WILDCARD:				case REWRITE:				{					break;				}				default:				{					throw new NoViableAltException(LT(1), getFilename());				}				}				}				if ( inputState.guessing==0 ) {												p_AST.setEnclosingRule(currentRuleName);							grammar.blocksWithSemPreds.add(currentBlockAST);											}				elementNoOptionSpec_AST = (GrammarAST)currentAST.root;				break;			}			case TREE_BEGIN:			{				tree();				t3_AST = (GrammarAST)returnAST;				astFactory.addASTChild(currentAST, returnAST);				elementNoOptionSpec_AST = (GrammarAST)currentAST.root;				break;			}			default:				if ((_tokenSet_28.member(LA(1))) && (_tokenSet_29.member(LA(2)))) {					{					if ((LA(1)==TOKEN_REF||LA(1)==RULE_REF) && (LA(2)==ASSIGN)) {						id();						astFactory.addASTChild(currentAST, returnAST);						GrammarAST tmp50_AST = null;						tmp50_AST = (GrammarAST)astFactory.create(LT(1));						astFactory.makeASTRoot(currentAST, tmp50_AST);						match(ASSIGN);					}					else if ((_tokenSet_28.member(LA(1))) && (_tokenSet_30.member(LA(2)))) {					}					else {						throw new NoViableAltException(LT(1), getFilename());					}										}					{					switch ( LA(1)) {					case NOT:					{						notSet();						astFactory.addASTChild(currentAST, returnAST);						break;					}					case LPAREN:					{						ebnf();						astFactory.addASTChild(currentAST, returnAST);						break;					}					default:						if ((LA(1)==CHAR_LITERAL) && (LA(2)==RANGE)) {							range();							astFactory.addASTChild(currentAST, returnAST);						}						else if ((_tokenSet_31.member(LA(1))) && (_tokenSet_32.member(LA(2)))) {							terminal();							astFactory.addASTChild(currentAST, returnAST);						}					else {						throw new NoViableAltException(LT(1), getFilename());					}					}					}					elementNoOptionSpec_AST = (GrammarAST)currentAST.root;				}				else if ((LA(1)==TOKEN_REF||LA(1)==RULE_REF) && (LA(2)==PLUS_ASSIGN)) {					id();					astFactory.addASTChild(currentAST, returnAST);					GrammarAST tmp51_AST = null;					tmp51_AST = (GrammarAST)astFactory.create(LT(1));					astFactory.makeASTRoot(currentAST, tmp51_AST);					match(PLUS_ASSIGN);					{					switch ( LA(1)) {					case STRING_LITERAL:					case CHAR_LITERAL:					case TOKEN_REF:					case RULE_REF:					case WILDCARD:					{						terminal();						astFactory.addASTChild(currentAST, returnAST);						break;					}					case NOT:					{						notSet();						astFactory.addASTChild(currentAST, returnAST);						break;					}					case LPAREN:					{						ebnf();						astFactory.addASTChild(currentAST, returnAST);						break;					}					default:					{						throw new NoViableAltException(LT(1), getFilename());					}					}					}					elementNoOptionSpec_AST = (GrammarAST)currentAST.root;				}			else {				throw new NoViableAltException(LT(1), getFilename());			}			}		}		catch (RecognitionException ex) {			if (inputState.guessing==0) {				reportError(ex);				recover(ex,_tokenSet_25);			} else {			  throw ex;			}		}		returnAST = elementNoOptionSpec_AST;	}		public final void elementOptionSpec() throws RecognitionException, TokenStreamException {				returnAST = null;		ASTPair currentAST = new ASTPair();		GrammarAST elementOptionSpec_AST = null;				try {      // for error handling			GrammarAST tmp52_AST = null;			tmp52_AST = (GrammarAST)astFactory.create(LT(1));			astFactory.addASTChild(currentAST, tmp52_AST);			match(OPEN_ELEMENT_OPTION);			id();			astFactory.addASTChild(currentAST, returnAST);			GrammarAST tmp53_AST = null;			tmp53_AST = (GrammarAST)astFactory.create(LT(1));			astFactory.addASTChild(currentAST, tmp53_AST);			match(ASSIGN);			optionValue();			astFactory.addASTChild(currentAST, returnAST);			{			_loop86:			do {				if ((LA(1)==SEMI)) {					GrammarAST tmp54_AST = null;					tmp54_AST = (GrammarAST)astFactory.create(LT(1));					astFactory.addASTChild(currentAST, tmp54_AST);					match(SEMI);					id();					astFactory.addASTChild(currentAST, returnAST);					GrammarAST tmp55_AST = null;					tmp55_AST = (GrammarAST)astFactory.create(LT(1));					astFactory.addASTChild(currentAST, tmp55_AST);					match(ASSIGN);					optionValue();					astFactory.addASTChild(currentAST, returnAST);				}				else {					break _loop86;				}							} while (true);			}			GrammarAST tmp56_AST = null;			tmp56_AST = (GrammarAST)astFactory.create(LT(1));			astFactory.addASTChild(currentAST, tmp56_AST);			match(CLOSE_ELEMENT_OPTION);			elementOptionSpec_AST = (GrammarAST)currentAST.root;		}		catch (RecognitionException ex) {			if (inputState.guessing==0) {				reportError(ex);				recover(ex,_tokenSet_0);			} else {			  throw ex;			}		}		returnAST = elementOptionSpec_AST;	}		public final void range() throws RecognitionException, TokenStreamException {				returnAST = null;		A

⌨️ 快捷键说明

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