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

📄 codegentreewalker.java

📁 antlr最新版本V3源代码
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
			_t = _t.getNextSibling();		}		catch (RecognitionException ex) {			reportError(ex);			if (_t!=null) {_t = _t.getNextSibling();}		}		_retTree = _t;	}		public final void rules(AST _t,		StringTemplate recognizerST	) throws RecognitionException {				GrammarAST rules_AST_in = (_t == ASTNULL) ? null : (GrammarAST)_t;				StringTemplate rST;						try {      // for error handling			{			int _cnt22=0;			_loop22:			do {				if (_t==null) _t=ASTNULL;				if ((_t.getType()==RULE)) {					{													String ruleName = _t.getFirstChild().getText();								Rule r = grammar.getRule(ruleName);													if (_t==null) _t=ASTNULL;					if (((_t.getType()==RULE))&&(!r.isSynPred || grammar.synPredNamesUsedInDFA.contains(ruleName))) {						rST=rule(_t);						_t = _retTree;																if ( rST!=null ) {											recognizerST.setAttribute("rules", rST);											outputFileST.setAttribute("rules", rST);											headerFileST.setAttribute("rules", rST);										}															}					else if ((_t.getType()==RULE)) {						GrammarAST tmp13_AST_in = (GrammarAST)_t;						match(_t,RULE);						_t = _t.getNextSibling();					}					else {						throw new NoViableAltException(_t);					}										}				}				else {					if ( _cnt22>=1 ) { break _loop22; } else {throw new NoViableAltException(_t);}				}								_cnt22++;			} while (true);			}		}		catch (RecognitionException ex) {			reportError(ex);			if (_t!=null) {_t = _t.getNextSibling();}		}		_retTree = _t;	}		public final StringTemplate  rule(AST _t) throws RecognitionException {		StringTemplate code=null;				GrammarAST rule_AST_in = (_t == ASTNULL) ? null : (GrammarAST)_t;		GrammarAST id = null;		GrammarAST mod = null;				String r;		String initAction = null;		StringTemplate b;			// get the dfa for the BLOCK		GrammarAST block=rule_AST_in.getFirstChildWithType(BLOCK);		DFA dfa=block.getLookaheadDFA();			// init blockNestingLevel so it's block level RULE_BLOCK_NESTING_LEVEL			// for alts of rule			blockNestingLevel = RULE_BLOCK_NESTING_LEVEL-1;			Rule ruleDescr = grammar.getRule(rule_AST_in.getFirstChild().getText());					// For syn preds, we don't want any AST code etc... in there.			// Save old templates ptr and restore later.  Base templates include Dbg.			StringTemplateGroup saveGroup = templates;			if ( ruleDescr.isSynPred ) {				templates = generator.getBaseTemplates();			}						try {      // for error handling			AST __t24 = _t;			GrammarAST tmp14_AST_in = (GrammarAST)_t;			match(_t,RULE);			_t = _t.getFirstChild();			id = (GrammarAST)_t;			match(_t,ID);			_t = _t.getNextSibling();			r=id.getText(); currentRuleName = r;			{			if (_t==null) _t=ASTNULL;			switch ( _t.getType()) {			case FRAGMENT:			case LITERAL_protected:			case LITERAL_public:			case LITERAL_private:			{				mod = _t==ASTNULL ? null : (GrammarAST)_t;				modifier(_t);				_t = _retTree;				break;			}			case ARG:			{				break;			}			default:			{				throw new NoViableAltException(_t);			}			}			}			AST __t26 = _t;			GrammarAST tmp15_AST_in = (GrammarAST)_t;			match(_t,ARG);			_t = _t.getFirstChild();			{			if (_t==null) _t=ASTNULL;			switch ( _t.getType()) {			case ARG_ACTION:			{				GrammarAST tmp16_AST_in = (GrammarAST)_t;				match(_t,ARG_ACTION);				_t = _t.getNextSibling();				break;			}			case 3:			{				break;			}			default:			{				throw new NoViableAltException(_t);			}			}			}			_t = __t26;			_t = _t.getNextSibling();			AST __t28 = _t;			GrammarAST tmp17_AST_in = (GrammarAST)_t;			match(_t,RET);			_t = _t.getFirstChild();			{			if (_t==null) _t=ASTNULL;			switch ( _t.getType()) {			case ARG_ACTION:			{				GrammarAST tmp18_AST_in = (GrammarAST)_t;				match(_t,ARG_ACTION);				_t = _t.getNextSibling();				break;			}			case 3:			{				break;			}			default:			{				throw new NoViableAltException(_t);			}			}			}			_t = __t28;			_t = _t.getNextSibling();			{			if (_t==null) _t=ASTNULL;			switch ( _t.getType()) {			case OPTIONS:			{				AST __t31 = _t;				GrammarAST tmp19_AST_in = (GrammarAST)_t;				match(_t,OPTIONS);				_t = _t.getFirstChild();				GrammarAST tmp20_AST_in = (GrammarAST)_t;				if ( _t==null ) throw new MismatchedTokenException();				_t = _t.getNextSibling();				_t = __t31;				_t = _t.getNextSibling();				break;			}			case BLOCK:			case SCOPE:			case AMPERSAND:			{				break;			}			default:			{				throw new NoViableAltException(_t);			}			}			}			{			if (_t==null) _t=ASTNULL;			switch ( _t.getType()) {			case SCOPE:			{				ruleScopeSpec(_t);				_t = _retTree;				break;			}			case BLOCK:			case AMPERSAND:			{				break;			}			default:			{				throw new NoViableAltException(_t);			}			}			}			{			_loop34:			do {				if (_t==null) _t=ASTNULL;				if ((_t.getType()==AMPERSAND)) {					GrammarAST tmp21_AST_in = (GrammarAST)_t;					match(_t,AMPERSAND);					_t = _t.getNextSibling();				}				else {					break _loop34;				}							} while (true);			}			b=block(_t,"ruleBlock", dfa);			_t = _retTree;									String description =							grammar.grammarTreeToString(rule_AST_in.getFirstChildWithType(BLOCK),			false);						description =			generator.target.getTargetStringLiteralFromString(description);						b.setAttribute("description", description);						// do not generate lexer rules in combined grammar						String stName = null;						if ( ruleDescr.isSynPred ) {							stName = "synpredRule";						}						else if ( grammar.type==Grammar.LEXER ) {							if ( r.equals(Grammar.ARTIFICIAL_TOKENS_RULENAME) ) {								stName = "tokensRule";							}							else {								stName = "lexerRule";							}						}						else {							if ( !(grammar.type==Grammar.COMBINED &&								 Character.isUpperCase(r.charAt(0))) )							{								stName = "rule";							}						}						code = templates.getInstanceOf(stName);						if ( code.getName().equals("rule") ) {							code.setAttribute("emptyRule",								Boolean.valueOf(grammar.isEmptyRule(block)));						}						code.setAttribute("ruleDescriptor", ruleDescr);						String memo = (String)rule_AST_in.getOption("memoize");						if ( memo==null ) {							memo = (String)grammar.getOption("memoize");						}						if ( memo!=null && memo.equals("true") &&						     (stName.equals("rule")||stName.equals("lexerRule")) )						{				code.setAttribute("memoize",					Boolean.valueOf(memo!=null && memo.equals("true")));			}									{			if (_t==null) _t=ASTNULL;			switch ( _t.getType()) {			case LITERAL_catch:			case LITERAL_finally:			{				exceptionGroup(_t,code);				_t = _retTree;				break;			}			case EOR:			{				break;			}			default:			{				throw new NoViableAltException(_t);			}			}			}			GrammarAST tmp22_AST_in = (GrammarAST)_t;			match(_t,EOR);			_t = _t.getNextSibling();			_t = __t24;			_t = _t.getNextSibling();						if ( code!=null ) {						if ( grammar.type==Grammar.LEXER ) {					    	boolean naked =					    		r.equals(Grammar.ARTIFICIAL_TOKENS_RULENAME) ||					    	    (mod!=null&&mod.getText().equals(Grammar.FRAGMENT_RULE_MODIFIER));					    	code.setAttribute("nakedBlock", Boolean.valueOf(naked));						}						else {							description =								grammar.grammarTreeToString(rule_AST_in,false);							description =							    generator.target.getTargetStringLiteralFromString(description);							code.setAttribute("description", description);						}						Rule theRule = grammar.getRule(r);						generator.translateActionAttributeReferencesForSingleScope(							theRule,							theRule.getActions()						);						code.setAttribute("ruleName", r);						code.setAttribute("block", b);						if ( initAction!=null ) {							code.setAttribute("initAction", initAction);						}			}					templates = saveGroup;					}		catch (RecognitionException ex) {			reportError(ex);			if (_t!=null) {_t = _t.getNextSibling();}		}		_retTree = _t;		return code;	}		public final void modifier(AST _t) throws RecognitionException {				GrammarAST modifier_AST_in = (_t == ASTNULL) ? null : (GrammarAST)_t;				try {      // for error handling			if (_t==null) _t=ASTNULL;			switch ( _t.getType()) {			case LITERAL_protected:			{				GrammarAST tmp23_AST_in = (GrammarAST)_t;				match(_t,LITERAL_protected);				_t = _t.getNextSibling();				break;			}			case LITERAL_public:			{				GrammarAST tmp24_AST_in = (GrammarAST)_t;				match(_t,LITERAL_public);				_t = _t.getNextSibling();				break;			}			case LITERAL_private:			{				GrammarAST tmp25_AST_in = (GrammarAST)_t;				match(_t,LITERAL_private);				_t = _t.getNextSibling();				break;			}			case FRAGMENT:			{				GrammarAST tmp26_AST_in = (GrammarAST)_t;				match(_t,FRAGMENT);				_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 ruleScopeSpec(AST _t) throws RecognitionException {				GrammarAST ruleScopeSpec_AST_in = (_t == ASTNULL) ? null : (GrammarAST)_t;				try {      // for error handling			AST __t38 = _t;			GrammarAST tmp27_AST_in = (GrammarAST)_t;			match(_t,SCOPE);			_t = _t.getFirstChild();			{			if (_t==null) _t=ASTNULL;			switch ( _t.getType()) {			case ACTION:			{				GrammarAST tmp28_AST_in = (GrammarAST)_t;				match(_t,ACTION);				_t = _t.getNextSibling();				break;			}			case 3:			case ID:			{				break;			}			default:			{				throw new NoViableAltException(_t);			}			}			}			{			_loop41:			do {				if (_t==null) _t=ASTNULL;				if ((_t.getType()==ID)) {					GrammarAST tmp29_AST_in = (GrammarAST)_t;					match(_t,ID);					_t = _t.getNextSibling();				}				else {					break _loop41;				}							} while (true);			}			_t = __t38;			_t = _t.getNextSibling();		}		catch (RecognitionException ex) {			reportError(ex);			if (_t!=null) {_t = _t.getNextSibling();}		}		_retTree = _t;	}		public final StringTemplate  block(AST _t,		String blockTemplateName, DFA dfa	) throws RecognitionException {		StringTemplate code=null;				GrammarAST block_AST_in = (_t == ASTNULL) ? null : (GrammarAST)_t;				StringTemplate decision = null;		if ( dfa!=null ) {		code = templates.getInstanceOf(blockTemplateName);		decision = generator.genLookaheadDecision(recognizerST,dfa);		code.setAttribute("decision", decision);		code.setAttribute("decisionNumber", dfa.getDecisionNumber());				code.setAttribute("maxK",dfa.getMaxLookaheadDepth());				code.setAttribute("maxAlt",dfa.getNumberOfAlts());		}		else {		code = templates.getInstanceOf(blockTemplateName+"SingleAlt");		}		blockNestingLevel++;		code.setAttribute("blockLevel", blockNestingLevel);		code.setAttribute("enclosingBlockLevel", blockNestingLevel-1);		StringTemplate alt = null;		StringTemplate rew = null;		StringTemplate sb = null;		GrammarAST r = null;		int altNum = 1;			if ( this.blockNestingLevel==RULE_BLOCK_NESTING_LEVEL ) {		this.outerAltNum=1;		}						try {      // for error handling			if (_t==null) _t=ASTNULL;			if (((_t.getType()==BLOCK))&&(block_AST_in.getSetValue()!=null)) {				sb=setBlock(_t);				_t = _retTree;								code.setAttribute("alts",sb);				blockNestingLevel--;							}			else if ((_t.getType()==BLOCK)) {				AST __t43 = _t;				GrammarAST tmp30_AST_in = (GrammarAST)_t;				match(_t,BLOCK);				_t = _t.getFirstChild();				{				if (_t==null) _t=ASTNULL;				switch ( _t.getType()) {				case OPTIONS:				{					GrammarAST tmp31_AST_in = (GrammarAST)_t;					match(_t,OPTIONS);					_t = _t.getNextSibling();					break;				}				case ALT:				{

⌨️ 快捷键说明

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