treetonfaconverter.java

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

JAVA
2,853
字号
			match(_t,EOR);			_t = _t.getNextSibling();						if ( blk.setValue!=null ) {			// if block comes back as a set not BLOCK, make it			// a single ALT block			b = factory.build_AlternativeBlockFromSet(b);			}							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(blk);									int d = grammar.assignDecisionNumber( b.left );									grammar.setDecisionNFA( d, b.left );				grammar.setDecisionBlockAST(d, blk);								}											// 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 tmp22_AST_in = (GrammarAST)_t;				match(_t,LITERAL_protected);				_t = _t.getNextSibling();				break;			}			case LITERAL_public:			{				GrammarAST tmp23_AST_in = (GrammarAST)_t;				match(_t,LITERAL_public);				_t = _t.getNextSibling();				break;			}			case LITERAL_private:			{				GrammarAST tmp24_AST_in = (GrammarAST)_t;				match(_t,LITERAL_private);				_t = _t.getNextSibling();				break;			}			case FRAGMENT:			{				GrammarAST tmp25_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 __t36 = _t;			GrammarAST tmp26_AST_in = (GrammarAST)_t;			match(_t,SCOPE);			_t = _t.getFirstChild();			{			if (_t==null) _t=ASTNULL;			switch ( _t.getType()) {			case ACTION:			{				GrammarAST tmp27_AST_in = (GrammarAST)_t;				match(_t,ACTION);				_t = _t.getNextSibling();				break;			}			case 3:			case ID:			{				break;			}			default:			{				throw new NoViableAltException(_t);			}			}			}			{			_loop39:			do {				if (_t==null) _t=ASTNULL;				if ((_t.getType()==ID)) {					GrammarAST tmp28_AST_in = (GrammarAST)_t;					match(_t,ID);					_t = _t.getNextSibling();				}				else {					break _loop39;				}							} while (true);			}			_t = __t36;			_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();		this.blockLevel++;		if ( this.blockLevel==1 ) {this.outerAltNum=1;}						try {      // for error handling			if (_t==null) _t=ASTNULL;			if (((_t.getType()==BLOCK))&&(grammar.isValidSet(this,block_AST_in) &&		 !currentRuleName.equals(Grammar.ARTIFICIAL_TOKENS_RULENAME))) {				g=set(_t);				_t = _retTree;				this.blockLevel--;			}			else if ((_t.getType()==BLOCK)) {				AST __t41 = _t;				GrammarAST tmp29_AST_in = (GrammarAST)_t;				match(_t,BLOCK);				_t = _t.getFirstChild();				{				if (_t==null) _t=ASTNULL;				switch ( _t.getType()) {				case OPTIONS:				{					GrammarAST tmp30_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);						if ( this.blockLevel==1 ) {this.outerAltNum++;}											}					else {						if ( _cnt44>=1 ) { break _loop44; } else {throw new NoViableAltException(_t);}					}										_cnt44++;				} while (true);				}				GrammarAST tmp31_AST_in = (GrammarAST)_t;				match(_t,EOB);				_t = _t.getNextSibling();				_t = __t41;				_t = _t.getNextSibling();				g = factory.build_AlternativeBlock(alts);				this.blockLevel--;			}			else {				throw new NoViableAltException(_t);			}					}		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			if (_t==null) _t=ASTNULL;			switch ( _t.getType()) {			case LITERAL_catch:			{				{				int _cnt51=0;				_loop51:				do {					if (_t==null) _t=ASTNULL;					if ((_t.getType()==LITERAL_catch)) {						exceptionHandler(_t);						_t = _retTree;					}					else {						if ( _cnt51>=1 ) { break _loop51; } else {throw new NoViableAltException(_t);}					}										_cnt51++;				} while (true);				}				{				if (_t==null) _t=ASTNULL;				switch ( _t.getType()) {				case LITERAL_finally:				{					finallyClause(_t);					_t = _retTree;					break;				}				case EOR:				{					break;				}				default:				{					throw new NoViableAltException(_t);				}				}				}				break;			}			case LITERAL_finally:			{				finallyClause(_t);				_t = _retTree;				break;			}			default:			{				throw new NoViableAltException(_t);			}			}		}		catch (RecognitionException ex) {			reportError(ex);			if (_t!=null) {_t = _t.getNextSibling();}		}		_retTree = _t;	}		public final StateCluster  set(AST _t) throws RecognitionException {		StateCluster g=null;				GrammarAST set_AST_in = (_t == ASTNULL) ? null : (GrammarAST)_t;		GrammarAST b = null;				IntSet elements=new IntervalSet();		set_AST_in.setSetValue(elements); // track set for use by code gen						try {      // for error handling			AST __t99 = _t;			b = _t==ASTNULL ? null :(GrammarAST)_t;			match(_t,BLOCK);			_t = _t.getFirstChild();			{			int _cnt103=0;			_loop103:			do {				if (_t==null) _t=ASTNULL;				if ((_t.getType()==ALT)) {					AST __t101 = _t;					GrammarAST tmp32_AST_in = (GrammarAST)_t;					match(_t,ALT);					_t = _t.getFirstChild();					{					if (_t==null) _t=ASTNULL;					switch ( _t.getType()) {					case BACKTRACK_SEMPRED:					{						GrammarAST tmp33_AST_in = (GrammarAST)_t;						match(_t,BACKTRACK_SEMPRED);						_t = _t.getNextSibling();						break;					}					case BLOCK:					case CHAR_RANGE:					case STRING_LITERAL:					case CHAR_LITERAL:					case TOKEN_REF:					case NOT:					{						break;					}					default:					{						throw new NoViableAltException(_t);					}					}					}					setElement(_t,elements);					_t = _retTree;					GrammarAST tmp34_AST_in = (GrammarAST)_t;					match(_t,EOA);					_t = _t.getNextSibling();					_t = __t101;					_t = _t.getNextSibling();				}				else {					if ( _cnt103>=1 ) { break _loop103; } else {throw new NoViableAltException(_t);}				}								_cnt103++;			} while (true);			}			GrammarAST tmp35_AST_in = (GrammarAST)_t;			match(_t,EOB);			_t = _t.getNextSibling();			_t = __t99;			_t = _t.getNextSibling();						g = factory.build_Set(elements);			b.followingNFAState = g.right;			b.setValue = elements; // track set value of this block					}		catch (RecognitionException ex) {			reportError(ex);			if (_t!=null) {_t = _t.getNextSibling();}		}		_retTree = _t;		return g;	}		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 tmp36_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			{			_loop62:			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 __t59 = _t;					GrammarAST tmp37_AST_in = (GrammarAST)_t;					match(_t,REWRITE);					_t = _t.getFirstChild();					{					if (_t==null) _t=ASTNULL;					switch ( _t.getType()) {					case SEMPRED:					{						GrammarAST tmp38_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 tmp39_AST_in = (GrammarAST)_t;						match(_t,ALT);						_t = _t.getNextSibling();						break;					}					case TEMPLATE:					{						GrammarAST tmp40_AST_in = (GrammarAST)_t;						match(_t,TEMPLATE);						_t = _t.getNextSibling();						break;					}					case ACTION:					{						GrammarAST tmp41_AST_in = (GrammarAST)_t;						match(_t,ACTION);						_t = _t.getNextSibling();						break;					}					default:					{						throw new NoViableAltException(_t);					}					}					}					_t = __t59;					_t = _t.getNextSibling();				}				else {					break _loop62;				}							} 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 a = null;		GrammarAST b = null;		GrammarAST c1 = null;		GrammarAST c2 = null;		GrammarAST pred = null;		GrammarAST spred = null;		GrammarAST bpred = null;		GrammarAST gpred = null;				try {      // for error handling			if (_t==null) _t=ASTNULL;			switch ( _t.getType()) {			case ROOT:			{				AST __t64 = _t;				GrammarAST tmp42_AST_in = (GrammarAST)_t;				match(_t,ROOT);				_t = _t.getFirstChild();				g=element(_t);				_t = _retTree;				_t = __t64;				_t = _t.getNextSibling();				break;			}			case BANG:			{				AST __t65 = _t;				GrammarAST tmp43_AST_in = (GrammarAST)_t;				match(_t,BANG);				_t = _t.getFirstChild();				g=element(_t);				_t = _retTree;				_t = __t65;				_t = _t.getNextSibling();				break;			}			case ASSIGN:			{				AST __t66 = _t;				GrammarAST tmp44_AST_in = (GrammarAST)_t;				match(_t,ASSIGN);				_t = _t.getFirstChild();				GrammarAST tmp45_AST_in = (GrammarAST)_t;				match(_t,ID);				_t = _t.getNextSibling();				g=element(_t);				_t = _retTree;				_t = __t66;				_t = _t.getNextSibling();				break;

⌨️ 快捷键说明

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