String ruleName = r.name; NFAState ruleBeginState = factory.newState(); ruleBeginState.setDescription("rule "+ruleName+" start"); ruleBeginState.enclosingRule = r; r.startState = ruleBeginState; NFAState ruleEndState = factory.newState(); ruleEndState.setDescription("rule "+ruleName+" end"); ruleEndState.setAcceptState(true); ruleEndState.enclosingRule = r;
String ruleName = r.name; NFAState ruleBeginState = factory.newState(); ruleBeginState.setDescription("rule "+ruleName+" start"); ruleBeginState.enclosingRule = r; r.startState = ruleBeginState; NFAState ruleEndState = factory.newState(); ruleEndState.setDescription("rule "+ruleName+" end"); ruleEndState.setAcceptState(true); ruleEndState.enclosingRule = r;
/** Define all the rule begin/end NFAStates to solve forward reference * issues. Critical for composite grammars too. * This is normally called on all root/delegates manually and then * buildNFA() is called afterwards because the NFA construction needs * to see rule start/stop states from potentially every grammar. Has * to be have these created a priori. Testing routines will often * just call buildNFA(), which forces a call to this method if not * done already. Works ONLY for single noncomposite grammars. */ public void createRuleStartAndStopNFAStates() { //System.out.println("### createRuleStartAndStopNFAStates "+getGrammarTypeString()+" grammar "+name+" NFAs"); if ( nfa!=null ) { return; } nfa = new NFA(this); factory = new NFAFactory(nfa); Collection<Rule> rules = getRules(); for (Rule r : rules) { String ruleName = r.name; NFAState ruleBeginState = factory.newState(); ruleBeginState.setDescription("rule "+ruleName+" start"); ruleBeginState.enclosingRule = r; r.startState = ruleBeginState; NFAState ruleEndState = factory.newState(); ruleEndState.setDescription("rule "+ruleName+" end"); ruleEndState.setAcceptState(true); ruleEndState.enclosingRule = r; r.stopState = ruleEndState; } }
/** Define all the rule begin/end NFAStates to solve forward reference * issues. Critical for composite grammars too. * This is normally called on all root/delegates manually and then * buildNFA() is called afterwards because the NFA construction needs * to see rule start/stop states from potentially every grammar. Has * to be have these created a priori. Testing routines will often * just call buildNFA(), which forces a call to this method if not * done already. Works ONLY for single noncomposite grammars. */ public void createRuleStartAndStopNFAStates() { //System.out.println("### createRuleStartAndStopNFAStates "+getGrammarTypeString()+" grammar "+name+" NFAs"); if ( nfa!=null ) { return; } nfa = new NFA(this); factory = new NFAFactory(nfa); Collection<Rule> rules = getRules(); for (Rule r : rules) { String ruleName = r.name; NFAState ruleBeginState = factory.newState(); ruleBeginState.setDescription("rule "+ruleName+" start"); ruleBeginState.enclosingRule = r; r.startState = ruleBeginState; NFAState ruleEndState = factory.newState(); ruleEndState.setDescription("rule "+ruleName+" end"); ruleEndState.setAcceptState(true); ruleEndState.enclosingRule = r; r.stopState = ruleEndState; } }
decisionState.setDescription("only alt of ()? block"); NFAState emptyAlt = newState(); emptyAlt.setDescription("epsilon path of ()? block"); NFAState blockEndNFAState; blockEndNFAState = newState(); transitionBetweenStates(A.right, blockEndNFAState, Label.EPSILON); blockEndNFAState.setDescription("end ()? block"); nfa.grammar.getNFAStateForAltOfDecision(A.left, n); NFAState emptyAlt = newState(); emptyAlt.setDescription("epsilon path of ()? block"); transitionBetweenStates(lastRealAlt, emptyAlt, Label.EPSILON); transitionBetweenStates(emptyAlt, A.right, Label.EPSILON);
decisionState.setDescription("only alt of ()? block"); NFAState emptyAlt = newState(); emptyAlt.setDescription("epsilon path of ()? block"); NFAState blockEndNFAState; blockEndNFAState = newState(); transitionBetweenStates(A.right, blockEndNFAState, Label.EPSILON); blockEndNFAState.setDescription("end ()? block"); nfa.grammar.getNFAStateForAltOfDecision(A.left, n); NFAState emptyAlt = newState(); emptyAlt.setDescription("epsilon path of ()? block"); transitionBetweenStates(lastRealAlt, emptyAlt, Label.EPSILON); transitionBetweenStates(emptyAlt, A.right, Label.EPSILON);
decisionState.setDescription("only alt of ()? block"); NFAState emptyAlt = newState(); emptyAlt.setDescription("epsilon path of ()? block"); NFAState blockEndNFAState = null; blockEndNFAState = newState(); transitionBetweenStates(A.right, blockEndNFAState, Label.EPSILON); blockEndNFAState.setDescription("end ()? block"); nfa.grammar.getNFAStateForAltOfDecision(A.left, n); NFAState emptyAlt = newState(); emptyAlt.setDescription("epsilon path of ()? block"); transitionBetweenStates(lastRealAlt, emptyAlt, Label.EPSILON); transitionBetweenStates(emptyAlt, A.right, Label.EPSILON);
decisionState.setDescription("only alt of ()? block"); NFAState emptyAlt = newState(); emptyAlt.setDescription("epsilon path of ()? block"); NFAState blockEndNFAState = null; blockEndNFAState = newState(); transitionBetweenStates(A.right, blockEndNFAState, Label.EPSILON); blockEndNFAState.setDescription("end ()? block"); nfa.grammar.getNFAStateForAltOfDecision(A.left, n); NFAState emptyAlt = newState(); emptyAlt.setDescription("epsilon path of ()? block"); transitionBetweenStates(lastRealAlt, emptyAlt, Label.EPSILON); transitionBetweenStates(emptyAlt, A.right, Label.EPSILON);
blockEndNFAState.setDescription("end block"); int altNum = 1; for (Iterator iter = alternativeStateClusters.iterator(); iter.hasNext();) { left.setDescription("alt "+altNum+" of ()"); transitionBetweenStates(left, g.left, Label.EPSILON); transitionBetweenStates(g.right, blockEndNFAState, Label.EPSILON);
blockEndNFAState.setDescription("end block"); int altNum = 1; for (Iterator iter = alternativeStateClusters.iterator(); iter.hasNext();) { left.setDescription("alt "+altNum+" of ()"); transitionBetweenStates(left, g.left, Label.EPSILON); transitionBetweenStates(g.right, blockEndNFAState, Label.EPSILON);
blockEndNFAState.setDescription("end block"); int altNum = 1; for (StateCluster g : alternativeStateClusters) { left.setDescription("alt "+altNum+" of ()"); transitionBetweenStates(left, g.left, Label.EPSILON); transitionBetweenStates(g.right, blockEndNFAState, Label.EPSILON);
blockEndNFAState.setDescription("end block"); int altNum = 1; for (StateCluster g : alternativeStateClusters) { left.setDescription("alt "+altNum+" of ()"); transitionBetweenStates(left, g.left, Label.EPSILON); transitionBetweenStates(g.right, blockEndNFAState, Label.EPSILON);
bypassDecisionState.setDescription("enter loop path of ()* block"); NFAState optionalAlt = newState(); optionalAlt.setDescription("epsilon path of ()* block"); NFAState blockEndNFAState = newState(); blockEndNFAState.decisionStateType = NFAState.RIGHT_EDGE_OF_BLOCK; A.right.setDescription("()* loopback");
bypassDecisionState.setDescription("enter loop path of ()* block"); NFAState optionalAlt = newState(); optionalAlt.setDescription("epsilon path of ()* block"); NFAState blockEndNFAState = newState(); blockEndNFAState.decisionStateType = NFAState.RIGHT_EDGE_OF_BLOCK; A.right.setDescription("()* loopback");
bypassDecisionState.setDescription("enter loop path of ()* block"); NFAState optionalAlt = newState(); optionalAlt.setDescription("epsilon path of ()* block"); NFAState blockEndNFAState = newState(); blockEndNFAState.decisionStateType = NFAState.RIGHT_EDGE_OF_BLOCK; A.right.setDescription("()* loopback");
bypassDecisionState.setDescription("enter loop path of ()* block"); NFAState optionalAlt = newState(); optionalAlt.setDescription("epsilon path of ()* block"); NFAState blockEndNFAState = newState(); blockEndNFAState.decisionStateType = NFAState.RIGHT_EDGE_OF_BLOCK; A.right.setDescription("()* loopback");
g.left.setDescription(grammar.grammarTreeToString(ebnf_AST_in,false)); b.right.setDescription("()* loopback of "+grammar.grammarTreeToString(ebnf_AST_in,false)); int d = grammar.assignDecisionNumber( b.right ); grammar.setDecisionNFA(d, b.right); b.right.setDescription("()+ loopback of "+grammar.grammarTreeToString(ebnf_AST_in,false)); int d = grammar.assignDecisionNumber( b.right ); grammar.setDecisionNFA(d, b.right); b.left.setDescription(grammar.grammarTreeToString(blk,false)); b.left.setDecisionASTNode(blk); int d = grammar.assignDecisionNumber( b.left );
(b!=null?((TreeToNFAConverter.block_return)b).g:null).left.setDescription(grammar.grammarTreeToString(blk, false)); (b!=null?((TreeToNFAConverter.block_return)b).g:null).left.setDecisionASTNode(blk); int d = grammar.assignDecisionNumber( (b!=null?((TreeToNFAConverter.block_return)b).g:null).left ); retval.g.left.setDescription(grammar.grammarTreeToString(((GrammarAST)retval.start), false)); bg.right.setDescription("()* loopback of "+grammar.grammarTreeToString(((GrammarAST)retval.start), false)); int d = grammar.assignDecisionNumber( bg.right ); grammar.setDecisionNFA(d, bg.right); bg.right.setDescription("()+ loopback of "+grammar.grammarTreeToString(((GrammarAST)retval.start), false)); int d = grammar.assignDecisionNumber( bg.right ); grammar.setDecisionNFA(d, bg.right);
(b!=null?((TreeToNFAConverter.block_return)b).g:null).left.setDescription(grammar.grammarTreeToString(blk, false)); (b!=null?((TreeToNFAConverter.block_return)b).g:null).left.setDecisionASTNode(blk); int d = grammar.assignDecisionNumber( (b!=null?((TreeToNFAConverter.block_return)b).g:null).left ); retval.g.left.setDescription(grammar.grammarTreeToString(((GrammarAST)retval.start), false)); bg.right.setDescription("()* loopback of "+grammar.grammarTreeToString(((GrammarAST)retval.start), false)); int d = grammar.assignDecisionNumber( bg.right ); grammar.setDecisionNFA(d, bg.right); bg.right.setDescription("()+ loopback of "+grammar.grammarTreeToString(((GrammarAST)retval.start), false)); int d = grammar.assignDecisionNumber( bg.right ); grammar.setDecisionNFA(d, bg.right);
b.left.setDescription(grammar.grammarTreeToString(rule_AST_in,false)); b.left.setDecisionASTNode(blk); int d = grammar.assignDecisionNumber( b.left );