antlrparser.java

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

JAVA
2,609
字号
			do {				if ((LA(1)==TOKEN_REF||LA(1)==RULE_REF)) {					option(opts);					astFactory.addASTChild(currentAST, returnAST);					match(SEMI);				}				else {					if ( _cnt17>=1 ) { break _loop17; } else {throw new NoViableAltException(LT(1), getFilename());}				}								_cnt17++;			} while (true);			}			match(RCURLY);			optionsSpec_AST = (GrammarAST)currentAST.root;		}		catch (RecognitionException ex) {			reportError(ex);			recover(ex,_tokenSet_3);		}		returnAST = optionsSpec_AST;		return opts;	}		public final void tokensSpec() throws RecognitionException, TokenStreamException {				returnAST = null;		ASTPair currentAST = new ASTPair();		GrammarAST tokensSpec_AST = null;				try {      // for error handling			GrammarAST tmp12_AST = null;			tmp12_AST = (GrammarAST)astFactory.create(LT(1));			astFactory.makeASTRoot(currentAST, tmp12_AST);			match(TOKENS);			{			int _cnt22=0;			_loop22:			do {				if ((LA(1)==TOKEN_REF)) {					tokenSpec();					astFactory.addASTChild(currentAST, returnAST);				}				else {					if ( _cnt22>=1 ) { break _loop22; } else {throw new NoViableAltException(LT(1), getFilename());}				}								_cnt22++;			} while (true);			}			match(RCURLY);			tokensSpec_AST = (GrammarAST)currentAST.root;		}		catch (RecognitionException ex) {			reportError(ex);			recover(ex,_tokenSet_4);		}		returnAST = tokensSpec_AST;	}		public final void attrScopes() throws RecognitionException, TokenStreamException {				returnAST = null;		ASTPair currentAST = new ASTPair();		GrammarAST attrScopes_AST = null;				try {      // for error handling			{			_loop28:			do {				if ((LA(1)==SCOPE)) {					attrScope();					astFactory.addASTChild(currentAST, returnAST);				}				else {					break _loop28;				}							} while (true);			}			attrScopes_AST = (GrammarAST)currentAST.root;		}		catch (RecognitionException ex) {			reportError(ex);			recover(ex,_tokenSet_5);		}		returnAST = attrScopes_AST;	}		public final void actions() throws RecognitionException, TokenStreamException {				returnAST = null;		ASTPair currentAST = new ASTPair();		GrammarAST actions_AST = null;				try {      // for error handling			{			int _cnt11=0;			_loop11:			do {				if ((LA(1)==AMPERSAND)) {					action();					astFactory.addASTChild(currentAST, returnAST);				}				else {					if ( _cnt11>=1 ) { break _loop11; } else {throw new NoViableAltException(LT(1), getFilename());}				}								_cnt11++;			} while (true);			}			actions_AST = (GrammarAST)currentAST.root;		}		catch (RecognitionException ex) {			reportError(ex);			recover(ex,_tokenSet_6);		}		returnAST = actions_AST;	}		public final void rules() throws RecognitionException, TokenStreamException {				returnAST = null;		ASTPair currentAST = new ASTPair();		GrammarAST rules_AST = null;				try {      // for error handling			{			int _cnt32=0;			_loop32:			do {				if ((_tokenSet_6.member(LA(1)))) {					rule();					astFactory.addASTChild(currentAST, returnAST);				}				else {					if ( _cnt32>=1 ) { break _loop32; } else {throw new NoViableAltException(LT(1), getFilename());}				}								_cnt32++;			} while (true);			}			rules_AST = (GrammarAST)currentAST.root;		}		catch (RecognitionException ex) {			reportError(ex);			recover(ex,_tokenSet_0);		}		returnAST = rules_AST;	}	/** Match stuff like @parser::members {int i;} */	public final void action() throws RecognitionException, TokenStreamException {				returnAST = null;		ASTPair currentAST = new ASTPair();		GrammarAST action_AST = null;				try {      // for error handling			GrammarAST tmp14_AST = null;			tmp14_AST = (GrammarAST)astFactory.create(LT(1));			astFactory.makeASTRoot(currentAST, tmp14_AST);			match(AMPERSAND);			{			if ((_tokenSet_7.member(LA(1))) && (LA(2)==COLON)) {				actionScopeName();				astFactory.addASTChild(currentAST, returnAST);				match(COLON);				match(COLON);			}			else if ((LA(1)==TOKEN_REF||LA(1)==RULE_REF) && (LA(2)==ACTION)) {			}			else {				throw new NoViableAltException(LT(1), getFilename());			}						}			id();			astFactory.addASTChild(currentAST, returnAST);			GrammarAST tmp17_AST = null;			tmp17_AST = (GrammarAST)astFactory.create(LT(1));			astFactory.addASTChild(currentAST, tmp17_AST);			match(ACTION);			action_AST = (GrammarAST)currentAST.root;		}		catch (RecognitionException ex) {			reportError(ex);			recover(ex,_tokenSet_5);		}		returnAST = action_AST;	}	/** Sometimes the scope names will collide with keywords; allow them as *  ids for action scopes. */	public final void actionScopeName() throws RecognitionException, TokenStreamException {				returnAST = null;		ASTPair currentAST = new ASTPair();		GrammarAST actionScopeName_AST = null;		Token  l = null;		GrammarAST l_AST = null;		Token  p = null;		GrammarAST p_AST = null;				try {      // for error handling			switch ( LA(1)) {			case TOKEN_REF:			case RULE_REF:			{				id();				astFactory.addASTChild(currentAST, returnAST);				actionScopeName_AST = (GrammarAST)currentAST.root;				break;			}			case LITERAL_lexer:			{				l = LT(1);				l_AST = (GrammarAST)astFactory.create(l);				astFactory.addASTChild(currentAST, l_AST);				match(LITERAL_lexer);				l_AST.setType(ID);				actionScopeName_AST = (GrammarAST)currentAST.root;				break;			}			case PARSER:			{				p = LT(1);				p_AST = (GrammarAST)astFactory.create(p);				astFactory.addASTChild(currentAST, p_AST);				match(PARSER);				p_AST.setType(ID);				actionScopeName_AST = (GrammarAST)currentAST.root;				break;			}			default:			{				throw new NoViableAltException(LT(1), getFilename());			}			}		}		catch (RecognitionException ex) {			reportError(ex);			recover(ex,_tokenSet_8);		}		returnAST = actionScopeName_AST;	}		public final void option(		Map opts	) throws RecognitionException, TokenStreamException {				returnAST = null;		ASTPair currentAST = new ASTPair();		GrammarAST option_AST = null;		GrammarAST o_AST = null;				Object value=null;						try {      // for error handling			id();			o_AST = (GrammarAST)returnAST;			astFactory.addASTChild(currentAST, returnAST);			GrammarAST tmp18_AST = null;			tmp18_AST = (GrammarAST)astFactory.create(LT(1));			astFactory.makeASTRoot(currentAST, tmp18_AST);			match(ASSIGN);			value=optionValue();			astFactory.addASTChild(currentAST, returnAST);							opts.put(o_AST.getText(), value);							option_AST = (GrammarAST)currentAST.root;		}		catch (RecognitionException ex) {			reportError(ex);			recover(ex,_tokenSet_9);		}		returnAST = option_AST;	}		public final Object  optionValue() throws RecognitionException, TokenStreamException {		Object value=null;				returnAST = null;		ASTPair currentAST = new ASTPair();		GrammarAST optionValue_AST = null;		GrammarAST x_AST = null;		Token  s = null;		GrammarAST s_AST = null;		Token  c = null;		GrammarAST c_AST = null;		Token  i = null;		GrammarAST i_AST = null;		Token  ss = null;		GrammarAST ss_AST = null;				try {      // for error handling			switch ( LA(1)) {			case TOKEN_REF:			case RULE_REF:			{				id();				x_AST = (GrammarAST)returnAST;				astFactory.addASTChild(currentAST, returnAST);				value = x_AST.getText();				optionValue_AST = (GrammarAST)currentAST.root;				break;			}			case STRING_LITERAL:			{				s = LT(1);				s_AST = (GrammarAST)astFactory.create(s);				astFactory.addASTChild(currentAST, s_AST);				match(STRING_LITERAL);				String vs = s_AST.getText();				value=vs.substring(1,vs.length()-1);				optionValue_AST = (GrammarAST)currentAST.root;				break;			}			case CHAR_LITERAL:			{				c = LT(1);				c_AST = (GrammarAST)astFactory.create(c);				astFactory.addASTChild(currentAST, c_AST);				match(CHAR_LITERAL);				String vs = c_AST.getText();				value=vs.substring(1,vs.length()-1);				optionValue_AST = (GrammarAST)currentAST.root;				break;			}			case INT:			{				i = LT(1);				i_AST = (GrammarAST)astFactory.create(i);				astFactory.addASTChild(currentAST, i_AST);				match(INT);				value = new Integer(i_AST.getText());				optionValue_AST = (GrammarAST)currentAST.root;				break;			}			case STAR:			{				ss = LT(1);				ss_AST = (GrammarAST)astFactory.create(ss);				astFactory.addASTChild(currentAST, ss_AST);				match(STAR);				ss_AST.setType(STRING_LITERAL); value = "*";				optionValue_AST = (GrammarAST)currentAST.root;				break;			}			default:			{				throw new NoViableAltException(LT(1), getFilename());			}			}		}		catch (RecognitionException ex) {			reportError(ex);			recover(ex,_tokenSet_9);		}		returnAST = optionValue_AST;		return value;	}		public final void tokenSpec() throws RecognitionException, TokenStreamException {				returnAST = null;		ASTPair currentAST = new ASTPair();		GrammarAST tokenSpec_AST = null;				try {      // for error handling			GrammarAST tmp19_AST = null;			tmp19_AST = (GrammarAST)astFactory.create(LT(1));			astFactory.addASTChild(currentAST, tmp19_AST);			match(TOKEN_REF);			{			switch ( LA(1)) {			case ASSIGN:			{				GrammarAST tmp20_AST = null;				tmp20_AST = (GrammarAST)astFactory.create(LT(1));				astFactory.makeASTRoot(currentAST, tmp20_AST);				match(ASSIGN);				{				switch ( LA(1)) {				case STRING_LITERAL:				{					GrammarAST tmp21_AST = null;					tmp21_AST = (GrammarAST)astFactory.create(LT(1));					astFactory.addASTChild(currentAST, tmp21_AST);					match(STRING_LITERAL);					break;				}				case CHAR_LITERAL:				{					GrammarAST tmp22_AST = null;					tmp22_AST = (GrammarAST)astFactory.create(LT(1));					astFactory.addASTChild(currentAST, tmp22_AST);					match(CHAR_LITERAL);					break;				}				default:				{					throw new NoViableAltException(LT(1), getFilename());				}				}				}				break;			}			case SEMI:			{				break;			}			default:			{				throw new NoViableAltException(LT(1), getFilename());			}			}			}			match(SEMI);			tokenSpec_AST = (GrammarAST)currentAST.root;		}		catch (RecognitionException ex) {			reportError(ex);			recover(ex,_tokenSet_10);		}		returnAST = tokenSpec_AST;	}		public final void attrScope() throws RecognitionException, TokenStreamException {				returnAST = null;		ASTPair currentAST = new ASTPair();		GrammarAST attrScope_AST = null;				try {      // for error handling			GrammarAST tmp24_AST = null;			tmp24_AST = (GrammarAST)astFactory.create(LT(1));			astFactory.makeASTRoot(currentAST, tmp24_AST);			match(SCOPE);			id();			astFactory.addASTChild(currentAST, returnAST);			GrammarAST tmp25_AST = null;			tmp25_AST = (GrammarAST)astFactory.create(LT(1));			astFactory.addASTChild(currentAST, tmp25_AST);			match(ACTION);			attrScope_AST = (GrammarAST)currentAST.root;		}		catch (RecognitionException ex) {			reportError(ex);			recover(ex,_tokenSet_4);		}		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 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:			{

⌨️ 快捷键说明

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