antlrparser.java

来自「antlr最新版本V3源代码」· Java 代码 · 共 2,609 行 · 第 1/5 页

JAVA
2,609
字号
				p1 = LT(1);				p1_AST = (GrammarAST)astFactory.create(p1);				match(LITERAL_protected);				modifier=p1_AST;				break;			}			case LITERAL_public:			{				p2 = LT(1);				p2_AST = (GrammarAST)astFactory.create(p2);				match(LITERAL_public);				modifier=p2_AST;				break;			}			case LITERAL_private:			{				p3 = LT(1);				p3_AST = (GrammarAST)astFactory.create(p3);				match(LITERAL_private);				modifier=p3_AST;				break;			}			case FRAGMENT:			{				p4 = LT(1);				p4_AST = (GrammarAST)astFactory.create(p4);				match(FRAGMENT);				modifier=p4_AST;				break;			}			case TOKEN_REF:			case RULE_REF:			{				break;			}			default:			{				throw new NoViableAltException(LT(1), getFilename());			}			}			}			id();			ruleName_AST = (GrammarAST)returnAST;			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();				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);							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>");						altList(opts);			b_AST = (GrammarAST)returnAST;			blk = b_AST;			semi = LT(1);			semi_AST = (GrammarAST)astFactory.create(semi);			match(SEMI);			{			switch ( LA(1)) {			case LITERAL_catch:			case LITERAL_finally:			{				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());			}			}			}			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) {			reportError(ex);			recover(ex,_tokenSet_11);		}		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);			{			_loop49:			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 _loop49;				}							} while (true);			}			throwsSpec_AST = (GrammarAST)currentAST.root;		}		catch (RecognitionException ex) {			reportError(ex);			recover(ex,_tokenSet_12);		}		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_13.member(LA(2)))) {			}			else {				throw new NoViableAltException(LT(1), getFilename());			}						}			{			_loop53:			do {				if ((LA(1)==SCOPE)) {					match(SCOPE);					idList();					ids_AST = (GrammarAST)returnAST;					match(SEMI);				}				else {					break _loop53;				}							} while (true);			}			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) {			reportError(ex);			recover(ex,_tokenSet_14);		}		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 _cnt45=0;			_loop45:			do {				if ((LA(1)==AMPERSAND)) {					ruleAction();					astFactory.addASTChild(currentAST, returnAST);				}				else {					if ( _cnt45>=1 ) { break _loop45; } else {throw new NoViableAltException(LT(1), getFilename());}				}								_cnt45++;			} while (true);			}			ruleActions_AST = (GrammarAST)currentAST.root;		}		catch (RecognitionException ex) {			reportError(ex);			recover(ex,_tokenSet_8);		}		returnAST = ruleActions_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 (LA(1)==OR||(LA(2)==QUESTION||LA(2)==PLUS||LA(2)==STAR)) prefixWithSynPred(a1_AST);			{			_loop62:			do {				if ((LA(1)==OR)) {					match(OR);					alternative();					a2_AST = (GrammarAST)returnAST;					astFactory.addASTChild(currentAST, returnAST);					rewrite();					astFactory.addASTChild(currentAST, returnAST);					if (LA(1)==OR||(LA(2)==QUESTION||LA(2)==PLUS||LA(2)==STAR)) prefixWithSynPred(a2_AST);				}				else {					break _loop62;				}							} while (true);			}			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) {			reportError(ex);			recover(ex,_tokenSet_9);		}		returnAST = altList_AST;	}		public final void exceptionGroup() throws RecognitionException, TokenStreamException {				returnAST = null;		ASTPair currentAST = new ASTPair();		GrammarAST exceptionGroup_AST = null;				try {      // for error handling			switch ( LA(1)) {			case LITERAL_catch:			{				{				int _cnt68=0;				_loop68:				do {					if ((LA(1)==LITERAL_catch)) {						exceptionHandler();						astFactory.addASTChild(currentAST, returnAST);					}					else {						if ( _cnt68>=1 ) { break _loop68; } else {throw new NoViableAltException(LT(1), getFilename());}					}										_cnt68++;				} while (true);				}				{				switch ( LA(1)) {				case LITERAL_finally:				{					finallyClause();					astFactory.addASTChild(currentAST, 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());				}				}				}				exceptionGroup_AST = (GrammarAST)currentAST.root;				break;			}			case LITERAL_finally:			{				finallyClause();				astFactory.addASTChild(currentAST, returnAST);				exceptionGroup_AST = (GrammarAST)currentAST.root;				break;			}			default:			{				throw new NoViableAltException(LT(1), getFilename());			}			}		}		catch (RecognitionException ex) {			reportError(ex);			recover(ex,_tokenSet_11);		}		returnAST = exceptionGroup_AST;	}	/** Match stuff like @init {int i;} */	public final void ruleAction() throws RecognitionException, TokenStreamException {				returnAST = null;

⌨️ 快捷键说明

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