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

📄 treetonfaconverter.java

📁 ANTLR(ANother Tool for Language Recognition)它是这样的一种工具
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
					        start.addTransition(new Transition(Label.EPSILON, ruleState));			}			else */			{							if ( Character.isLowerCase(r.charAt(0)) ||								 grammar.type==Grammar.LEXER )							{								// attach start node to block for this rule								NFAState start = grammar.getRuleStartState(r);								start.setAssociatedASTNode(id);								start.addTransition(new Transition(Label.EPSILON, b.left));											// track decision if > 1 alts								if ( grammar.getNumberOfAltsForDecisionNFA(b.left)>1 ) {									b.left.setDescription(grammar.grammarTreeToString(rule_AST_in,false));									b.left.setDecisionASTNode(tmp21_AST_in);									int d = grammar.assignDecisionNumber( b.left );									grammar.setDecisionNFA( d, b.left );				grammar.setDecisionBlockAST(d, tmp21_AST_in);								}											// hook to end of rule node								NFAState end = grammar.getRuleStopState(r);								b.right.addTransition(new Transition(Label.EPSILON,end));							}			}						_t = __t23;			_t = _t.getNextSibling();		}		catch (RecognitionException ex) {			reportError(ex);			if (_t!=null) {_t = _t.getNextSibling();}		}		_retTree = _t;	}		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 tmp24_AST_in = (GrammarAST)_t;				match(_t,LITERAL_protected);				_t = _t.getNextSibling();				break;			}			case LITERAL_public:			{				GrammarAST tmp25_AST_in = (GrammarAST)_t;				match(_t,LITERAL_public);				_t = _t.getNextSibling();				break;			}			case LITERAL_private:			{				GrammarAST tmp26_AST_in = (GrammarAST)_t;				match(_t,LITERAL_private);				_t = _t.getNextSibling();				break;			}			case FRAGMENT:			{				GrammarAST tmp27_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 __t37 = _t;			GrammarAST tmp28_AST_in = (GrammarAST)_t;			match(_t,SCOPE);			_t = _t.getFirstChild();			{			if (_t==null) _t=ASTNULL;			switch ( _t.getType()) {			case ACTION:			{				GrammarAST tmp29_AST_in = (GrammarAST)_t;				match(_t,ACTION);				_t = _t.getNextSibling();				break;			}			case 3:			case ID:			{				break;			}			default:			{				throw new NoViableAltException(_t);			}			}			}			{			_loop40:			do {				if (_t==null) _t=ASTNULL;				if ((_t.getType()==ID)) {					GrammarAST tmp30_AST_in = (GrammarAST)_t;					match(_t,ID);					_t = _t.getNextSibling();				}				else {					break _loop40;				}							} while (true);			}			_t = __t37;			_t = _t.getNextSibling();		}		catch (RecognitionException ex) {			reportError(ex);			if (_t!=null) {_t = _t.getNextSibling();}		}		_retTree = _t;	}		public final StateCluster  block(AST _t) throws RecognitionException {		StateCluster g = null;				GrammarAST block_AST_in = (_t == ASTNULL) ? null : (GrammarAST)_t;				StateCluster a = null;		List alts = new LinkedList();						try {      // for error handling			{			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:			{				break;			}			default:			{				throw new NoViableAltException(_t);			}			}			}			{			int _cnt44=0;			_loop44:			do {				if (_t==null) _t=ASTNULL;				if ((_t.getType()==ALT)) {					a=alternative(_t);					_t = _retTree;					rewrite(_t);					_t = _retTree;					alts.add(a);				}				else {					if ( _cnt44>=1 ) { break _loop44; } else {throw new NoViableAltException(_t);}				}								_cnt44++;			} while (true);			}						g = factory.build_AlternativeBlock(alts);					}		catch (RecognitionException ex) {			reportError(ex);			if (_t!=null) {_t = _t.getNextSibling();}		}		_retTree = _t;		return g;	}		public final void exceptionGroup(AST _t) throws RecognitionException {				GrammarAST exceptionGroup_AST_in = (_t == ASTNULL) ? null : (GrammarAST)_t;				try {      // for error handling			{			int _cnt51=0;			_loop51:			do {				if (_t==null) _t=ASTNULL;				if ((_t.getType()==LITERAL_exception)) {					exceptionSpec(_t);					_t = _retTree;				}				else {					if ( _cnt51>=1 ) { break _loop51; } else {throw new NoViableAltException(_t);}				}								_cnt51++;			} while (true);			}		}		catch (RecognitionException ex) {			reportError(ex);			if (_t!=null) {_t = _t.getNextSibling();}		}		_retTree = _t;	}		public final StateCluster  alternative(AST _t) throws RecognitionException {		StateCluster g=null;				GrammarAST alternative_AST_in = (_t == ASTNULL) ? null : (GrammarAST)_t;				StateCluster e = null;						try {      // for error handling			AST __t46 = _t;			GrammarAST tmp32_AST_in = (GrammarAST)_t;			match(_t,ALT);			_t = _t.getFirstChild();			{			int _cnt48=0;			_loop48:			do {				if (_t==null) _t=ASTNULL;				if ((_tokenSet_0.member(_t.getType()))) {					e=element(_t);					_t = _retTree;					g = factory.build_AB(g,e);				}				else {					if ( _cnt48>=1 ) { break _loop48; } else {throw new NoViableAltException(_t);}				}								_cnt48++;			} while (true);			}			_t = __t46;			_t = _t.getNextSibling();						if (g==null) { // if alt was a list of actions or whatever			g = factory.build_Epsilon();			}			else {				factory.optimizeAlternative(g);			}					}		catch (RecognitionException ex) {			reportError(ex);			if (_t!=null) {_t = _t.getNextSibling();}		}		_retTree = _t;		return g;	}		public final void rewrite(AST _t) throws RecognitionException {				GrammarAST rewrite_AST_in = (_t == ASTNULL) ? null : (GrammarAST)_t;				try {      // for error handling			{			_loop64:			do {				if (_t==null) _t=ASTNULL;				if ((_t.getType()==REWRITE)) {													if ( grammar.getOption("output")==null ) {									ErrorManager.grammarError(ErrorManager.MSG_REWRITE_OR_OP_WITH_NO_OUTPUT_OPTION,															  grammar, rewrite_AST_in.token, currentRuleName);								}													AST __t61 = _t;					GrammarAST tmp33_AST_in = (GrammarAST)_t;					match(_t,REWRITE);					_t = _t.getFirstChild();					{					if (_t==null) _t=ASTNULL;					switch ( _t.getType()) {					case SEMPRED:					{						GrammarAST tmp34_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 tmp35_AST_in = (GrammarAST)_t;						match(_t,ALT);						_t = _t.getNextSibling();						break;					}					case TEMPLATE:					{						GrammarAST tmp36_AST_in = (GrammarAST)_t;						match(_t,TEMPLATE);						_t = _t.getNextSibling();						break;					}					case ACTION:					{						GrammarAST tmp37_AST_in = (GrammarAST)_t;						match(_t,ACTION);						_t = _t.getNextSibling();						break;					}					default:					{						throw new NoViableAltException(_t);					}					}					}					_t = __t61;					_t = _t.getNextSibling();				}				else {					break _loop64;				}							} while (true);			}		}		catch (RecognitionException ex) {			reportError(ex);			if (_t!=null) {_t = _t.getNextSibling();}		}		_retTree = _t;	}		public final StateCluster  element(AST _t) throws RecognitionException {		StateCluster g=null;				GrammarAST element_AST_in = (_t == ASTNULL) ? null : (GrammarAST)_t;		GrammarAST n = null;		GrammarAST c = null;		GrammarAST ast1 = null;		GrammarAST t = null;		GrammarAST ast3 = null;		GrammarAST a = null;		GrammarAST b = null;		GrammarAST c1 = null;		GrammarAST c2 = null;		GrammarAST pred = null;		GrammarAST spred = null;		GrammarAST gpred = 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:			{				g=atom(_t);				_t = _retTree;				break;			}			case NOT:			{				AST __t66 = _t;				n = _t==ASTNULL ? null :(GrammarAST)_t;				match(_t,NOT);				_t = _t.getFirstChild();				{				if (_t==null) _t=ASTNULL;				switch ( _t.getType()) {				case CHAR_LITERAL:				{					AST __t68 = _t;					c = _t==ASTNULL ? null :(GrammarAST)_t;					match(_t,CHAR_LITERAL);					_t = _t.getFirstChild();					{					if (_t==null) _t=ASTNULL;					switch ( _t.getType()) {					case BANG:					case ROOT:					case RULEROOT:					{						ast1 = _t==ASTNULL ? null : (GrammarAST)_t;						ast_suffix(_t);						_t = _retTree;						break;					}					case 3:					{						break;					}					default:					{						throw new NoViableAltException(_t);					}					}					}					_t = __t68;					_t = _t.getNextSibling();											            int ttype=0;								if ( grammar.type==Grammar.LEXER ) {								ttype = Grammar.getCharValueFromGrammarCharLiteral(c.getText());								}								else {								ttype = grammar.getTokenType(c.getText());							}					IntSet notAtom = grammar.complement(ttype);					if ( notAtom.isNil() ) {					ErrorManager.grammarError(ErrorManager.MSG_EMPTY_COMPLEMENT,										  			              grammar,													              c.token,														          c.getText());					}						            g=factory.build_Set(notAtom);											break;				}				case TOKEN_REF:				{					AST __t70 = _t;					t = _t==ASTNULL ? null :(GrammarAST)_t;					match(_t,TOKEN_REF);					_t = _t.getFirstChild();					{					if (_t==null) _t=ASTNULL;					switch ( _t.getType()) {					case BANG:					case ROOT:					case RULEROOT:					{						ast3 = _t==ASTNULL ? null : (GrammarAST)_t;						ast_suffix(_t);						_t = _retTree;						break;					}					case 3:					{						break;					}					default:					{						throw new NoViableAltException(_t);					}					}					}					_t = __t70;					_t = _t.getNextSibling();											           int ttype = grammar.getTokenType(t.getText());					IntSet notAtom = grammar.complement(ttype);					if ( notAtom.isNil() ) {					ErrorManager.grammarError(ErrorManager.MSG_EMPTY_COMPLEMENT,									  			              grammar,												              t.token,													          t.getText());					}						           g=factory.build_Set(notAtom);											break;				}				case SET:				{					g=set(_t);					_t = _retTree;											           GrammarAST stNode = (GrammarAST)n.getFirstChild();					IntSet notSet = grammar.complement(stNode.getSetValue());					stNode.setSetValue(notSet);					if ( notSet.isNil() ) {					ErrorManager.grammarError(ErrorManager.MSG_EMPTY_COMPLEMENT,									  			              grammar,												              n.token);					}						           g=factory.build_Set(notSet);											break;				}				default:				{					throw new NoViableAltException(_t);				}				}				}				n.followingNFAState = g.right;				_t = __t66;				_t = _t.getNextSibling();				break;			}			case RANGE:			{				AST __t72 = _t;				GrammarAST tmp38_AST_in = (GrammarAST)_t;				match(_t,RANGE);				_t = _t.getFirstChild();				a = _t==ASTNULL ? null : (GrammarAST)_t;				atom(_t);				_t = _retTree;				b = _t==ASTNULL ? null : (GrammarAST)_t;				atom(_t);				_t = _retTree;				_t = __t72;				_t = _t.getNextSibling();				g = factory.build_Range(grammar.getTokenType(a.getText()),				grammar.getTokenType(b.getText()));				break;			}			case CHAR_RANGE:			{				AST __t73 = _t;				GrammarAST tmp39_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 = __t73;				_t = _t.getNextSibling();								if ( grammar.type==Grammar.LEXER ) {					g = factory.build_CharRange(c1.getText(), c2.getText());				}								break;			}			case ASSIGN:			{				AST __t74 = _t;				GrammarAST tmp40_AST_in = (GrammarAST)_t;				match(_t,ASSIGN);				_t = _t.getFirstChild();				GrammarAST tmp41_AST_in = (GrammarAST)_t;				match(_t,ID);				_t = _t.getNextSibling();				g=atom_or_notatom(_t);				_t = _retTree;				_t = __t74;				_t = _t.getNextSibling();				break;			}			case PLUS_ASSIGN:			{				AST __t75 = _t;				GrammarAST tmp42_AST_in = (GrammarAST)_t;				match(_t,PLUS_ASSIGN);				_t = _t.getFirstChild();				GrammarAST tmp43_AST_in = (GrammarAST)_t;

⌨️ 快捷键说明

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