private void LoadTables(GrammarReader reader) { Object obj; Int16 index; while (reader.MoveNext()) { byte id = (byte)reader.RetrieveNext(); switch ((RecordId)id) { case RecordId.Parameters: m_parameters["Name"] = (String)reader.RetrieveNext(); m_parameters["Version"] = (String)reader.RetrieveNext(); m_parameters["Author"] = (String)reader.RetrieveNext(); m_parameters["About"] = (String)reader.RetrieveNext(); m_caseSensitive = (Boolean)reader.RetrieveNext(); m_startSymbol = (Int16)reader.RetrieveNext(); break; case RecordId.TableCounts: m_symbols = new Symbol[(Int16)reader.RetrieveNext()]; m_charsets = new String[(Int16)reader.RetrieveNext()]; m_rules = new Rule[(Int16)reader.RetrieveNext()]; m_DfaStates = new FAState[(Int16)reader.RetrieveNext()]; m_LalrTables = new LRActionTable[(Int16)reader.RetrieveNext()]; m_initialized = true; break; case RecordId.Initial: m_initDfaState = (Int16)reader.RetrieveNext(); m_initLalrState = (Int16)reader.RetrieveNext(); break; case RecordId.Symbols: index = (Int16)reader.RetrieveNext(); String name = (String)reader.RetrieveNext(); SymbolType kind = (SymbolType)(Int16)reader.RetrieveNext(); Symbol symbol = new Symbol(index, name, kind); AddSymbol(symbol); break; case RecordId.CharSets: index = (Int16)reader.RetrieveNext(); String charset = (String)reader.RetrieveNext(); AddCharset(index, charset); break; case RecordId.Rules: index = (Int16)reader.RetrieveNext(); Symbol head = m_symbols[(Int16)reader.RetrieveNext()]; Rule rule = new Rule(index, head); reader.RetrieveNext(); // reserved while ((obj = reader.RetrieveNext()) != null) { rule.AddItem(m_symbols[(Int16)obj]); } AddRule(rule); break; case RecordId.DFAStates: FAState fastate = new FAState(); index = (Int16)reader.RetrieveNext(); if ((bool)reader.RetrieveNext()) { fastate.AcceptSymbol = (Int16)reader.RetrieveNext(); } else { reader.RetrieveNext(); } reader.RetrieveNext(); // reserverd while (!reader.RetrieveDone()) { Int16 ci = (Int16)reader.RetrieveNext(); Int16 ti = (Int16)reader.RetrieveNext(); reader.RetrieveNext(); // reserved fastate.AddEdge(m_charsets[ci], ti); } AddDfaState(index, fastate); break; case RecordId.LRTables: LRActionTable table = new LRActionTable(); index = (Int16)reader.RetrieveNext(); reader.RetrieveNext(); // reserverd while (!reader.RetrieveDone()) { Int16 sid = (Int16)reader.RetrieveNext(); Int16 action = (Int16)reader.RetrieveNext(); Int16 tid = (Int16)reader.RetrieveNext(); reader.RetrieveNext(); // reserved table.AddItem(m_symbols[sid], (Action)action, tid); } AddLalrTable(index, table); break; case RecordId.Comment: Console.WriteLine("Comment record encountered"); break; default: throw new ParserException("Wrong id for record"); } } }
private void LoadTables(GrammarReader reader) { Object obj; Int16 index; while (reader.MoveNext()) { byte id = (byte)reader.RetrieveNext(); switch ((RecordId)id) { case RecordId.Parameters: m_parameters["Name"] = (String)reader.RetrieveNext(); m_parameters["Version"] = (String)reader.RetrieveNext(); m_parameters["Author"] = (String)reader.RetrieveNext(); m_parameters["About"] = (String)reader.RetrieveNext(); m_caseSensitive = (Boolean)reader.RetrieveNext(); m_startSymbol = (Int16)reader.RetrieveNext(); break; case RecordId.TableCounts: m_symbols = new Symbol[(Int16)reader.RetrieveNext()]; m_charsets = new String[(Int16)reader.RetrieveNext()]; m_rules = new Rule[(Int16)reader.RetrieveNext()]; m_DfaStates = new FAState[(Int16)reader.RetrieveNext()]; m_LalrTables = new LRActionTable[(Int16)reader.RetrieveNext()]; m_initialized = true; break; case RecordId.Initial: m_initDfaState = (Int16)reader.RetrieveNext(); m_initLalrState = (Int16)reader.RetrieveNext(); break; case RecordId.Symbols: index = (Int16)reader.RetrieveNext(); String name = (String)reader.RetrieveNext(); SymbolType kind = (SymbolType)(Int16)reader.RetrieveNext(); Symbol symbol = new Symbol(index, name, kind); AddSymbol(symbol); break; case RecordId.CharSets: index = (Int16)reader.RetrieveNext(); String charset = (String)reader.RetrieveNext(); AddCharset(index, charset); break; case RecordId.Rules: index = (Int16)reader.RetrieveNext(); Symbol head = m_symbols[(Int16)reader.RetrieveNext()]; Rule rule = new Rule(index, head); reader.RetrieveNext(); // reserved while ((obj = reader.RetrieveNext()) != null) rule.AddItem(m_symbols[(Int16)obj]); AddRule(rule); break; case RecordId.DFAStates: FAState fastate = new FAState(); index = (Int16)reader.RetrieveNext(); if ((bool)reader.RetrieveNext()) fastate.AcceptSymbol = (Int16)reader.RetrieveNext(); else reader.RetrieveNext(); reader.RetrieveNext(); // reserverd while (! reader.RetrieveDone()) { Int16 ci = (Int16)reader.RetrieveNext(); Int16 ti = (Int16)reader.RetrieveNext(); reader.RetrieveNext(); // reserved fastate.AddEdge(m_charsets[ci], ti); } AddDfaState(index, fastate); break; case RecordId.LRTables: LRActionTable table = new LRActionTable(); index = (Int16)reader.RetrieveNext(); reader.RetrieveNext(); // reserverd while (! reader.RetrieveDone()) { Int16 sid = (Int16)reader.RetrieveNext(); Int16 action = (Int16)reader.RetrieveNext(); Int16 tid = (Int16)reader.RetrieveNext(); reader.RetrieveNext(); // reserved table.AddItem(m_symbols[sid], (Action)action, tid); } AddLalrTable(index, table); break; case RecordId.Comment: Console.WriteLine("Comment record encountered"); break; default: throw new ParserException("Wrong id for record"); } } }