Пример #1
0
 /// <summary>
 /// Reads a CGT and creates all the objects needed to create
 /// a tokenizer and parser at a later time.
 /// </summary>
 /// <param name="stream">The CGT stream.</param>
 private void ReadFile(Stream stream)
 {
     try
     {
         Reset();
         this.stream = stream;
         CalithaBinReader reader = new CalithaBinReader(stream);
         string           header = "";
         try
         {
             header = reader.ReadUnicodeString();
             if (!header.StartsWith("GOLD"))
             {
                 throw new CGTStructureException("File header is invalid");
             }
         }
         catch (EndOfStreamException e)
         {
             throw new CGTStructureException("File header is invalid", e);
         }
         RecordCollection records = new RecordCollection();
         while (!(stream.Position == stream.Length))
         {
             records.Add(ReadRecord(reader));
         }
         structure    = new CGTStructure(header, records);
         content      = new CGTContent(structure);
         dfaStates    = CreateDFAStates(content);
         parserStates = CreateParserStates(content);
     }
     finally
     {
         stream.Close();
     }
 }
Пример #2
0
 private void Reset()
 {
     stream       = null;
     structure    = null;
     content      = null;
     dfaStates    = null;
     parserStates = null;
     symbols      = null;
     rules        = null;
 }
Пример #3
0
        private lalr.StateCollection CreateParserStates(CGTContent content)
        {
            rules = CreateRules(content);

            lalr.StateCollection states = new lalr.StateCollection();
            foreach (LALRStateRecord record in content.LALRStateTable)
            {
                lalr.State state = new lalr.State(record.Index);
                states.Add(state);
            }

            foreach (LALRStateRecord record in content.LALRStateTable)
            {
                lalr.State state = states[record.Index];
                foreach (ActionSubRecord subRecord in record.ActionSubRecords)
                {
                    Action action = ActionFactory.CreateAction(subRecord, states, symbols, rules);
                    state.Actions.Add(action);
                }
            }
            return(states);
        }
Пример #4
0
 private void Reset()
 {
     stream = null;
     structure = null;
     content = null;
     dfaStates = null;
     parserStates = null;
     symbols = null;
     rules = null;
 }
Пример #5
0
 /// <summary>
 /// Reads a CGT and creates all the objects needed to create
 /// a tokenizer and parser at a later time.
 /// </summary>
 /// <param name="stream">The CGT stream.</param>
 private void ReadFile(Stream stream)
 {
     try
     {
         Reset();
         this.stream = stream;
         CalithaBinReader reader = new CalithaBinReader(stream);
         string header = "";
         try
         {
             header = reader.ReadUnicodeString();
             if (! header.StartsWith("GOLD"))
                 throw new CGTStructureException("File header is invalid");
         }
         catch (EndOfStreamException e)
         {
             throw new CGTStructureException("File header is invalid", e);
         }
         RecordCollection records = new RecordCollection();
         while (!(stream.Position == stream.Length))
         {
             records.Add(ReadRecord(reader));
         }
         structure = new CGTStructure(header, records);
         content = new CGTContent(structure);
         dfaStates = CreateDFAStates(content);
         parserStates = CreateParserStates(content);
     }
     finally
     {
         stream.Close();
     }
 }
Пример #6
0
        private lalr.StateCollection CreateParserStates(CGTContent content)
        {
            rules = CreateRules(content);

            lalr.StateCollection states = new lalr.StateCollection();
            foreach (LALRStateRecord record in content.LALRStateTable)
            {
                lalr.State state = new lalr.State(record.Index);
                states.Add(state);
            }

            foreach (LALRStateRecord record in content.LALRStateTable)
            {
                lalr.State state = states[record.Index];
                foreach (ActionSubRecord subRecord in record.ActionSubRecords)
                {
                    Action action = ActionFactory.CreateAction(subRecord, states, symbols, rules);
                    state.Actions.Add(action);
                }
            }
            return states;
        }