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

📄 antlrparser.java

📁 ANTLR(ANother Tool for Language Recognition)它是这样的一种工具
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
		}		returnAST = attrScope_AST;	}		public final void rule() throws RecognitionException, TokenStreamException {				returnAST = null;		ASTPair currentAST = new ASTPair();		GrammarAST rule_AST = null;		Token  d = null;		GrammarAST d_AST = null;		Token  p1 = null;		GrammarAST p1_AST = null;		Token  p2 = null;		GrammarAST p2_AST = null;		Token  p3 = null;		GrammarAST p3_AST = null;		Token  p4 = null;		GrammarAST p4_AST = null;		GrammarAST ruleName_AST = null;		Token  aa = null;		GrammarAST aa_AST = null;		Token  rt = null;		GrammarAST rt_AST = null;		GrammarAST scopes_AST = null;		GrammarAST a_AST = null;		Token  colon = null;		GrammarAST colon_AST = null;		GrammarAST s_AST = null;		GrammarAST b_AST = null;		Token  semi = null;		GrammarAST semi_AST = null;		GrammarAST ex_AST = null;				GrammarAST modifier=null, blk=null, blkRoot=null, eob=null;		int start = ((TokenWithIndex)LT(1)).getIndex();		int startLine = LT(1).getLine();		GrammarAST opt = null;		Map opts = null;						try {      // for error handling			{			switch ( LA(1)) {			case DOC_COMMENT:			{				d = LT(1);				d_AST = (GrammarAST)astFactory.create(d);				match(DOC_COMMENT);				break;			}			case FRAGMENT:			case TOKEN_REF:			case LITERAL_protected:			case LITERAL_public:			case LITERAL_private:			case RULE_REF:			{				break;			}			default:			{				throw new NoViableAltException(LT(1), getFilename());			}			}			}			{			switch ( LA(1)) {			case LITERAL_protected:			{				p1 = LT(1);				p1_AST = (GrammarAST)astFactory.create(p1);				match(LITERAL_protected);				if ( inputState.guessing==0 ) {					modifier=p1_AST;				}				break;			}			case LITERAL_public:			{				p2 = LT(1);				p2_AST = (GrammarAST)astFactory.create(p2);				match(LITERAL_public);				if ( inputState.guessing==0 ) {					modifier=p2_AST;				}				break;			}			case LITERAL_private:			{				p3 = LT(1);				p3_AST = (GrammarAST)astFactory.create(p3);				match(LITERAL_private);				if ( inputState.guessing==0 ) {					modifier=p3_AST;				}				break;			}			case FRAGMENT:			{				p4 = LT(1);				p4_AST = (GrammarAST)astFactory.create(p4);				match(FRAGMENT);				if ( inputState.guessing==0 ) {					modifier=p4_AST;				}				break;			}			case TOKEN_REF:			case RULE_REF:			{				break;			}			default:			{				throw new NoViableAltException(LT(1), getFilename());			}			}			}			id();			ruleName_AST = (GrammarAST)returnAST;			if ( inputState.guessing==0 ) {				currentRuleName=ruleName_AST.getText();				if ( gtype==LEXER_GRAMMAR && p4_AST==null ) {				lexerRuleNames.add(currentRuleName);					 }								}			{			switch ( LA(1)) {			case BANG:			{				GrammarAST tmp26_AST = null;				tmp26_AST = (GrammarAST)astFactory.create(LT(1));				match(BANG);				break;			}			case OPTIONS:			case SCOPE:			case AMPERSAND:			case COLON:			case ARG_ACTION:			case LITERAL_returns:			case LITERAL_throws:			{				break;			}			default:			{				throw new NoViableAltException(LT(1), getFilename());			}			}			}			{			switch ( LA(1)) {			case ARG_ACTION:			{				aa = LT(1);				aa_AST = (GrammarAST)astFactory.create(aa);				match(ARG_ACTION);				break;			}			case OPTIONS:			case SCOPE:			case AMPERSAND:			case COLON:			case LITERAL_returns:			case LITERAL_throws:			{				break;			}			default:			{				throw new NoViableAltException(LT(1), getFilename());			}			}			}			{			switch ( LA(1)) {			case LITERAL_returns:			{				match(LITERAL_returns);				rt = LT(1);				rt_AST = (GrammarAST)astFactory.create(rt);				match(ARG_ACTION);				break;			}			case OPTIONS:			case SCOPE:			case AMPERSAND:			case COLON:			case LITERAL_throws:			{				break;			}			default:			{				throw new NoViableAltException(LT(1), getFilename());			}			}			}			{			switch ( LA(1)) {			case LITERAL_throws:			{				throwsSpec();				break;			}			case OPTIONS:			case SCOPE:			case AMPERSAND:			case COLON:			{				break;			}			default:			{				throw new NoViableAltException(LT(1), getFilename());			}			}			}			{			switch ( LA(1)) {			case OPTIONS:			{				opts=optionsSpec();				if ( inputState.guessing==0 ) {					opt=(GrammarAST)returnAST;				}				break;			}			case SCOPE:			case AMPERSAND:			case COLON:			{				break;			}			default:			{				throw new NoViableAltException(LT(1), getFilename());			}			}			}			ruleScopeSpec();			scopes_AST = (GrammarAST)returnAST;			{			switch ( LA(1)) {			case AMPERSAND:			{				ruleActions();				a_AST = (GrammarAST)returnAST;				break;			}			case COLON:			{				break;			}			default:			{				throw new NoViableAltException(LT(1), getFilename());			}			}			}			colon = LT(1);			colon_AST = (GrammarAST)astFactory.create(colon);			match(COLON);			if ( inputState.guessing==0 ) {									blkRoot = (GrammarAST)astFactory.create(BLOCK,"BLOCK");					blkRoot.options = opts;					blkRoot.setLine(colon.getLine());					blkRoot.setColumn(colon.getColumn());					eob = (GrammarAST)astFactory.create(EOB,"<end-of-block>");							}			{			boolean synPredMatched44 = false;			if (((LA(1)==STRING_LITERAL||LA(1)==CHAR_LITERAL||LA(1)==TOKEN_REF) && (LA(2)==RANGE||LA(2)==OR))) {				int _m44 = mark();				synPredMatched44 = true;				inputState.guessing++;				try {					{					setNoParens();					match(SEMI);					}				}				catch (RecognitionException pe) {					synPredMatched44 = false;				}				rewind(_m44);inputState.guessing--;			}			if ( synPredMatched44 ) {				setNoParens();				s_AST = (GrammarAST)returnAST;				if ( inputState.guessing==0 ) {												blk = (GrammarAST)astFactory.make( (new ASTArray(3)).add(blkRoot).add((GrammarAST)astFactory.make( (new ASTArray(3)).add((GrammarAST)astFactory.create(ALT,"ALT")).add(s_AST).add((GrammarAST)astFactory.create(EOA,"<end-of-alt>")))).add(eob));											}			}			else if ((_tokenSet_12.member(LA(1))) && (_tokenSet_13.member(LA(2)))) {				altList(opts);				b_AST = (GrammarAST)returnAST;				if ( inputState.guessing==0 ) {					blk = b_AST;				}			}			else {				throw new NoViableAltException(LT(1), getFilename());			}						}			semi = LT(1);			semi_AST = (GrammarAST)astFactory.create(semi);			match(SEMI);			{			switch ( LA(1)) {			case LITERAL_exception:			{				exceptionGroup();				ex_AST = (GrammarAST)returnAST;				break;			}			case EOF:			case FRAGMENT:			case DOC_COMMENT:			case TOKEN_REF:			case LITERAL_protected:			case LITERAL_public:			case LITERAL_private:			case RULE_REF:			{				break;			}			default:			{				throw new NoViableAltException(LT(1), getFilename());			}			}			}			if ( inputState.guessing==0 ) {				rule_AST = (GrammarAST)currentAST.root;								int stop = ((TokenWithIndex)LT(1)).getIndex()-1; // point at the semi or exception thingie					eob.setLine(semi.getLine());					eob.setColumn(semi.getColumn());				GrammarAST eor = (GrammarAST)astFactory.create(EOR,"<end-of-rule>");					eor.setEnclosingRule(ruleName_AST.getText());					eor.setLine(semi.getLine());					eor.setColumn(semi.getColumn());					GrammarAST root = (GrammarAST)astFactory.create(RULE,"rule");					root.ruleStartTokenIndex = start;					root.ruleStopTokenIndex = stop;					root.setLine(startLine);					root.options = opts;				rule_AST = (GrammarAST)astFactory.make( (new ASTArray(11)).add(root).add(ruleName_AST).add(modifier).add((GrammarAST)astFactory.make( (new ASTArray(2)).add((GrammarAST)astFactory.create(ARG,"ARG")).add(aa_AST))).add((GrammarAST)astFactory.make( (new ASTArray(2)).add((GrammarAST)astFactory.create(RET,"RET")).add(rt_AST))).add(opt).add(scopes_AST).add(a_AST).add(blk).add(ex_AST).add(eor));					currentRuleName=null;								currentAST.root = rule_AST;				currentAST.child = rule_AST!=null &&rule_AST.getFirstChild()!=null ?					rule_AST.getFirstChild() : rule_AST;				currentAST.advanceChildToEnd();			}		}		catch (RecognitionException ex) {			if (inputState.guessing==0) {				reportError(ex);				recover(ex,_tokenSet_14);			} else {			  throw ex;			}		}		returnAST = rule_AST;	}		public final void throwsSpec() throws RecognitionException, TokenStreamException {				returnAST = null;		ASTPair currentAST = new ASTPair();		GrammarAST throwsSpec_AST = null;				try {      // for error handling			GrammarAST tmp28_AST = null;			tmp28_AST = (GrammarAST)astFactory.create(LT(1));			astFactory.addASTChild(currentAST, tmp28_AST);			match(LITERAL_throws);			id();			astFactory.addASTChild(currentAST, returnAST);			{			_loop52:			do {				if ((LA(1)==COMMA)) {					GrammarAST tmp29_AST = null;					tmp29_AST = (GrammarAST)astFactory.create(LT(1));					astFactory.addASTChild(currentAST, tmp29_AST);					match(COMMA);					id();					astFactory.addASTChild(currentAST, returnAST);				}				else {					break _loop52;				}							} while (true);			}			throwsSpec_AST = (GrammarAST)currentAST.root;		}		catch (RecognitionException ex) {			if (inputState.guessing==0) {				reportError(ex);				recover(ex,_tokenSet_15);			} else {			  throw ex;			}		}		returnAST = throwsSpec_AST;	}		public final void ruleScopeSpec() throws RecognitionException, TokenStreamException {				returnAST = null;		ASTPair currentAST = new ASTPair();		GrammarAST ruleScopeSpec_AST = null;		Token  a = null;		GrammarAST a_AST = null;		GrammarAST ids_AST = null;				int line = LT(1).getLine();		int column = LT(1).getColumn();						try {      // for error handling			{			if ((LA(1)==SCOPE) && (LA(2)==ACTION)) {				match(SCOPE);				a = LT(1);				a_AST = (GrammarAST)astFactory.create(a);				match(ACTION);			}			else if ((LA(1)==SCOPE||LA(1)==AMPERSAND||LA(1)==COLON) && (_tokenSet_12.member(LA(2)))) {			}			else {				throw new NoViableAltException(LT(1), getFilename());			}						}			{			_loop56:			do {				if ((LA(1)==SCOPE)) {					match(SCOPE);					idList();					ids_AST = (GrammarAST)returnAST;					match(SEMI);				}				else {					break _loop56;				}							} while (true);			}			if ( inputState.guessing==0 ) {				ruleScopeSpec_AST = (GrammarAST)currentAST.root;										GrammarAST scopeRoot = (GrammarAST)(GrammarAST)astFactory.create(SCOPE,"scope");						scopeRoot.setLine(line);						scopeRoot.setColumn(column);						ruleScopeSpec_AST = (GrammarAST)astFactory.make( (new ASTArray(3)).add(scopeRoot).add(a_AST).add(ids_AST));										currentAST.root = ruleScopeSpec_AST;				currentAST.child = ruleScopeSpec_AST!=null &&ruleScopeSpec_AST.getFirstChild()!=null ?					ruleScopeSpec_AST.getFirstChild() : ruleScopeSpec_AST;				currentAST.advanceChildToEnd();			}		}		catch (RecognitionException ex) {			if (inputState.guessing==0) {				reportError(ex);				recover(ex,_tokenSet_16);			} else {			  throw ex;			}		}		returnAST = ruleScopeSpec_AST;	}		public final void ruleActions() throws RecognitionException, TokenStreamException {				returnAST = null;		ASTPair currentAST = new ASTPair();		GrammarAST ruleActions_AST = null;				try {      // for error handling			{			int _cnt48=0;			_loop48:			do {				if ((LA(1)==AMPERSAND)) {					ruleAction();					astFactory.addASTChild(currentAST, returnAST);				}				else {					if ( _cnt48>=1 ) { break _loop48; } else {throw new NoViableAltException(LT(1), getFilename());}				}								_cnt48++;			} while (true);			}			ruleActions_AST = (GrammarAST)currentAST.root;		}		catch (RecognitionException ex) {			if (inputState.guessing==0) {				reportError(ex);				recover(ex,_tokenSet_8);			} else {			  throw ex;			}		}		returnAST = ruleActions_AST;	}		public final void setNoParens() throws RecognitionException, TokenStreamException {				returnAST = null;		ASTPair currentAST = new ASTPair();		GrammarAST setNoParens_AST = null;		Token startingToken = LT(1);				try {      // for error handling			setElement();			astFactory.addASTChild(currentAST, returnAST);

⌨️ 快捷键说明

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