예제 #1
0
파일: Grammar.cs 프로젝트: zgf/VBF
        public static ProductionBase <T> Union <T>(params ProductionBase <T>[] productions)
        {
            CodeContract.RequiresArgumentInRange(productions.Length > 0, "productions", "There must be at least one production to be unioned");

            ProductionBase <T> result = productions[0];

            for (int i = 1; i < productions.Length; i++)
            {
                result = new AlternationProduction <T>(result, productions[i]);
            }

            return(result);
        }
예제 #2
0
파일: Grammar.cs 프로젝트: zgf/VBF
        public static ProductionBase <Lexeme> Union(params Token[] tokens)
        {
            CodeContract.RequiresArgumentInRange(tokens.Length > 0, "tokens", "There must be at least on token to be unioned");

            ProductionBase <Lexeme> result = tokens[0].AsTerminal();

            for (int i = 1; i < tokens.Length; i++)
            {
                result = new AlternationProduction <Lexeme>(result, tokens[i].AsTerminal());
            }

            return(result);
        }
예제 #3
0
        ReduceResult IProductionVisitor <StackNode, ReduceResult> .VisitAlternation <T>(AlternationProduction <T> alternationProduction, StackNode TopStack)
        {
            var info = ((ProductionBase)alternationProduction).Info;

            //compute goto
            var gotoAction = m_transitions.GetGoto(TopStack.PrevNode.StateIndex, info.NonTerminalIndex);

            //perform goto
            StackNode reduceNode = new StackNode(gotoAction, TopStack.PrevNode, TopStack.ReducedValue);

            return(new ReduceResult(reduceNode));
        }