コード例 #1
0
        internal EGT(BinaryReader Reader)
        {
            EGTReader EGT     = new EGTReader(Reader);
            EGTRecord RecType = default(EGTRecord);

            try
            {
                while (!EGT.EndOfFile())
                {
                    EGT.GetNextRecord();

                    RecType = (EGTRecord)EGT.RetrieveByte();

                    switch (RecType)
                    {
                    case EGTRecord.Property:
                    {
                        //Index, Name, Value
                        int    Index = 0;
                        string Name  = null;

                        Index = EGT.RetrieveInt16();
                        Name  = EGT.RetrieveString();
                        //Just discard
                        m_Grammar.SetValue(Index, EGT.RetrieveString());
                    }
                    break;

                    case EGTRecord.TableCounts:
                        //Symbol, CharacterSet, Rule, DFA, LALR
                        m_SymbolTable     = new SymbolList(EGT.RetrieveInt16());
                        m_CharSetTable    = new CharacterSetList(EGT.RetrieveInt16());
                        m_ProductionTable = new ProductionList(EGT.RetrieveInt16());
                        m_DFA             = new FAStateList(EGT.RetrieveInt16());
                        m_LRStates        = new LRStateList(EGT.RetrieveInt16());
                        m_GroupTable      = new GroupList(EGT.RetrieveInt16());

                        break;

                    case EGTRecord.InitialStates:
                        //DFA, LALR
                        m_DFA.InitialState      = EGT.RetrieveInt16();
                        m_LRStates.InitialState = EGT.RetrieveInt16();

                        break;

                    case EGTRecord.Symbol:
                    {
                        //#, Name, Kind
                        short      Index = 0;
                        string     Name  = null;
                        SymbolType Type  = default(SymbolType);

                        Index = EGT.RetrieveInt16();
                        Name  = EGT.RetrieveString();
                        Type  = (SymbolType)EGT.RetrieveInt16();

                        m_SymbolTable[Index] = new Symbol(Name, Type, Index);
                    }
                    break;

                    case EGTRecord.Group:
                        //#, Name, Container#, Start#, End#, Tokenized, Open Ended, Reserved, Count, (Nested Group #...)
                    {
                        Group G = new Group();

                        G.TableIndex = EGT.RetrieveInt16();
                        //#

                        G.Name      = EGT.RetrieveString();
                        G.Container = m_SymbolTable[EGT.RetrieveInt16()];
                        G.Start     = m_SymbolTable[EGT.RetrieveInt16()];
                        G.End       = m_SymbolTable[EGT.RetrieveInt16()];

                        G.Advance = (Group.AdvanceMode)EGT.RetrieveInt16();
                        G.Ending  = (Group.EndingMode)EGT.RetrieveInt16();
                        EGT.RetrieveEntry();
                        //Reserved

                        int Count = EGT.RetrieveInt16();
                        for (int n = 1; n <= Count; n++)
                        {
                            G.Nesting.Add(EGT.RetrieveInt16());
                        }

                        //=== Link back
                        m_GroupStart.Add(G.Start, G);
                        m_GroupTable[G.TableIndex] = G;
                    }
                    break;

                    case EGTRecord.CharRanges:
                        //#, Total Sets, RESERVED, (Start#, End#  ...)
                    {
                        int Index = 0;
                        int Total = 0;

                        Index = EGT.RetrieveInt16();
                        EGT.RetrieveInt16();
                        //Codepage
                        Total = EGT.RetrieveInt16();
                        EGT.RetrieveEntry();
                        //Reserved

                        m_CharSetTable[Index] = new CharacterSet();
                        while (!(EGT.RecordComplete()))
                        {
                            m_CharSetTable[Index].Add(new CharacterRange(EGT.RetrieveUInt16(), EGT.RetrieveUInt16()));
                        }
                    }
                    break;

                    case EGTRecord.Production:
                        //#, ID#, Reserved, (Symbol#,  ...)
                    {
                        short Index     = 0;
                        int   HeadIndex = 0;
                        int   SymIndex  = 0;

                        Index     = EGT.RetrieveInt16();
                        HeadIndex = EGT.RetrieveInt16();
                        EGT.RetrieveEntry();
                        //Reserved

                        List <Symbol> symbols = new List <Symbol>();
                        while (!(EGT.RecordComplete()))
                        {
                            SymIndex = EGT.RetrieveInt16();
                            //m_ProductionTable[Index].Handle().Add(m_SymbolTable[SymIndex]);
                            symbols.Add(m_SymbolTable[SymIndex]);
                        }
                        SymbolList symbolList = new SymbolList(symbols);
                        m_ProductionTable[Index] = new Production(m_SymbolTable[HeadIndex], Index, symbolList);
                    }
                    break;

                    case EGTRecord.DFAState:
                        //#, Accept?, Accept#, Reserved (CharSet#, Target#, Reserved)...
                    {
                        int   Index       = 0;
                        bool  Accept      = false;
                        int   AcceptIndex = 0;
                        int   SetIndex    = 0;
                        short Target      = 0;

                        Index       = EGT.RetrieveInt16();
                        Accept      = EGT.RetrieveBoolean();
                        AcceptIndex = EGT.RetrieveInt16();
                        EGT.RetrieveEntry();
                        //Reserved

                        if (Accept)
                        {
                            m_DFA[Index] = new FAState(m_SymbolTable[AcceptIndex]);
                        }
                        else
                        {
                            m_DFA[Index] = new FAState();
                        }

                        //(Edge chars, Target#, Reserved)...
                        while (!(EGT.RecordComplete()))
                        {
                            SetIndex = EGT.RetrieveInt16();
                            //Char table index
                            Target = EGT.RetrieveInt16();
                            //Target
                            EGT.RetrieveEntry();
                            //Reserved

                            m_DFA[Index].Edges.Add(new FAEdge(m_CharSetTable[SetIndex], Target));
                        }
                    }
                    break;

                    case EGTRecord.LRState:
                        //#, Reserved (Symbol#, Action, Target#, Reserved)...
                    {
                        int          Index    = 0;
                        int          SymIndex = 0;
                        LRActionType Action   = 0;
                        short        Target   = 0;

                        Index = EGT.RetrieveInt16();
                        EGT.RetrieveEntry();
                        //Reserved

                        m_LRStates[Index] = new LRState();

                        //(Symbol#, Action, Target#, Reserved)...
                        while (!EGT.RecordComplete())
                        {
                            SymIndex = EGT.RetrieveInt16();
                            Action   = (LRActionType)EGT.RetrieveInt16();
                            Target   = EGT.RetrieveInt16();
                            EGT.RetrieveEntry();
                            //Reserved

                            m_LRStates[Index].Add(new LRAction(m_SymbolTable[SymIndex], Action, Target));
                        }
                    }
                    break;

                    default:
                        //RecordIDComment
                        throw new ParserException("File Error. A record of type '" + (char)RecType + "' was read. This is not a valid code.");
                    }
                }
            }
            catch (Exception ex)
            {
                throw new ParserException(ex.Message, ex, "LoadTables");
            }
        }
コード例 #2
0
 public FAEdge(CharacterSet CharSet, short Target)
 {
     this.Characters = CharSet;
     this.Target     = Target;
 }