Ejemplo 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();
            }
        }
Ejemplo 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()
            );
        }
Ejemplo n.º 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])
            );
        }
Ejemplo n.º 4
0
        public void StopWhenNotParsing()
        {
            var p = new Parser();
            p.Stop();

            Assert.True(!p.IsParsing);
            Assert.Equal(Syntan.SyntacticAnalysis.LR.ParsingPhase.NotParsing, p.Phase);
        }
Ejemplo n.º 5
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);
        }
Ejemplo n.º 6
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);
        }
Ejemplo n.º 7
0
        public void StepWhenNotParsing()
        {
            var p = new Parser();

            Assert.Throws<InvalidOperationException>(
                () => p.StepPhase()
            );
        }
Ejemplo n.º 8
0
        public void CreateNeedsNothing()
        {
            var p = new Parser();

            Assert.Equal(ParsingPhase.NotParsing, p.Phase);
        }
Ejemplo n.º 9
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()
            );
        }
Ejemplo n.º 10
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);
        }
Ejemplo n.º 11
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);
        }
Ejemplo n.º 12
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);
        }
Ejemplo n.º 13
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);
        }