Пример #1
0
 public CharacterSetRecord(Record record)
 {
     if (record.Entries.Count != 3)
         throw new CGTContentException("Invalid number of entries for character set");
     byte header = record.Entries[0].ToByteValue();
     if (header != 67) //'C'
         throw new CGTContentException("Invalid character set header");
     index = record.Entries[1].ToIntValue();
     characters = record.Entries[2].ToStringValue();
 }
Пример #2
0
		public InitialStatesRecord(Record record)
		{
			if (record.Entries.Count != 3)
				throw new CGTContentException("Invalid number of entries for initial states");
			byte header = record.Entries[0].ToByteValue();
			if (header != 73) //'I'
				throw new CGTContentException("Invalid initial states header");
			this.dfa   = record.Entries[1].ToIntValue();
			this.lalr  = record.Entries[2].ToIntValue();
		}
Пример #3
0
 public SymbolRecord(Record record)
 {
     if (record.Entries.Count != 4)
         throw new CGTContentException("Invalid number of entries for symbol");
     byte header = record.Entries[0].ToByteValue();
     if (header != 83) //'S'
         throw new CGTContentException("Invalid symbol header");
     this.index  = record.Entries[1].ToIntValue();
     this.name   = record.Entries[2].ToStringValue();
     this.kind   = record.Entries[3].ToIntValue();
 }
Пример #4
0
 public LALRStateRecord(Record record)
 {
     if (record.Entries.Count < 3)
         throw new CGTContentException("Invalid number of entries for LALR state");
     byte header = record.Entries[0].ToByteValue();
     if (header != 76) //'L'
         throw new CGTContentException("Invalid LALR state header");
     this.index = record.Entries[1].ToIntValue();
     //skip empty reserved entry
     actionSubRecords = new ActionSubRecordCollection(record,3);
 }
Пример #5
0
 public EdgeSubRecordCollection(Record record, int start)
 {
     list = new ArrayList();
     if ((record.Entries.Count - start) % 3 != 0)
         throw new CGTContentException("Invalid number of entries for edges in DFA state");
     for (int i = start; i < record.Entries.Count; i = i + 3)
     {
         EdgeSubRecord edgeRecord = new EdgeSubRecord(record.Entries[i], record.Entries[i + 1]);
         list.Add(edgeRecord);
     }
 }
Пример #6
0
 public ActionSubRecordCollection(Record record, int start)
 {
     list = new ArrayList();
     if ((record.Entries.Count - start) % 4 != 0)
         throw new CGTContentException("Invalid number of entries for actions in LALR state");
     for (int i = start; i < record.Entries.Count; i = i + 4)
     {
         ActionSubRecord actionRecord =
             new ActionSubRecord(record.Entries[i], record.Entries[i + 1], record.Entries[i + 2]);
         list.Add(actionRecord);
     }
 }
Пример #7
0
 public TableCounts(Record record)
 {
     if (record.Entries.Count != 6)
         throw new CGTContentException("Invalid number of entries for table counts");
     byte header = record.Entries[0].ToByteValue();
     if (header != 84) //'T'
         throw new CGTContentException("Invalid table counts header");
     this.symbolTable        = record.Entries[1].ToIntValue();
     this.characterSetTable  = record.Entries[2].ToIntValue();
     this.ruleTable          = record.Entries[3].ToIntValue();
     this.dfaTable           = record.Entries[4].ToIntValue();
     this.lalrTable          = record.Entries[5].ToIntValue();
 }
Пример #8
0
 public DFAStateRecord(Record record)
 {
     if (record.Entries.Count < 5)
         throw new CGTContentException("Invalid number of entries for DFA state");
     byte header = record.Entries[0].ToByteValue();
     if (header != 68) //'D'
         throw new CGTContentException("Invalid DFA state header");
     this.index = record.Entries[1].ToIntValue();
     this.acceptState = record.Entries[2].ToBoolValue();
     this.acceptIndex = record.Entries[3].ToIntValue();
     //skip empty reserved entry
     edgeSubRecords = new EdgeSubRecordCollection(record,5);
 }
Пример #9
0
 public Parameters(Record record)
 {
     if (record.Entries.Count != 7)
         throw new CGTContentException("Invalid number of entries for parameters");
     byte header = record.Entries[0].ToByteValue();
     if (header != 80) //'P'
         throw new CGTContentException("Invalid parameters header");
     name = record.Entries[1].ToStringValue();
     version = record.Entries[2].ToStringValue();
     author = record.Entries[3].ToStringValue();
     about = record.Entries[4].ToStringValue();
     caseSensitive = record.Entries[5].ToBoolValue();
     startSymbol = record.Entries[6].ToIntValue();
 }
Пример #10
0
		public RuleRecord(Record record)
		{
			if (record.Entries.Count < 4)
				throw new CGTContentException("Invalid number of entries for rule");
			byte header = record.Entries[0].ToByteValue();
			if (header != 82) //'R'
				throw new CGTContentException("Invalid rule header");
			this.index = record.Entries[1].ToIntValue();
			this.nonterminal = record.Entries[2].ToIntValue();		
			//skip reserved empty entry
			this.symbols = new IntegerList();
			for (int i=4;i<record.Entries.Count;i++)
			{
				int symbol = record.Entries[i].ToIntValue();
				symbols.Add(symbol);
			}
		}
Пример #11
0
 public int Add(Record record)
 {
     return list.Add(record);
 }
Пример #12
0
        private Record ReadRecord(CalithaBinReader reader)
        {
            Record record = new Record();
            byte entriesHeader = reader.ReadByte();
            if (entriesHeader != 77) // 'M'
            {
                throw new CGTStructureException("Invalid entries header at byte "+(stream.Position-1));
            }
            ushort entriesCount = reader.ReadUInt16();

            for (int i=0;i<entriesCount;i++)
            {
                record.Entries.Add(ReadEntry(reader));
            }
            return record;
        }