📄 treetonfaconverter.java
字号:
case ROOT: { ast3 = _t==ASTNULL ? null : (GrammarAST)_t; ast_suffix(_t); _t = _retTree; break; } case 3: { break; } default: { throw new NoViableAltException(_t); } } } int ttype=0; IntSet notAtom = null; if ( grammar.type==Grammar.LEXER ) { notAtom = grammar.getSetFromRule(this,t.getText()); if ( notAtom==null ) { ErrorManager.grammarError(ErrorManager.MSG_RULE_INVALID_SET, grammar, t.token, t.getText()); } else { notAtom = grammar.complement(notAtom); } } else { ttype = grammar.getTokenType(t.getText()); notAtom = grammar.complement(ttype); } if ( notAtom==null || notAtom.isNil() ) { ErrorManager.grammarError(ErrorManager.MSG_EMPTY_COMPLEMENT, grammar, t.token, t.getText()); } g=factory.build_Set(notAtom); break; } case BLOCK: { g=set(_t); _t = _retTree; GrammarAST stNode = (GrammarAST)n.getFirstChild(); //IntSet notSet = grammar.complement(stNode.getSetValue()); // let code generator complement the sets IntSet s = stNode.getSetValue(); stNode.setSetValue(s); // let code gen do the complement again; here we compute // for NFA construction s = grammar.complement(s); if ( s.isNil() ) { ErrorManager.grammarError(ErrorManager.MSG_EMPTY_COMPLEMENT, grammar, n.token); } g=factory.build_Set(s); break; } default: { throw new NoViableAltException(_t); } } } n.followingNFAState = g.right; _t = __t80; _t = _t.getNextSibling(); break; } default: { throw new NoViableAltException(_t); } } } catch (RecognitionException ex) { reportError(ex); if (_t!=null) {_t = _t.getNextSibling();} } _retTree = _t; return g; } public final StateCluster ebnf(AST _t) throws RecognitionException { StateCluster g=null; GrammarAST ebnf_AST_in = (_t == ASTNULL) ? null : (GrammarAST)_t; StateCluster b = null; GrammarAST blk = ebnf_AST_in; if ( blk.getType()!=BLOCK ) { blk = (GrammarAST)blk.getFirstChild(); } GrammarAST eob = blk.getLastChild(); try { // for error handling if (_t==null) _t=ASTNULL; switch ( _t.getType()) { case OPTIONAL: { AST __t72 = _t; GrammarAST tmp58_AST_in = (GrammarAST)_t; match(_t,OPTIONAL); _t = _t.getFirstChild(); b=block(_t); _t = _retTree; _t = __t72; _t = _t.getNextSibling(); if ( blk.setValue!=null ) { // if block comes back SET not BLOCK, make it // a single ALT block b = factory.build_AlternativeBlockFromSet(b); } g = factory.build_Aoptional(b); g.left.setDescription(grammar.grammarTreeToString(ebnf_AST_in,false)); // there is always at least one alt even if block has just 1 alt int d = grammar.assignDecisionNumber( g.left ); grammar.setDecisionNFA(d, g.left); grammar.setDecisionBlockAST(d, blk); g.left.setDecisionASTNode(ebnf_AST_in); break; } case CLOSURE: { AST __t73 = _t; GrammarAST tmp59_AST_in = (GrammarAST)_t; match(_t,CLOSURE); _t = _t.getFirstChild(); b=block(_t); _t = _retTree; _t = __t73; _t = _t.getNextSibling(); if ( blk.setValue!=null ) { b = factory.build_AlternativeBlockFromSet(b); } g = factory.build_Astar(b); // track the loop back / exit decision point b.right.setDescription("()* loopback of "+grammar.grammarTreeToString(ebnf_AST_in,false)); int d = grammar.assignDecisionNumber( b.right ); grammar.setDecisionNFA(d, b.right); grammar.setDecisionBlockAST(d, blk); b.right.setDecisionASTNode(eob); // make block entry state also have same decision for interpreting grammar NFAState altBlockState = (NFAState)g.left.transition(0).target; altBlockState.setDecisionASTNode(ebnf_AST_in); altBlockState.setDecisionNumber(d); g.left.setDecisionNumber(d); // this is the bypass decision (2 alts) g.left.setDecisionASTNode(ebnf_AST_in); break; } case POSITIVE_CLOSURE: { AST __t74 = _t; GrammarAST tmp60_AST_in = (GrammarAST)_t; match(_t,POSITIVE_CLOSURE); _t = _t.getFirstChild(); b=block(_t); _t = _retTree; _t = __t74; _t = _t.getNextSibling(); if ( blk.setValue!=null ) { b = factory.build_AlternativeBlockFromSet(b); } g = factory.build_Aplus(b); // don't make a decision on left edge, can reuse loop end decision // track the loop back / exit decision point b.right.setDescription("()+ loopback of "+grammar.grammarTreeToString(ebnf_AST_in,false)); int d = grammar.assignDecisionNumber( b.right ); grammar.setDecisionNFA(d, b.right); grammar.setDecisionBlockAST(d, blk); b.right.setDecisionASTNode(eob); // make block entry state also have same decision for interpreting grammar NFAState altBlockState = (NFAState)g.left.transition(0).target; altBlockState.setDecisionASTNode(ebnf_AST_in); altBlockState.setDecisionNumber(d); break; } default: if (_t==null) _t=ASTNULL; if (((_t.getType()==BLOCK))&&(grammar.isValidSet(this,ebnf_AST_in))) { g=set(_t); _t = _retTree; } else if ((_t.getType()==BLOCK)) { b=block(_t); _t = _retTree; // track decision if > 1 alts if ( grammar.getNumberOfAltsForDecisionNFA(b.left)>1 ) { b.left.setDescription(grammar.grammarTreeToString(blk,false)); b.left.setDecisionASTNode(blk); int d = grammar.assignDecisionNumber( b.left ); grammar.setDecisionNFA( d, b.left ); grammar.setDecisionBlockAST(d, blk); } g = b; } else { throw new NoViableAltException(_t); } } } catch (RecognitionException ex) { reportError(ex); if (_t!=null) {_t = _t.getNextSibling();} } _retTree = _t; return g; } public final StateCluster tree(AST _t) throws RecognitionException { StateCluster g=null; GrammarAST tree_AST_in = (_t == ASTNULL) ? null : (GrammarAST)_t; StateCluster e=null; GrammarAST el=null; StateCluster down=null, up=null; try { // for error handling AST __t76 = _t; GrammarAST tmp61_AST_in = (GrammarAST)_t; match(_t,TREE_BEGIN); _t = _t.getFirstChild(); el=(GrammarAST)_t; g=element(_t); _t = _retTree; down = factory.build_Atom(Label.DOWN); // TODO set following states for imaginary nodes? //el.followingNFAState = down.right; g = factory.build_AB(g,down); { _loop78: do { if (_t==null) _t=ASTNULL; if ((_tokenSet_0.member(_t.getType()))) { el=(GrammarAST)_t; e=element(_t); _t = _retTree; g = factory.build_AB(g,e); } else { break _loop78; } } while (true); } up = factory.build_Atom(Label.UP); //el.followingNFAState = up.right; g = factory.build_AB(g,up); // tree roots point at right edge of DOWN for LOOK computation later tree_AST_in.NFATreeDownState = down.left; _t = __t76; _t = _t.getNextSibling(); } catch (RecognitionException ex) { reportError(ex); if (_t!=null) {_t = _t.getNextSibling();} } _retTree = _t; return g; } public final void ast_suffix(AST _t) throws RecognitionException { GrammarAST ast_suffix_AST_in = (_t == ASTNULL) ? null : (GrammarAST)_t; if ( grammar.getOption("output")==null ) { ErrorManager.grammarError(ErrorManager.MSG_REWRITE_OR_OP_WITH_NO_OUTPUT_OPTION, grammar, ast_suffix_AST_in.token, currentRuleName); } try { // for error handling if (_t==null) _t=ASTNULL; switch ( _t.getType()) { case ROOT: { GrammarAST tmp62_AST_in = (GrammarAST)_t; match(_t,ROOT); _t = _t.getNextSibling(); break; } case BANG: { GrammarAST tmp63_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, IntSet elements ) 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; int ttype; IntSet ns=null; StateCluster gset; 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(); if ( grammar.type==Grammar.LEXER ) { ttype = Grammar.getCharValueFromGrammarCharLiteral(c.getText()); } else { ttype = grammar.getTokenType(c.getText()); } if ( elements.member(ttype) ) { ErrorManager.grammarError(ErrorManager.MSG_DUPLICATE_SET_ENTRY, grammar, c.token, c.getText()); } elements.add(ttype); break; } case TOKEN_REF: { t = (GrammarAST)_t; match(_t,TOKEN_REF); _t = _t.getNextSibling(); if ( grammar.type==Grammar.LEXER ) { // recursively will invoke this rule to match elements in target rule ref IntSet ruleSet = grammar.getSetFromRule(this,t.getText()); if ( ruleSet==null ) { ErrorManager.grammarError(ErrorManager.MSG_RULE_INVALID_SET, grammar, t.token, t.getText()); } else { elements.addAll(ruleSet); } } else { ttype = grammar.getTokenType(t.getText()); if ( elements.member(ttype) ) { ErrorManager.grammarError(ErrorManager.MSG_DUPLICATE_SET_ENTRY, grammar, t.token, t.getText()); } elements.add(ttype); } break; } case STRING_LITERAL: { s = (GrammarAST)_t; match(_t,STRING_LITERAL); _t = _t.getNextSibling(); ttype = grammar.getTokenType(s.getText()); if ( elements.member(ttype) ) { ErrorManager.grammarError(ErrorManager.MSG_DUPLICATE_SET_ENTRY, grammar, s.token, s.getText()); } elements.add(ttype); break; } case CHAR_RANGE: { AST __t118 = _t; GrammarAST tmp64_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 = __t118; _t = _t.getNextSibling(); if ( grammar.type==Grammar.LEXER ) { int a = Grammar.getCharValueFromGrammarCharLiteral(c1.getText()); int b = Grammar.getCharValueFromGrammarCharLiteral(c2.getText()); elements.addAll(IntervalSet.of(a,b)); } break; } case BLOCK: { gset=set(_t); _t = _retTree; Transition setTrans = gset.left.transition(0); elements.addAll(setTrans.label.getSet()); break; } case NOT: { AST __t119 = _t; GrammarAST tmp65_AST_in = (GrammarAST)_t; match(_t,NOT); _t = _t.getFirstChild(); ns=new IntervalSet(); setElement(_t,ns); _t = _retTree; IntSet not = grammar.complement(ns); elements.addAll(not); _t = __t119; _t = _t.getNextSibling(); break; } default: { throw new NoViableAltException(_t); } } } catch (RecognitionException ex) { reportError(ex); if (_t!=null) {_t = _t.getNextSibling();} } _retTree = _t; } public final IntSet setRule(AST _t) throws RecognitionException { IntSet elements=new IntervalSet(); GrammarAST setRule_AST_in = (_t == ASTNULL) ? null : (GrammarAST)_t; GrammarAST id = null; IntSet s=null; try { // for error handling AST __t105 = _t; GrammarAST tmp66_AST_in = (GrammarAST)_t; match(_t,RULE); _t = _t.getFirstChild(); id = (GrammarAST)_t; match(_t,ID); _t = _t.getNextSibling(); { if (_t==null) _t=ASTNULL; switch ( _t.getType()) { case FRAGMENT: case LITERAL_protected: case LITERAL_public: case LITERAL_private: { modifier(_t); _t = _retTree; break; } case ARG: { break; } default: { throw new NoViableAltException(_t); } } } GrammarAST tmp67_AST_in = (GrammarAST)_t; match(_t,ARG); _t = _t.getNextSibling(); GrammarAST tmp68_AST_in = (GrammarAST)_t; match(_t,RET); _t = _t.getNextSibling(); { if (_t==null) _t=ASTNULL; switch ( _t.getType()) { case OPTIONS: { GrammarAST tmp69_AST_in = (GrammarAST)_t; match(_t,OPTIONS); _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); } } } { _loop110: do { if (_t==null) _t=ASTNULL; if ((_t.getType()==AMPERSAND)) { GrammarAST tmp70_AST_in = (GrammarAST)_t; match(_t,AMPERSAND);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -