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); }
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); } }
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); } }
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); } }
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); } }
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); } }
private void Reset() { stream = null; structure = null; content = null; dfaStates = null; parserStates = null; symbols = null; rules = null; }
/// <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(); } }