コード例 #1
0
 public GrammarCompilationContext(GrammarData grammarData)
 {
     if (grammarData == null)
         throw new ArgumentNullException(nameof(grammarData));
     GrammarData = grammarData;
     States= new List<IntermediateParserState>();
     Conflicts = new List<GrammarReductionConflict>();
     InitialStates = new Dictionary<GrammarDefinition, IntermediateParserState>();
 }
コード例 #2
0
        private static void TestSerializer(Grammar grammar)
        {
            var data = new GrammarData(grammar);
            var serializer = new ParserAutomatonSerializer(data);
            var result = GrammarCompiler.Compile(data);
            using (var stream = new MemoryStream())
            {
                serializer.Serialize(stream, result.Automaton);
                stream.Position = 0;
                var newAutomaton = serializer.Deserialize(stream);

                Assert.AreEqual(result.Automaton.DefaultInitialState.Id, newAutomaton.DefaultInitialState.Id);
                Assert.AreEqual(result.Automaton.States.Count, newAutomaton.States.Count);

                for (int index = 0; index < result.Automaton.States.Count; index++)
                {
                    var expectedState = result.Automaton.States[index];
                    var actualState = newAutomaton.States[index];

                    ValidateState(expectedState, actualState);
                }
            }
        }
コード例 #3
0
        public static GrammarCompilationResult Compile(GrammarData grammarData)
        {
            if (grammarData == null)
                throw new ArgumentNullException(nameof(grammarData));

            var context = new GrammarCompilationContext(grammarData);
            CreateLr0States(context);
            ConstructAugmentedGrammar(context);
            ComputeLookaheads(context);
            PlaceReduceActions(context);

            var automaton = CreateAutomaton(context);
            var result = new GrammarCompilationResult(context, automaton);
            return result;
        }
コード例 #4
0
 public ParserAutomatonSerializer(GrammarData data)
 {
     if (data == null)
         throw new ArgumentNullException(nameof(data));
     Data = data;
 }