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

📄 definegrammaritemswalker.java

📁 ANTLR(ANother Tool for Language Recognition)它是这样的一种工具
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
			if (_t==null) _t=ASTNULL;			switch ( _t.getType()) {			case SCOPE:			{				GrammarAST tmp24_AST_in = (GrammarAST)_t;				match(_t,SCOPE);				_t = _t.getNextSibling();				break;			}			case BLOCK:			case AMPERSAND:			{				break;			}			default:			{				throw new NoViableAltException(_t);			}			}			}			{			_loop51:			do {				if (_t==null) _t=ASTNULL;				if ((_t.getType()==AMPERSAND)) {					GrammarAST tmp25_AST_in = (GrammarAST)_t;					match(_t,AMPERSAND);					_t = _t.getNextSibling();				}				else {					break _loop51;				}							} while (true);			}			AST __t52 = _t;			GrammarAST tmp26_AST_in = (GrammarAST)_t;			match(_t,BLOCK);			_t = _t.getFirstChild();			{			if (_t==null) _t=ASTNULL;			switch ( _t.getType()) {			case OPTIONS:			{				GrammarAST tmp27_AST_in = (GrammarAST)_t;				match(_t,OPTIONS);				_t = _t.getNextSibling();				break;			}			case ALT:			{				break;			}			default:			{				throw new NoViableAltException(_t);			}			}			}			{			int _cnt57=0;			_loop57:			do {				if (_t==null) _t=ASTNULL;				if ((_t.getType()==ALT)) {					GrammarAST tmp28_AST_in = (GrammarAST)_t;					match(_t,ALT);					_t = _t.getNextSibling();					{					_loop56:					do {						if (_t==null) _t=ASTNULL;						if ((_t.getType()==REWRITE)) {							GrammarAST tmp29_AST_in = (GrammarAST)_t;							match(_t,REWRITE);							_t = _t.getNextSibling();						}						else {							break _loop56;						}											} while (true);					}					if ( inputState.guessing==0 ) {						n++;					}				}				else {					if ( _cnt57>=1 ) { break _loop57; } else {throw new NoViableAltException(_t);}				}								_cnt57++;			} while (true);			}			GrammarAST tmp30_AST_in = (GrammarAST)_t;			match(_t,EOB);			_t = _t.getNextSibling();			_t = __t52;			_t = _t.getNextSibling();			{			if (_t==null) _t=ASTNULL;			switch ( _t.getType()) {			case LITERAL_exception:			{				exceptionGroup(_t);				_t = _retTree;				break;			}			case EOR:			{				break;			}			default:			{				throw new NoViableAltException(_t);			}			}			}			GrammarAST tmp31_AST_in = (GrammarAST)_t;			match(_t,EOR);			_t = _t.getNextSibling();			_t = __t46;			_t = _t.getNextSibling();		}		catch (RecognitionException ex) {			if (inputState.guessing==0) {				reportError(ex);				if (_t!=null) {_t = _t.getNextSibling();}			} else {			  throw ex;			}		}		_retTree = _t;		return n;	}		public final void blockAction(AST _t) throws RecognitionException {				GrammarAST blockAction_AST_in = (_t == ASTNULL) ? null : (GrammarAST)_t;		GrammarAST amp = null;		GrammarAST id = null;		GrammarAST a = null;				try {      // for error handling			AST __t75 = _t;			amp = _t==ASTNULL ? null :(GrammarAST)_t;			match(_t,AMPERSAND);			_t = _t.getFirstChild();			id = (GrammarAST)_t;			match(_t,ID);			_t = _t.getNextSibling();			a = (GrammarAST)_t;			match(_t,ACTION);			_t = _t.getNextSibling();			_t = __t75;			_t = _t.getNextSibling();		}		catch (RecognitionException ex) {			if (inputState.guessing==0) {				reportError(ex);				if (_t!=null) {_t = _t.getNextSibling();}			} else {			  throw ex;			}		}		_retTree = _t;	}		public final void alternative(AST _t) throws RecognitionException {				GrammarAST alternative_AST_in = (_t == ASTNULL) ? null : (GrammarAST)_t;				if ( grammar.type!=Grammar.LEXER && grammar.getOption("output")!=null && blockLevel==1 ) {			GrammarAST aRewriteNode = alternative_AST_in.findFirstType(REWRITE);			if ( aRewriteNode!=null||				 (alternative_AST_in.getNextSibling()!=null &&				  alternative_AST_in.getNextSibling().getType()==REWRITE) )			{				Rule r = grammar.getRule(currentRuleName);				r.trackAltsWithRewrites(this.outerAltNum);			}		}						try {      // for error handling			AST __t77 = _t;			GrammarAST tmp32_AST_in = (GrammarAST)_t;			match(_t,ALT);			_t = _t.getFirstChild();			{			int _cnt79=0;			_loop79:			do {				if (_t==null) _t=ASTNULL;				if ((_t.getType()==BLOCK||_t.getType()==OPTIONAL||_t.getType()==CLOSURE||_t.getType()==POSITIVE_CLOSURE||_t.getType()==SYNPRED||_t.getType()==RANGE||_t.getType()==CHAR_RANGE||_t.getType()==EPSILON||_t.getType()==SET||_t.getType()==GATED_SEMPRED||_t.getType()==SYN_SEMPRED||_t.getType()==ACTION||_t.getType()==ASSIGN||_t.getType()==STRING_LITERAL||_t.getType()==CHAR_LITERAL||_t.getType()==TOKEN_REF||_t.getType()==PLUS_ASSIGN||_t.getType()==SEMPRED||_t.getType()==NOT||_t.getType()==TREE_BEGIN||_t.getType()==RULE_REF||_t.getType()==WILDCARD)) {					element(_t);					_t = _retTree;				}				else {					if ( _cnt79>=1 ) { break _loop79; } else {throw new NoViableAltException(_t);}				}								_cnt79++;			} while (true);			}			GrammarAST tmp33_AST_in = (GrammarAST)_t;			match(_t,EOA);			_t = _t.getNextSibling();			_t = __t77;			_t = _t.getNextSibling();		}		catch (RecognitionException ex) {			if (inputState.guessing==0) {				reportError(ex);				if (_t!=null) {_t = _t.getNextSibling();}			} else {			  throw ex;			}		}		_retTree = _t;	}		public final void rewrite(AST _t) throws RecognitionException {				GrammarAST rewrite_AST_in = (_t == ASTNULL) ? null : (GrammarAST)_t;				try {      // for error handling			{			_loop95:			do {				if (_t==null) _t=ASTNULL;				if ((_t.getType()==REWRITE)) {					AST __t92 = _t;					GrammarAST tmp34_AST_in = (GrammarAST)_t;					match(_t,REWRITE);					_t = _t.getFirstChild();					{					if (_t==null) _t=ASTNULL;					switch ( _t.getType()) {					case SEMPRED:					{						GrammarAST tmp35_AST_in = (GrammarAST)_t;						match(_t,SEMPRED);						_t = _t.getNextSibling();						break;					}					case ALT:					case TEMPLATE:					case ACTION:					{						break;					}					default:					{						throw new NoViableAltException(_t);					}					}					}					{					if (_t==null) _t=ASTNULL;					switch ( _t.getType()) {					case ALT:					{						GrammarAST tmp36_AST_in = (GrammarAST)_t;						match(_t,ALT);						_t = _t.getNextSibling();						break;					}					case TEMPLATE:					{						GrammarAST tmp37_AST_in = (GrammarAST)_t;						match(_t,TEMPLATE);						_t = _t.getNextSibling();						break;					}					case ACTION:					{						GrammarAST tmp38_AST_in = (GrammarAST)_t;						match(_t,ACTION);						_t = _t.getNextSibling();						break;					}					default:					{						throw new NoViableAltException(_t);					}					}					}					_t = __t92;					_t = _t.getNextSibling();				}				else {					break _loop95;				}							} while (true);			}		}		catch (RecognitionException ex) {			if (inputState.guessing==0) {				reportError(ex);				if (_t!=null) {_t = _t.getNextSibling();}			} else {			  throw ex;			}		}		_retTree = _t;	}		public final void element(AST _t) throws RecognitionException {				GrammarAST element_AST_in = (_t == ASTNULL) ? null : (GrammarAST)_t;		GrammarAST id = null;		GrammarAST not_a = null;		GrammarAST a = null;		GrammarAST id2 = null;		GrammarAST a2 = null;		GrammarAST act = null;				try {      // for error handling			if (_t==null) _t=ASTNULL;			switch ( _t.getType()) {			case SET:			case STRING_LITERAL:			case CHAR_LITERAL:			case TOKEN_REF:			case RULE_REF:			case WILDCARD:			{				atom(_t);				_t = _retTree;				break;			}			case NOT:			{				AST __t97 = _t;				GrammarAST tmp39_AST_in = (GrammarAST)_t;				match(_t,NOT);				_t = _t.getFirstChild();				atom(_t);				_t = _retTree;				_t = __t97;				_t = _t.getNextSibling();				break;			}			case RANGE:			{				AST __t98 = _t;				GrammarAST tmp40_AST_in = (GrammarAST)_t;				match(_t,RANGE);				_t = _t.getFirstChild();				atom(_t);				_t = _retTree;				atom(_t);				_t = _retTree;				_t = __t98;				_t = _t.getNextSibling();				break;			}			case CHAR_RANGE:			{				AST __t99 = _t;				GrammarAST tmp41_AST_in = (GrammarAST)_t;				match(_t,CHAR_RANGE);				_t = _t.getFirstChild();				atom(_t);				_t = _retTree;				atom(_t);				_t = _retTree;				_t = __t99;				_t = _t.getNextSibling();				break;			}			case ASSIGN:			{				AST __t100 = _t;				GrammarAST tmp42_AST_in = (GrammarAST)_t;				match(_t,ASSIGN);				_t = _t.getFirstChild();				id = (GrammarAST)_t;				match(_t,ID);				_t = _t.getNextSibling();				{				if (_t==null) _t=ASTNULL;				switch ( _t.getType()) {				case NOT:				{					AST __t102 = _t;					GrammarAST tmp43_AST_in = (GrammarAST)_t;					match(_t,NOT);					_t = _t.getFirstChild();					not_a = _t==ASTNULL ? null : (GrammarAST)_t;					atom(_t);					_t = _retTree;					_t = __t102;					_t = _t.getNextSibling();					break;				}				case SET:				case STRING_LITERAL:				case CHAR_LITERAL:				case TOKEN_REF:				case RULE_REF:				case WILDCARD:				{					a = _t==ASTNULL ? null : (GrammarAST)_t;					atom(_t);					_t = _retTree;					break;				}				default:				{					throw new NoViableAltException(_t);				}				}				}				_t = __t100;				_t = _t.getNextSibling();				if ( inputState.guessing==0 ) {											if (not_a != null) {							a = not_a;	// "hoist" up the ~atom for name inspection - is this valid?						}						if ( a.getType()==RULE_REF ) {							grammar.defineRuleRefLabel(currentRuleName,id.getToken(),a);						}						else if ( a.getType()!=CHAR_RANGE ) {							grammar.defineTokenRefLabel(currentRuleName,id.getToken(),a);						}										}				break;			}			case PLUS_ASSIGN:			{				AST __t103 = _t;				GrammarAST tmp44_AST_in = (GrammarAST)_t;				match(_t,PLUS_ASSIGN);				_t = _t.getFirstChild();				id2 = (GrammarAST)_t;				match(_t,ID);				_t = _t.getNextSibling();				a2 = _t==ASTNULL ? null : (GrammarAST)_t;				atom(_t);				_t = _retTree;				if ( inputState.guessing==0 ) {											    if ( a2.getType()==RULE_REF ) {						    	grammar.defineRuleListLabel(currentRuleName,id2.getToken(),a2);						    }						    else {						    	grammar.defineTokenListLabel(currentRuleName,id2.getToken(),a2);						    }										}				_t = __t103;				_t = _t.getNextSibling();				break;			}			case BLOCK:			case OPTIONAL:			case CLOSURE:			case POSITIVE_CLOSURE:			{				ebnf(_t);				_t = _retTree;				break;			}			case TREE_BEGIN:			{				tree(_t);				_t = _retTree;				break;			}			case SYNPRED:			{				AST __t104 = _t;				GrammarAST tmp45_AST_in = (GrammarAST)_t;				match(_t,SYNPRED);				_t = _t.getFirstChild();				block(_t);				_t = _retTree;				_t = __t104;				_t = _t.getNextSibling();				break;			}			case ACTION:			{				act = (GrammarAST)_t;				match(_t,ACTION);				_t = _t.getNextSibling();				break;			}			case SEMPRED:			{				GrammarAST tmp46_AST_in = (GrammarAST)_t;				match(_t,SEMPRED);				_t = _t.getNextSibling();				break;			}			case SYN_SEMPRED:			{				GrammarAST tmp47_AST_in = (GrammarAST)_t;				match(_t,SYN_SEMPRED);				_t = _t.getNextSibling();				break;			}			case GATED_SEMPRED:			{				GrammarAST tmp48_AST_in = (GrammarAST)_t;				match(_t,GATED_SEMPRED);				_t = _t.getNextSibling();				break;			}			case EPSILON:			{				GrammarAST tmp49_AST_in = (GrammarAST)_t;				match(_t,EPSILON);				_t = _t.getNextSibling();				break;			}			default:			{				throw new NoViableAltException(_t);			}			}		}		catch (RecognitionException ex) {			if (inputState.guessing==0) {				reportError(ex);				if (_t!=null) {_t = _t.getNextSibling();}			} else {			  throw ex;			}		}		_retTree = _t;	}		public final void exceptionSpec(AST _t) throws RecognitionException {				GrammarAST exceptionSpec_AST_in = (_t == ASTNULL) ? null : (GrammarAST)_t;				try {      // for error handling			AST __t84 = _t;			GrammarAST tmp50_AST_in = (GrammarAST)_t;			match(_t,LITERAL_exception);			_t = _t.getFirstChild();			{			if (_t==null) _t=ASTNULL;			switch ( _t.getType()) {			case ARG_ACTION:			{				GrammarAST tmp51_AST_in = (GrammarAST)_t;				match(_t,ARG_ACTION);				_t = _t.getNextSibling();				break;			}			case LITERAL_catch:			{				break;			}			default:			{				throw new NoViableAltException(_t);			}			}			}			{			int _cnt87=0;			_loop87:			do {				if (_t==null) _t=ASTNULL;				if ((_t.getType()==LITERAL_catch)) {					exceptionHandler(_t);					_t = _retTree;				}				else {					if ( _cnt87>=1 ) { break _loop87; } else {throw new NoViableAltException(_t);}				}								_cnt87++;			} while (true);			}			_t = __t84;			_t = _t.getNextSibling();		}		catch (RecognitionException ex) {			if (inputState.guessing==0) {				reportError(ex);				if (_t!=null) {_t = _t.getNextSibling();}			} else {			  throw ex;			}		}		_retTree = _t;	}		public final void exceptionHandler(AST _t) throws RecognitionException {				GrammarAST exceptionHandler_AST_in = (_t == ASTNULL) ? null : (GrammarAST)_t;				try {      // for error handling			AST __t89 = _t;			GrammarAST tmp52_AST_in = (GrammarAST)_t;			match(_t,LITERAL_catch);			_t = _t.getFirstChild();			GrammarAST tmp53_AST_in = (GrammarAST)_t;			match(_t,ARG_ACTION);			_t = _t.getNextSibling();			GrammarAST tmp54_AST_in = (GrammarAST)_t;			match(_t,ACTION);			_t = _t.getNextSibling();			_t = __t89;			_t = _t.getNextSibling();		}		catch (RecognitionException ex) {			if (inputState.guessing==0) {				reportError(ex);

⌨️ 快捷键说明

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