Exemplo n.º 1
0
        public void ParsingSteps(
            Syntan.SyntacticAnalysis.ExtendedGrammar grammar,
            Syntan.SyntacticAnalysis.LR.ParserTable table,
            IEnumerable<Syntan.SyntacticAnalysis.TerminalSymbol> input,
            IEnumerable<Fixtures.ParsingStepData> expected_parsing_steps)
        {
            var p = new Parser();

            p.Start(grammar, table, input);

            foreach( var step in expected_parsing_steps )
            {
                Assert.Equal(step.Phase, p.Phase);
                Assert.Equal(step.IsParsing, p.IsParsing);
                Assert.Equal(step.IsFinished, p.IsFinished);
                Assert.Equal(step.StepCount, p.StepCount);
                Assert.Equal(step.CurrentState, p.CurrentState);
                Assert.Equal(step.CurrentInputSymbol, p.CurrentInputSymbol);
                Assert.Equal(step.ActionArgument, p.ActionArgument);
                if( step.AreReductionPropertiesSet )
                {
                    Assert.Equal(step.GotoState, p.GotoState);
                    Assert.Equal(step.GotoSymbol, p.GotoSymbol);
                    Assert.Equal(step.ReductionRule, p.ReductionRule);
                }

                p.StepPhase();
            }
        }
Exemplo n.º 2
0
        public void SetpAfterAccept()
        {
            var p = new Parser();
            p.Start(
                Fixtures.EmptyGrammar.ExtendedGrammar,
                Fixtures.EmptyGrammar.SLR1ParserTable,
                new Syntan.SyntacticAnalysis.TerminalSymbol[] { Fixtures.EmptyGrammar.ExtendedGrammar.EndOfSourceSymbol });

            Assert.Throws<InvalidOperationException>(
                () => p.StepPhase()
            );
        }
Exemplo n.º 3
0
        public void StepWhenNotParsing()
        {
            var p = new Parser();

            Assert.Throws<InvalidOperationException>(
                () => p.StepPhase()
            );
        }
Exemplo n.º 4
0
        public void StepAfterError()
        {
            var p = new Parser();
            p.Start(
                Fixtures.Grammar2.ExtendedGrammar,
                Fixtures.Grammar2.SLR1ParserTable,
                new TerminalSymbol[] { Fixtures.Grammar2.ExtendedGrammar.EndOfSourceSymbol });

            Assert.Throws<InvalidOperationException>(
                () => p.StepPhase()
            );
        }