Exemplo n.º 1
0
		public CGTContent(CGTStructure structure)
		{
			if (structure.Records.Count < 3)
				throw new CGTContentException("File does not have enough records");
			parameters = new Parameters(structure.Records[0]);
			tableCounts = new TableCounts(structure.Records[1]);
			
			int initialStatesStart = 2;
			int characterSetStart = initialStatesStart + 1;
			int symbolStart = characterSetStart + TableCounts.CharacterSetTable;
			int ruleStart = symbolStart + TableCounts.SymbolTable;
			int dfaStart = ruleStart + TableCounts.RuleTable;
			int lalrStart = dfaStart + TableCounts.DFATable;
			int specifiedRecordCount = lalrStart + TableCounts.LALRTable;
			if (structure.Records.Count != specifiedRecordCount)
				throw new CGTContentException("Invalid number of records");
			
			characterSetTable =	new CharacterSetTable(structure,
													  characterSetStart,
													  TableCounts.CharacterSetTable);
			symbolTable = new SymbolTable(structure,
				symbolStart,
				TableCounts.SymbolTable);

			ruleTable = new RuleTable(structure,
									  ruleStart,
									  TableCounts.RuleTable);
			initialStates = new InitialStatesRecord(structure.Records[initialStatesStart]);
			dfaStateTable = new DFAStateTable(structure,dfaStart,TableCounts.DFATable);
			lalrStateTable = new LALRStateTable(structure,lalrStart,TableCounts.LALRTable);
		}
Exemplo n.º 2
0
 public DFAStateTable(CGTStructure structure, int start, int count)
 {
     list = new ArrayList();
     for (int i = start; i < start + count; i++)
     {
         DFAStateRecord dfaState = new DFAStateRecord(structure.Records[i]);
         list.Add(dfaState);
     }
 }
Exemplo n.º 3
0
 public RuleTable(CGTStructure structure, int start, int count)
 {
     list = new ArrayList();
     for (int i=start;i<start+count;i++)
     {
         RuleRecord ruleRecord = new RuleRecord(structure.Records[i]);
         list.Add(ruleRecord);
     }
 }
Exemplo n.º 4
0
		public SymbolTable(CGTStructure cgtStructure, int start, int count)
		{
			list = new ArrayList();
			for (int i=start;i<start+count;i++)
			{
				SymbolRecord symbol = new SymbolRecord(cgtStructure.Records[i]);
				list.Add(symbol);
			}
		}
Exemplo n.º 5
0
 public CharacterSetTable(CGTStructure structure, int start, int count)
 {
     list = new ArrayList();
     for (int i=start;i<start+count;i++)
     {
         CharacterSetRecord charSet = new CharacterSetRecord(structure.Records[i]);
         list.Add(charSet);
     }
 }
Exemplo n.º 6
0
 public LALRStateTable(CGTStructure structure, int start, int count)
 {
     list = new ArrayList();
     for (int i = start; i < start + count; i++)
     {
         LALRStateRecord lalrState = new LALRStateRecord(structure.Records[i]);
         list.Add(lalrState);
     }
 }
Exemplo n.º 7
0
		private void Reset()
		{
			stream = null;
			structure = null;
			content = null;
			dfaStates = null;
			parserStates = null;
			symbols = null;
			rules = null;
		}
Exemplo n.º 8
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();
     }
 }