public AutomatonSourceParser(ParserAutomaton automaton)
 {
     if (automaton == null)
         throw new ArgumentNullException(nameof(automaton));
     Automaton = automaton;
 }
 public GrammarCompilationResult(GrammarCompilationContext context, ParserAutomaton automaton)
 {
     CompilationContext = context;
     Automaton = automaton;
 }
Example #3
0
 private static ParserAutomaton CreateAutomaton(GrammarCompilationContext context)
 {
     var automaton = new ParserAutomaton(context.GrammarData.Grammar);
     foreach (var initialState in context.InitialStates)
         automaton.InitialStates.Add((GrammarDefinition)initialState.Key.Rule.Switch[0][0], initialState.Value.State);
     automaton.DefaultInitialState = context.InitialStates[context.GrammarData.DefaultAugmentedRoot].State;
     automaton.States.AddRange(context.States.Select(x => x.State));
     return automaton;
 }
        public void Serialize(Stream outputStream, ParserAutomaton automaton)
        {
            var writer = new BinaryWriter(outputStream);
            var context = new SerializerContext(automaton, writer);

            writer.Write((ushort)automaton.States.Count);
            writer.Write((ushort)automaton.DefaultInitialState.Id);
            writer.Write((byte)automaton.InitialStates.Count);

            foreach (var state in context.Automaton.InitialStates)
                WriteInitialStateEntry(writer, state);

            foreach (var state in context.Automaton.States)
                WriteState(context, state);
        }
 public SerializerContext(ParserAutomaton automaton, BinaryWriter writer)
 {
     Writer = writer;
     Automaton = automaton;
 }
 public DeserializerContext(Grammar grammar, BinaryReader reader)
 {
     Reader = reader;
     Automaton = new ParserAutomaton(grammar);
 }