Example #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();
            }
        }
Example #2
0
        public void StartWhenParsing()
        {
            var p = new Parser();

            p.Start(
                Fixtures.EmptyGrammar.ExtendedGrammar,
                Fixtures.EmptyGrammar.SLR1ParserTable,
                new Syntan.SyntacticAnalysis.TerminalSymbol[] { Fixtures.EmptyGrammar.ExtendedGrammar.EndOfSourceSymbol });

            Assert.Throws<InvalidOperationException>(
                () => p.Start(
                    Fixtures.EmptyGrammar.ExtendedGrammar,
                    Fixtures.EmptyGrammar.SLR1ParserTable,
                    new Syntan.SyntacticAnalysis.TerminalSymbol[] { Fixtures.EmptyGrammar.ExtendedGrammar.EndOfSourceSymbol })
            );
        }
Example #3
0
        public void StartWithEmptyInput()
        {
            var p = new Parser();

            Assert.Throws<UnexpectedEndOfSourceException>(
                () => p.Start(
                    Fixtures.EmptyGrammar.ExtendedGrammar,
                    Fixtures.EmptyGrammar.SLR1ParserTable,
                    new Syntan.SyntacticAnalysis.TerminalSymbol[0])
            );
        }
Example #4
0
        public void StopAfterAccept()
        {
            var p = new Parser();
            p.Start(
                Fixtures.EmptyGrammar.ExtendedGrammar,
                Fixtures.EmptyGrammar.SLR1ParserTable,
                new Syntan.SyntacticAnalysis.TerminalSymbol[] { Fixtures.EmptyGrammar.ExtendedGrammar.EndOfSourceSymbol });

            p.Stop();
            Assert.Equal(ParsingPhase.NotParsing, p.Phase);
            Assert.True(!p.IsParsing);
        }
Example #5
0
        public void StopAfterError()
        {
            var p = new Parser();
            p.Start(
                   Fixtures.Grammar2.ExtendedGrammar,
                   Fixtures.Grammar2.SLR1ParserTable,
                   new TerminalSymbol[] { Fixtures.Grammar2.ExtendedGrammar.EndOfSourceSymbol });

            p.Stop();
            Assert.Equal(ParsingPhase.NotParsing, p.Phase);
            Assert.True(!p.IsParsing);
        }
Example #6
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()
            );
        }
Example #7
0
        public void StartWithValidEmptyGrammar()
        {
            var p = new Parser();

            p.Start(
                Fixtures.EmptyGrammar.ExtendedGrammar,
                Fixtures.EmptyGrammar.SLR1ParserTable,
                new Syntan.SyntacticAnalysis.TerminalSymbol[] { Fixtures.EmptyGrammar.ExtendedGrammar.EndOfSourceSymbol });

            Assert.Equal(ParsingPhase.Accept, p.Phase);
        }
Example #8
0
        public void StartWithNullParserTable()
        {
            var p = new Parser();

            var ex = Assert.Throws<ArgumentNullException>(
                () => p.Start(
                    Fixtures.EmptyGrammar.ExtendedGrammar,
                    null,
                    new Syntan.SyntacticAnalysis.TerminalSymbol[0])
            );

            Assert.Equal("table", ex.ParamName);
        }
Example #9
0
        public void StartWithNullInput()
        {
            var p = new Parser();

            var ex = Assert.Throws<ArgumentNullException>(
                () => p.Start(
                    Fixtures.EmptyGrammar.ExtendedGrammar,
                    Fixtures.EmptyGrammar.SLR1ParserTable,
                    null)
            );

            Assert.Equal("input", ex.ParamName);
        }
Example #10
0
        public void StartWithNullGrammar()
        {
            var p = new Parser();

            var ex = Assert.Throws<ArgumentNullException>(
                () => p.Start(
                    null,
                    Fixtures.EmptyGrammar.SLR1ParserTable,
                    new Syntan.SyntacticAnalysis.TerminalSymbol[0])
            );

            Assert.Equal("grammar", ex.ParamName);
        }