示例#1
0
        internal int TestBlockAsSet(GrammarAST t)
        {
            Rule r = grammar.GetLocallyDefinedRule(currentRuleName);

            if (r.HasRewrite(outerAltNum))
            {
                return(-1);
            }

            TreeToNFAConverter other = new TreeToNFAConverter(grammar, nfa, factory, new CommonTreeNodeStream(t));

            other.state.backtracking++;
            other.currentRuleName = currentRuleName;
            other.outerAltNum     = outerAltNum;
            other.blockLevel      = blockLevel;

            var result = other.testBlockAsSet();

            if (other.state.failed)
            {
                return(-1);
            }

            return(result);
        }
示例#2
0
        public IIntSet SetRule(GrammarAST t)
        {
            TreeToNFAConverter other = new TreeToNFAConverter(grammar, nfa, factory, new CommonTreeNodeStream(t));

            other.currentRuleName = currentRuleName;
            other.outerAltNum     = outerAltNum;
            other.blockLevel      = blockLevel;

            return(other.setRule());
        }
示例#3
0
        public int TestSetRule( GrammarAST t )
        {
            TreeToNFAConverter other = new TreeToNFAConverter( grammar, nfa, factory, new CommonTreeNodeStream( t ) );

            other.state.backtracking++;
            other.currentRuleName = currentRuleName;
            other.outerAltNum = outerAltNum;
            other.blockLevel = blockLevel;

            var result = other.testSetRule();
            if ( other.state.failed )
                state.failed = true;

            return result;
        }
示例#4
0
 public virtual bool IsValidSet(TreeToNFAConverter nfabuilder, GrammarAST t)
 {
     bool valid = true;
     try
     {
         //[email protected]("parse BLOCK as set tree: "+t.toStringTree());
         int alts = nfabuilder.TestBlockAsSet( t );
         valid = ( alts > 1 );
     }
     catch ( RecognitionException /*re*/ )
     {
         // The rule did not parse as a set, return false; ignore exception
         valid = false;
     }
     //[email protected]("valid? "+valid);
     return valid;
 }
示例#5
0
 public virtual IIntSet GetSetFromRule(TreeToNFAConverter nfabuilder, string ruleName)
 {
     Rule r = GetRule( ruleName );
     if ( r == null )
     {
         return null;
     }
     IIntSet elements = null;
     //[email protected]("parsed tree: "+r.tree.toStringTree());
     elements = nfabuilder.SetRule( r.Tree );
     //[email protected]("elements="+elements);
     return elements;
 }
示例#6
0
        public virtual void BuildNFA()
        {
            if ( nfa == null )
            {
                CreateRuleStartAndStopNFAStates();
            }
            if ( nfa.Complete )
            {
                // don't let it create more than once; has side-effects
                return;
            }
            //[email protected]("### build "+getGrammarTypeString()+" grammar "+name+" NFAs");
            if ( Rules.Count == 0 )
            {
                return;
            }

            Antlr.Runtime.Tree.ITreeNodeStream input = new Antlr.Runtime.Tree.CommonTreeNodeStream( grammarTree );
            TreeToNFAConverter nfaBuilder = new TreeToNFAConverter( this, nfa, factory, input );
            try
            {
                nfaBuilder.grammar_();
            }
            catch ( RecognitionException re )
            {
                ErrorManager.Error( ErrorManager.MSG_BAD_AST_STRUCTURE,
                                   name,
                                   re );
            }
            nfa.Complete = true;
        }
        internal int TestBlockAsSet( GrammarAST t )
        {
            Rule r = grammar.GetLocallyDefinedRule( currentRuleName );
            if ( r.HasRewrite( outerAltNum ) )
                return -1;

            TreeToNFAConverter other = new TreeToNFAConverter( grammar, nfa, factory, new CommonTreeNodeStream( t ) );

            other.state.backtracking++;
            other.currentRuleName = currentRuleName;
            other.outerAltNum = outerAltNum;
            other.blockLevel = blockLevel;

            var result = other.testBlockAsSet();
            if ( other.state.failed )
                return -1;

            return result;
        }
        public int TestSetRule( GrammarAST t )
        {
            TreeToNFAConverter other = new TreeToNFAConverter( grammar, nfa, factory, new CommonTreeNodeStream( t ) );

            other.state.backtracking++;
            other.currentRuleName = currentRuleName;
            other.outerAltNum = outerAltNum;
            other.blockLevel = blockLevel;

            var result = other.testSetRule();
            if ( other.state.failed )
                state.failed = true;

            return result;
        }
        public IIntSet SetRule( GrammarAST t )
        {
            TreeToNFAConverter other = new TreeToNFAConverter( grammar, nfa, factory, new CommonTreeNodeStream( t ) );

            other.currentRuleName = currentRuleName;
            other.outerAltNum = outerAltNum;
            other.blockLevel = blockLevel;

            return other.setRule();
        }