protected LalrActionWithLalrState(int index, Symbol symbol, LalrState state) : base(index, symbol) { if (state == null) { throw new ArgumentNullException("state"); } Debug.Assert(symbol.Owner == state.Owner); this.state = state; }
/// <summary> /// Reads table record counts and initializes tables. /// </summary> /// <param name="context"></param> private void ReadTableCounts(LoadContext context, bool readGroups) { // Initialize tables symbolTable = new Symbol[context.ReadIntegerEntry()]; charSetTable = new DfaCharset[context.ReadIntegerEntry()]; ruleTable = new Rule[context.ReadIntegerEntry()]; for (int i = 0; i < ruleTable.Length; i++) { ruleTable[i] = new Rule(this, i); } dfaStateTable = new DfaState[context.ReadIntegerEntry()]; for (int i = 0; i < dfaStateTable.Length; i++) { dfaStateTable[i] = new DfaState(this, i); } lalrStateTable = new LalrState[context.ReadIntegerEntry()]; for (int i = 0; i < lalrStateTable.Length; i++) { lalrStateTable[i] = new LalrState(this, i); } groupTable = new Group[readGroups ? context.ReadIntegerEntry() : 0]; }
/// <summary> /// Loads grammar from the binary reader. /// </summary> private void Load(LoadContext context) { string headerString = context.ReadHeaderString(); // Trace.WriteLine(headerString, "Reading header"); Match headerMatch = FileHeader.Match(headerString); if (!headerMatch.Success) { throw new FileLoadException("The File Header is invalid or unsupported: " + headerString); } switch (headerMatch.Groups["version"].Value) { case "1.0": fileVersion = CgtVersion.V1_0; break; case "5.0": fileVersion = CgtVersion.V5_0; break; default: throw new FileLoadException(string.Format("The file format version {0} is not unsupported", headerMatch.Groups["version"].Value)); } while (context.HasMoreData()) { CgtRecordType recordType = context.ReadNextRecord(); /// Trace.WriteLine(recordType, "Reading record"); switch (recordType) { case CgtRecordType.Parameters: ReadHeader(context); break; case CgtRecordType.Property: ReadProperty(context); break; case CgtRecordType.Groups: ReadGroup(context); break; case CgtRecordType.TableCountsEnhanced: ReadTableCounts(context, true); break; case CgtRecordType.TableCounts: ReadTableCounts(context, false); break; case CgtRecordType.Initial: ReadInitialStates(context); break; case CgtRecordType.Symbols: ReadSymbol(context); break; case CgtRecordType.Charsets: ReadCharset(context); break; case CgtRecordType.PackedCharsets: if (fileVersion == CgtVersion.V1_0) { ReadPackedCharset(context); } else { ReadRangeCharset(context); } break; case CgtRecordType.Rules: ReadRule(context); break; case CgtRecordType.DfaStates: ReadDfaState(context); break; case CgtRecordType.LRStates: ReadLRState(context); break; default: throw new FileLoadException("Invalid record type"); } } dfaInitialState = dfaStateTable[context.DfaInitialStateIndex]; startSymbol = symbolTable[context.StartSymbolIndex]; lalrInitialState = lalrStateTable[context.LrInitialState]; FixupGroups(context); }
public LalrActionShift(int index, Symbol symbol, LalrState state) : base(index, symbol, state) { }