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

📄 codegentreewalker.java

📁 antlr最新版本V3源代码
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
			default:			{				throw new NoViableAltException(_t);			}			}		}		catch (RecognitionException ex) {			reportError(ex);			if (_t!=null) {_t = _t.getNextSibling();}		}		_retTree = _t;		return code;	}		public final StringTemplate  tree(AST _t) throws RecognitionException {		StringTemplate code=templates.getInstanceOf("tree");				GrammarAST tree_AST_in = (_t == ASTNULL) ? null : (GrammarAST)_t;				StringTemplate el=null, act=null;		GrammarAST elAST=null, actAST=null;		NFAState afterDOWN = (NFAState)tree_AST_in.NFATreeDownState.transition(0).target;		LookaheadSet s = grammar.LOOK(afterDOWN);		if ( s.member(Label.UP) ) {			// nullable child list if we can see the UP as the next token			// we need an "if ( input.LA(1)==Token.DOWN )" gate around			// the child list.			code.setAttribute("nullableChildList", "true");		}						try {      // for error handling			AST __t77 = _t;			GrammarAST tmp50_AST_in = (GrammarAST)_t;			match(_t,TREE_BEGIN);			_t = _t.getFirstChild();			elAST=(GrammarAST)_t;			el=element(_t,null,null);			_t = _retTree;						code.setAttribute("root.{el,line,pos}",										  el,										  Utils.integer(elAST.getLine()),										  Utils.integer(elAST.getColumn())										  );						{			_loop79:			do {				if (_t==null) _t=ASTNULL;				if ((_t.getType()==ACTION)) {					actAST=(GrammarAST)_t;					act=element_action(_t);					_t = _retTree;										code.setAttribute("actionsAfterRoot.{el,line,pos}",					act,					Utils.integer(actAST.getLine()),					Utils.integer(actAST.getColumn())					);									}				else {					break _loop79;				}							} while (true);			}			{			_loop81:			do {				if (_t==null) _t=ASTNULL;				if ((_t.getType()==BLOCK||_t.getType()==OPTIONAL||_t.getType()==CLOSURE||_t.getType()==POSITIVE_CLOSURE||_t.getType()==CHAR_RANGE||_t.getType()==EPSILON||_t.getType()==GATED_SEMPRED||_t.getType()==SYN_SEMPRED||_t.getType()==BACKTRACK_SEMPRED||_t.getType()==ACTION||_t.getType()==ASSIGN||_t.getType()==STRING_LITERAL||_t.getType()==CHAR_LITERAL||_t.getType()==TOKEN_REF||_t.getType()==BANG||_t.getType()==PLUS_ASSIGN||_t.getType()==SEMPRED||_t.getType()==ROOT||_t.getType()==RULE_REF||_t.getType()==NOT||_t.getType()==TREE_BEGIN||_t.getType()==WILDCARD)) {					elAST=(GrammarAST)_t;					el=element(_t,null,null);					_t = _retTree;													 code.setAttribute("children.{el,line,pos}",												  el,												  Utils.integer(elAST.getLine()),												  Utils.integer(elAST.getColumn())												  );												}				else {					break _loop81;				}							} while (true);			}			_t = __t77;			_t = _t.getNextSibling();		}		catch (RecognitionException ex) {			reportError(ex);			if (_t!=null) {_t = _t.getNextSibling();}		}		_retTree = _t;		return code;	}		public final StringTemplate  element_action(AST _t) throws RecognitionException {		StringTemplate code=null;				GrammarAST element_action_AST_in = (_t == ASTNULL) ? null : (GrammarAST)_t;		GrammarAST act = null;				try {      // for error handling			act = (GrammarAST)_t;			match(_t,ACTION);			_t = _t.getNextSibling();						code = templates.getInstanceOf("execAction");			code.setAttribute("action", generator.translateAction(currentRuleName,act));					}		catch (RecognitionException ex) {			reportError(ex);			if (_t!=null) {_t = _t.getNextSibling();}		}		_retTree = _t;		return code;	}		public final StringTemplate  set(AST _t,		GrammarAST label, GrammarAST astSuffix	) throws RecognitionException {		StringTemplate code=null;				GrammarAST set_AST_in = (_t == ASTNULL) ? null : (GrammarAST)_t;		GrammarAST s = null;				String labelText=null;		if ( label!=null ) {		labelText = label.getText();		}						try {      // for error handling			s = (GrammarAST)_t;			match(_t,BLOCK);			_t = _t.getNextSibling();						code = getTokenElementST("matchSet", "set", s, astSuffix, labelText);			int i = ((TokenWithIndex)s.getToken()).getIndex();					code.setAttribute("elementIndex", i);					if ( grammar.type!=Grammar.LEXER ) {						generator.generateLocalFOLLOW(s,"set",currentRuleName,i);			}			code.setAttribute("s", generator.genSetExpr(templates,s.getSetValue(),1,false));					}		catch (RecognitionException ex) {			reportError(ex);			if (_t!=null) {_t = _t.getNextSibling();}		}		_retTree = _t;		return code;	}		public final void ast_suffix(AST _t) throws RecognitionException {				GrammarAST ast_suffix_AST_in = (_t == ASTNULL) ? null : (GrammarAST)_t;				try {      // for error handling			if (_t==null) _t=ASTNULL;			switch ( _t.getType()) {			case ROOT:			{				GrammarAST tmp51_AST_in = (GrammarAST)_t;				match(_t,ROOT);				_t = _t.getNextSibling();				break;			}			case BANG:			{				GrammarAST tmp52_AST_in = (GrammarAST)_t;				match(_t,BANG);				_t = _t.getNextSibling();				break;			}			default:			{				throw new NoViableAltException(_t);			}			}		}		catch (RecognitionException ex) {			reportError(ex);			if (_t!=null) {_t = _t.getNextSibling();}		}		_retTree = _t;	}		public final void setElement(AST _t) throws RecognitionException {				GrammarAST setElement_AST_in = (_t == ASTNULL) ? null : (GrammarAST)_t;		GrammarAST c = null;		GrammarAST t = null;		GrammarAST s = null;		GrammarAST c1 = null;		GrammarAST c2 = null;				try {      // for error handling			if (_t==null) _t=ASTNULL;			switch ( _t.getType()) {			case CHAR_LITERAL:			{				c = (GrammarAST)_t;				match(_t,CHAR_LITERAL);				_t = _t.getNextSibling();				break;			}			case TOKEN_REF:			{				t = (GrammarAST)_t;				match(_t,TOKEN_REF);				_t = _t.getNextSibling();				break;			}			case STRING_LITERAL:			{				s = (GrammarAST)_t;				match(_t,STRING_LITERAL);				_t = _t.getNextSibling();				break;			}			case CHAR_RANGE:			{				AST __t90 = _t;				GrammarAST tmp53_AST_in = (GrammarAST)_t;				match(_t,CHAR_RANGE);				_t = _t.getFirstChild();				c1 = (GrammarAST)_t;				match(_t,CHAR_LITERAL);				_t = _t.getNextSibling();				c2 = (GrammarAST)_t;				match(_t,CHAR_LITERAL);				_t = _t.getNextSibling();				_t = __t90;				_t = _t.getNextSibling();				break;			}			default:			{				throw new NoViableAltException(_t);			}			}		}		catch (RecognitionException ex) {			reportError(ex);			if (_t!=null) {_t = _t.getNextSibling();}		}		_retTree = _t;	}		public final StringTemplate  rewrite_alternative(AST _t) throws RecognitionException {		StringTemplate code=null;				GrammarAST rewrite_alternative_AST_in = (_t == ASTNULL) ? null : (GrammarAST)_t;		GrammarAST a = null;				StringTemplate el,st;						try {      // for error handling			if (_t==null) _t=ASTNULL;			if (((_t.getType()==ALT))&&(generator.grammar.buildAST())) {				AST __t99 = _t;				a = _t==ASTNULL ? null :(GrammarAST)_t;				match(_t,ALT);				_t = _t.getFirstChild();				code=templates.getInstanceOf("rewriteElementList");				{				if (_t==null) _t=ASTNULL;				switch ( _t.getType()) {				case OPTIONAL:				case CLOSURE:				case POSITIVE_CLOSURE:				case LABEL:				case ACTION:				case STRING_LITERAL:				case CHAR_LITERAL:				case TOKEN_REF:				case RULE_REF:				case TREE_BEGIN:				{					{					int _cnt102=0;					_loop102:					do {						if (_t==null) _t=ASTNULL;						if ((_t.getType()==OPTIONAL||_t.getType()==CLOSURE||_t.getType()==POSITIVE_CLOSURE||_t.getType()==LABEL||_t.getType()==ACTION||_t.getType()==STRING_LITERAL||_t.getType()==CHAR_LITERAL||_t.getType()==TOKEN_REF||_t.getType()==RULE_REF||_t.getType()==TREE_BEGIN)) {							GrammarAST elAST=(GrammarAST)_t;							el=rewrite_element(_t);							_t = _retTree;							code.setAttribute("elements.{el,line,pos}",												 					el,														  		Utils.integer(elAST.getLine()),														  		Utils.integer(elAST.getColumn())												 					);																		}						else {							if ( _cnt102>=1 ) { break _loop102; } else {throw new NoViableAltException(_t);}						}												_cnt102++;					} while (true);					}					break;				}				case EPSILON:				{					GrammarAST tmp54_AST_in = (GrammarAST)_t;					match(_t,EPSILON);					_t = _t.getNextSibling();					code.setAttribute("elements.{el,line,pos}",												   templates.getInstanceOf("rewriteEmptyAlt"),												   Utils.integer(a.getLine()),												   Utils.integer(a.getColumn())										 			   );														break;				}				default:				{					throw new NoViableAltException(_t);				}				}				}				GrammarAST tmp55_AST_in = (GrammarAST)_t;				match(_t,EOA);				_t = _t.getNextSibling();				_t = __t99;				_t = _t.getNextSibling();			}			else if (((_t.getType()==ALT||_t.getType()==TEMPLATE||_t.getType()==ACTION))&&(generator.grammar.buildTemplate())) {				code=rewrite_template(_t);				_t = _retTree;			}			else {				throw new NoViableAltException(_t);			}					}		catch (RecognitionException ex) {			reportError(ex);			if (_t!=null) {_t = _t.getNextSibling();}		}		_retTree = _t;		return code;	}		public final StringTemplate  rewrite_block(AST _t,		String blockTemplateName	) throws RecognitionException {		StringTemplate code=null;				GrammarAST rewrite_block_AST_in = (_t == ASTNULL) ? null : (GrammarAST)_t;				rewriteBlockNestingLevel++;		code = templates.getInstanceOf(blockTemplateName);		StringTemplate save_currentBlockST = currentBlockST;		currentBlockST = code;		code.setAttribute("rewriteBlockLevel", rewriteBlockNestingLevel);		StringTemplate alt=null;						try {      // for error handling			AST __t97 = _t;			GrammarAST tmp56_AST_in = (GrammarAST)_t;			match(_t,BLOCK);			_t = _t.getFirstChild();						currentBlockST.setAttribute("referencedElementsDeep",			getTokenTypesAsTargetLabels(tmp56_AST_in.rewriteRefsDeep));			currentBlockST.setAttribute("referencedElements",			getTokenTypesAsTargetLabels(tmp56_AST_in.rewriteRefsShallow));						alt=rewrite_alternative(_t);			_t = _retTree;			GrammarAST tmp57_AST_in = (GrammarAST)_t;			match(_t,EOB);			_t = _t.getNextSibling();			_t = __t97;			_t = _t.getNextSibling();							code.setAttribute("alt", alt);				rewriteBlockNestingLevel--;				currentBlockST = save_currentBlockST;						}		catch (RecognitionException ex) {			reportError(ex);			if (_t!=null) {_t = _t.getNextSibling();}		}		_retTree = _t;		return code;	}		public final StringTemplate  rewrite_element(AST _t) throws RecognitionException {		StringTemplate code=null;				GrammarAST rewrite_element_AST_in = (_t == ASTNULL) ? null : (GrammarAST)_t;				IntSet elements=null;		GrammarAST ast = null;						try {      // for error handling			if (_t==null) _t=ASTNULL;			switch ( _t.getType()) {			case LABEL:			case ACTION:			case STRING_LITERAL:			case CHAR_LITERAL:			case TOKEN_REF:			case RULE_REF:			{				code=rewrite_atom(_t,false);				_t = _retTree;				break;			}			case OPTIONAL:			case CLOSURE:			case POSITIVE_CLOSURE:			{				code=rewrite_ebnf(_t);				_t = _retTree;				break;			}			case TREE_BEGIN:			{				code=rewrite_tree(_t);				_t = _retTree;				break;			}			default:			{				throw new NoViableAltException(_t);			}			}		}		catch (RecognitionException ex) {			reportError(ex);			if (_t!=null) {_t = _t.getNextSibling();}		}		_retTree = _t;		return code;	}		public final StringTemplate  rewrite_template(AST _t) throws RecognitionException {		StringTemplate code=null;				GrammarAST rewrite_template_AST_in = (_t == ASTNULL) ? null : (GrammarAST)_t;		GrammarAST id = null;		GrammarAST ind = null;		GrammarAST arg = null;		GrammarAST a = null;		GrammarAST act = null;				try {      // for error handling			if (_t==null) _t=ASTNULL;			switch ( _t.getType()) {			case ALT:			{				AST __t117 = _t;				GrammarAST tmp58_AST_in = (GrammarAST)_t;				match(_t,ALT);				_t = _t.getFirstChild();				GrammarAST tmp59_AST_in = (GrammarAST)_t;				match(_t,EPSILON);				_t = _t.getNextSibling();				GrammarAST tmp60_AST_in = (GrammarAST)_t;				match(_t,EOA);				_t = _t.getNextSibling();				_t = __t117;				_t = _t.getNextSibling();				code=templates.getInstanceOf("rewriteEmptyTemplate");				break;			}			case TEMPLATE:			{				AST __t118 = _t;				GrammarAST tmp61_AST_in = (GrammarAST)_t;				match(_t,TEMPLATE);				_t = _t.getFirstChild();				{				if (_t==null) _t=ASTNULL;				switch ( _t.getType()) {				case ID:				{					id = (GrammarAST)_t;					match(_t,ID);					_t = _t.getNextSibling();					break;				}				case ACTION:				{					ind = (GrammarAST)_t;					match(_t,ACTION);					_t = _t.getNextSibling();					break;				}				default:				{					throw new NoViableAltException(_t);				}				}		

⌨️ 快捷键说明

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