/// <summary>
        /// Gets the paged productions.
        /// </summary>
        /// <returns>IPagedList&lt;Production&gt;.</returns>
        public IPagedList <Production> GetPagedProductions()
        {
            Int32 pageNumber = 1;
            Int32 pageSize   = 2;

            // If PageNumber is set, set pageNumber to it
            if (PageNumber > 0)
            {
                pageNumber = PageNumber;
            }

            // If PageSize is set, set pageSize to it
            if (PageSize > 0)
            {
                pageSize = PageSize;
            }

            // Generated a paged list with appropriate page size and number
            if (ProductionList != null && ProductionList.Where(x => x != null).Count() > 0)
            {
                var Return = ProductionList.ToPagedList(pageNumber, pageSize);
                return(Return);
            }
            return(null);
        }
Beispiel #2
0
 public ImproptuDeclContext(Productions.SymbolTable symbols,
                            Productions.TypeTable typeTable)
 {
     this.symbols   = symbols;
     this.typeTable = typeTable;
     Productions    = new ProductionList();
 }
Beispiel #3
0
 public void CopyTo(ProductionList prods)
 {
     foreach (var prod in Productions)
     {
         prods.Add(prod);
     }
 }
 /// <summary>
 /// 显示列表
 /// </summary>
 public void ShowProductionTable()
 {
     foreach (var model in GetProductionList())
     {
         ProductionList.Add(model);
     }
     ShowProductionList();
 }
Beispiel #5
0
 public static ProductionList<string> P(this string wordList)
 {
     var fields = wordList.Split(',');
     ProductionList<string> list = new ProductionList<string>();
     foreach (var field in fields)
         list.Add(new WordTerminal(field.Trim().ToLowerInvariant()));
     return list;
 }
Beispiel #6
0
        public IActionResult ProductionList(string SearchTerm)
        {
            ProductionList model = new ProductionList();

            model.Productions = productionOperation.GetAllProduction(SearchTerm);

            return(View(model));
        }
        private ProductionList GetProductionList(SearchObject input)
        {
            ProductionList result = new ProductionList();

            try
            {
                Expression <Func <Production, object> >[] exp = new Expression <Func <Production, object> >[] { x => x.ProductionInventoryItems, x => x.ProductionProducts };
                var predicate = PredicateBuilder.True <Production>();
                predicate = predicate.And(x => !x.IsDeleted);

                if (input.ProductIds != null && input.ProductIds.Count > 0)
                {
                    predicate = predicate.And(x => input.ProductIds.Contains(x.Id));
                }
                else
                {
                    if (input.FromDate != null)
                    {
                        predicate = predicate.And(x => x.Date.Date >= input.FromDate.Date);
                    }

                    if (input.ToDate != null)
                    {
                        predicate = predicate.And(x => x.Date.Date <= input.ToDate.Date);
                    }
                }

                result.Productions = _baseOpp.GetAllUsingExpression(out int totalCount, 1, 0, predicate, null, null, exp).OrderByDescending(x => x.Date).ToList();

                //nullifying to avoid object chain

                if (result.Productions != null)
                {
                    result.Productions.ForEach(x =>
                    {
                        if (x.ProductionInventoryItems != null)
                        {
                            x.ProductionInventoryItems.ForEach(y => {
                                y.Production    = null;
                                y.InventoryItem = _inventoryItemOpp.GetUsingId(y.FK_InventoryItemId);
                            });
                        }

                        if (x.ProductionProducts != null)
                        {
                            x.ProductionProducts.ForEach(y => {
                                y.Production = null;
                                y.Product    = _productOpp.GetUsingId(y.FK_ProductId);
                            });
                        }
                    });
                }
            }
            catch (Exception ex)
            {
            }
            return(result);
        }
 private bool ContainsProduction(ProductionList productions, NonTerminal nonTerminal)
 {
     foreach (Production prod in productions)
     {
         if (prod.LValue == nonTerminal)
         {
             return(true);
         }
     }
     return(false);
 }
 private void addItem(ProductionList item, int prefers)
 {
     pLSorted.Add(new ProductionListCalculateOrder(item.Quantity, item.Article, Index, getStationGroupByArticle(item.Article), prefers));
     Index++;
 }
        private void calculateOrder(ProductionList item, int prefers)
        {
            Boolean check = false;

            switch (item.Article)
            {
            case 7:
            case 13:
            case 18:
            case 4:
            case 10:
            case 16:
            case 17:
            case 26:
            case 8:
            case 14:
            case 19:
            case 5:
            case 11:
            case 9:
            case 15:
            case 20:
            case 6:
            case 12:
                addItem(item, prefers);
                break;

            case 49:
                if (!checkPLSortedListForArticle(7) && StorageService.Instance.GetAmountFromWareHouseStockId(7) < item.Quantity * 1)
                {
                    calculateOrder(StorageService.Instance.GetProductionItem(7), 1);
                    check = true;
                }
                if (!checkPLSortedListForArticle(13) && StorageService.Instance.GetAmountFromWareHouseStockId(13) < item.Quantity * 1)
                {
                    calculateOrder(StorageService.Instance.GetProductionItem(13), 1);
                    check = true;
                }
                if (!checkPLSortedListForArticle(18) && StorageService.Instance.GetAmountFromWareHouseStockId(18) < item.Quantity * 1)
                {
                    calculateOrder(StorageService.Instance.GetProductionItem(18), 1);
                    check = true;
                }
                if (check && prefers != 1)
                {
                    addItem(item, 3);
                }
                else
                {
                    addItem(item, prefers);
                }
                break;

            case 50:
                if (!checkPLSortedListForArticle(4) && StorageService.Instance.GetAmountFromWareHouseStockId(4) < item.Quantity * 1)
                {
                    calculateOrder(StorageService.Instance.GetProductionItem(4), 1);
                    check = true;
                }
                if (!checkPLSortedListForArticle(10) && StorageService.Instance.GetAmountFromWareHouseStockId(10) < item.Quantity * 1)
                {
                    calculateOrder(StorageService.Instance.GetProductionItem(10), 1);
                    check = true;
                }
                if (!checkPLSortedListForArticle(49) && StorageService.Instance.GetAmountFromWareHouseStockId(49) < item.Quantity * 1)
                {
                    calculateOrder(StorageService.Instance.GetProductionItem(49), 1);
                    check = true;
                }
                if (check && prefers != 1)
                {
                    addItem(item, 3);
                }
                else
                {
                    addItem(item, prefers);
                }
                break;

            case 51:
                if (!checkPLSortedListForArticle(16) && StorageService.Instance.GetAmountFromWareHouseStockId(16) < item.Quantity * 1)
                {
                    calculateOrder(StorageService.Instance.GetProductionItem(16), 1);
                    check = true;
                }
                if (!checkPLSortedListForArticle(17) && StorageService.Instance.GetAmountFromWareHouseStockId(17) < item.Quantity * 1)
                {
                    calculateOrder(StorageService.Instance.GetProductionItem(17), 1);
                    check = true;
                }
                if (!checkPLSortedListForArticle(50) && StorageService.Instance.GetAmountFromWareHouseStockId(50) < item.Quantity * 1)
                {
                    calculateOrder(StorageService.Instance.GetProductionItem(50), 1);
                    check = true;
                }
                if (check && prefers != 1)
                {
                    addItem(item, 3);
                }
                else
                {
                    addItem(item, prefers);
                }
                break;

            case 1:
                if (!checkPLSortedListForArticle(26) && StorageService.Instance.GetAmountFromWareHouseStockId(26) < item.Quantity * 1)
                {
                    calculateOrder(StorageService.Instance.GetProductionItem(26), 1);
                    check = true;
                }
                if (!checkPLSortedListForArticle(51) && StorageService.Instance.GetAmountFromWareHouseStockId(51) < item.Quantity * 1)
                {
                    calculateOrder(StorageService.Instance.GetProductionItem(51), 1);
                    check = true;
                }
                if (check && prefers != 1)
                {
                    addItem(item, 3);
                }
                else
                {
                    addItem(item, prefers);
                }
                break;

            case 54:
                if (!checkPLSortedListForArticle(8) && StorageService.Instance.GetAmountFromWareHouseStockId(8) < item.Quantity * 1)
                {
                    calculateOrder(StorageService.Instance.GetProductionItem(8), 1);
                    check = true;
                }
                if (!checkPLSortedListForArticle(14) && StorageService.Instance.GetAmountFromWareHouseStockId(14) < item.Quantity * 1)
                {
                    calculateOrder(StorageService.Instance.GetProductionItem(14), 1);
                    check = true;
                }
                if (!checkPLSortedListForArticle(19) && StorageService.Instance.GetAmountFromWareHouseStockId(19) < item.Quantity * 1)
                {
                    calculateOrder(StorageService.Instance.GetProductionItem(19), 1);
                    check = true;
                }
                if (check && prefers != 1)
                {
                    addItem(item, 3);
                }
                else
                {
                    addItem(item, prefers);
                }
                break;

            case 55:
                if (!checkPLSortedListForArticle(5) && StorageService.Instance.GetAmountFromWareHouseStockId(5) < item.Quantity * 1)
                {
                    calculateOrder(StorageService.Instance.GetProductionItem(5), 1);
                    check = true;
                }
                if (!checkPLSortedListForArticle(11) && StorageService.Instance.GetAmountFromWareHouseStockId(11) < item.Quantity * 1)
                {
                    calculateOrder(StorageService.Instance.GetProductionItem(11), 1);
                    check = true;
                }
                if (!checkPLSortedListForArticle(54) && StorageService.Instance.GetAmountFromWareHouseStockId(54) < item.Quantity * 1)
                {
                    calculateOrder(StorageService.Instance.GetProductionItem(54), 1);
                    check = true;
                }
                if (check && prefers != 1)
                {
                    addItem(item, 3);
                }
                else
                {
                    addItem(item, prefers);
                }
                break;

            case 56:
                if (!checkPLSortedListForArticle(16) && StorageService.Instance.GetAmountFromWareHouseStockId(16) < item.Quantity * 1)
                {
                    calculateOrder(StorageService.Instance.GetProductionItem(16), 1);
                    check = true;
                }
                if (!checkPLSortedListForArticle(17) && StorageService.Instance.GetAmountFromWareHouseStockId(17) < item.Quantity * 1)
                {
                    calculateOrder(StorageService.Instance.GetProductionItem(17), 1);
                    check = true;
                }
                if (!checkPLSortedListForArticle(55) && StorageService.Instance.GetAmountFromWareHouseStockId(55) < item.Quantity * 1)
                {
                    calculateOrder(StorageService.Instance.GetProductionItem(55), 1);
                    check = true;
                }
                if (check && prefers != 1)
                {
                    addItem(item, 3);
                }
                else
                {
                    addItem(item, prefers);
                }
                break;

            case 2:
                if (!checkPLSortedListForArticle(26) && StorageService.Instance.GetAmountFromWareHouseStockId(26) < item.Quantity * 1)
                {
                    calculateOrder(StorageService.Instance.GetProductionItem(26), 1);
                    check = true;
                }
                if (!checkPLSortedListForArticle(56) && StorageService.Instance.GetAmountFromWareHouseStockId(56) < item.Quantity * 1)
                {
                    calculateOrder(StorageService.Instance.GetProductionItem(56), 1);
                    check = true;
                }
                if (check && prefers != 1)
                {
                    addItem(item, 3);
                }
                else
                {
                    addItem(item, prefers);
                }
                break;

            case 29:
                if (!checkPLSortedListForArticle(9) && StorageService.Instance.GetAmountFromWareHouseStockId(9) < item.Quantity * 1)
                {
                    calculateOrder(StorageService.Instance.GetProductionItem(9), 1);
                    check = true;
                }
                if (!checkPLSortedListForArticle(15) && StorageService.Instance.GetAmountFromWareHouseStockId(15) < item.Quantity * 1)
                {
                    calculateOrder(StorageService.Instance.GetProductionItem(15), 1);
                    check = true;
                }
                if (!checkPLSortedListForArticle(20) && StorageService.Instance.GetAmountFromWareHouseStockId(20) < item.Quantity * 1)
                {
                    calculateOrder(StorageService.Instance.GetProductionItem(20), 1);
                    check = true;
                }
                if (check && prefers != 1)
                {
                    addItem(item, 3);
                }
                else
                {
                    addItem(item, prefers);
                }
                break;

            case 30:
                if (!checkPLSortedListForArticle(6) && StorageService.Instance.GetAmountFromWareHouseStockId(6) < item.Quantity * 1)
                {
                    calculateOrder(StorageService.Instance.GetProductionItem(6), 1);
                    check = true;
                }
                if (!checkPLSortedListForArticle(12) && StorageService.Instance.GetAmountFromWareHouseStockId(12) < item.Quantity * 1)
                {
                    calculateOrder(StorageService.Instance.GetProductionItem(12), 1);
                    check = true;
                }
                if (!checkPLSortedListForArticle(29) && StorageService.Instance.GetAmountFromWareHouseStockId(29) < item.Quantity * 1)
                {
                    calculateOrder(StorageService.Instance.GetProductionItem(29), 1);
                    check = true;
                }
                if (check && prefers != 1)
                {
                    addItem(item, 3);
                }
                else
                {
                    addItem(item, prefers);
                }
                break;

            case 31:
                if (!checkPLSortedListForArticle(16) && StorageService.Instance.GetAmountFromWareHouseStockId(16) < item.Quantity * 1)
                {
                    calculateOrder(StorageService.Instance.GetProductionItem(16), 1);
                    check = true;
                }
                if (!checkPLSortedListForArticle(17) && StorageService.Instance.GetAmountFromWareHouseStockId(17) < item.Quantity * 1)
                {
                    calculateOrder(StorageService.Instance.GetProductionItem(17), 1);
                    check = true;
                }
                if (!checkPLSortedListForArticle(30) && StorageService.Instance.GetAmountFromWareHouseStockId(30) < item.Quantity * 1)
                {
                    calculateOrder(StorageService.Instance.GetProductionItem(30), 1);
                    check = true;
                }
                if (check && prefers != 1)
                {
                    addItem(item, 3);
                }
                else
                {
                    addItem(item, prefers);
                }
                break;

            case 3:
                if (!checkPLSortedListForArticle(26) && StorageService.Instance.GetAmountFromWareHouseStockId(26) < item.Quantity * 1)
                {
                    calculateOrder(StorageService.Instance.GetProductionItem(26), 1);
                    check = true;
                }
                if (!checkPLSortedListForArticle(31) && StorageService.Instance.GetAmountFromWareHouseStockId(31) < item.Quantity * 1)
                {
                    calculateOrder(StorageService.Instance.GetProductionItem(31), 1);
                    check = true;
                }
                if (check && prefers != 1)
                {
                    addItem(item, 3);
                }
                else
                {
                    addItem(item, prefers);
                }
                break;
            }
        }
Beispiel #11
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");
            }
        }
Beispiel #12
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");
            }
        }
Beispiel #13
0
        public bool Compile()
        {
            var fileName = Path.GetFileName(inPath);
            var fileDir  = Path.GetDirectoryName(fileName);

            parser = Parser.FromString(args.InputContents);
            parser.SetOptions(options);
            args.LogMessage(Importance.Normal, "Parsing {0}", fileName);
            var isOk = parser.Parse();

            if (!isOk)
            {
                return(isOk);
            }

            var lang = parser.Language;

            if (lang == null)
            {
                return(false);
            }
            prods = lang.Productions;

            var nfa = parser.Graph;

            if (!prods.SetStates(args, parser.Graph.Machine.AcceptingStates))
            {
                return(false);
            }

            if (options.TryGetValue("nfa", out var nfaPath))
            {
                if (string.IsNullOrEmpty(nfaPath))
                {
                    nfaPath = Path.ChangeExtension(inPath, ".nfa.txt");
                }
                File.WriteAllText(nfaPath, nfa.ToString());
            }

            args.LogMessage(Importance.Normal, "Building dfa");
            dfa = nfa.ToDfa();

            scannerWriter = (!options.TryGetValue("scanner", out var scannerValue) ||
                             scannerValue.Equals("state", StringComparison.InvariantCultureIgnoreCase)) ?
                            new DfaStateWriter(dfa) as IGeneratable :
                            new DfaSwitchWriter(dfa);


            args.LogMessage(Importance.Normal, "Building LR1");
            var grammar     = new LR1.Grammar(lang.Productions);
            var grammarPath = Path.ChangeExtension(inPath, ".grammar.txt");
            var grammarText = grammar.ToString();

            File.WriteAllText(grammarPath, grammarText);

            lr1Parser = new LR1.LR1Parser(args, grammar);

            var statesPath = Path.ChangeExtension(inPath, ".states.txt");

            File.WriteAllText(statesPath, lr1Parser.States.ToString());


            using (var csharp = new Generator(args.Output))
            {
                if (!string.IsNullOrEmpty(args.DefaultNamespace))
                {
                    lang.Namespace = new ParseTree.Identifier(args.DefaultNamespace);
                }

                var frameSpecified = false;
                if (options.TryGetValue("frame", out var frameFile) && !string.IsNullOrEmpty(frameFile))
                {
                    frameSpecified = File.Exists(frameFile);
                    if (!frameSpecified)
                    {
                        frameFile      = Path.Combine(fileDir, frameFile);
                        frameSpecified = File.Exists(frameFile);
                        if (!frameSpecified)
                        {
                            args.LogWarning("Unable to find frame file {0}", frameFile);
                        }
                    }
                }
                if (frameSpecified)
                {
                    args.LogMessage(Importance.Normal, "Using frame file {0}", frameFile);
                    //args.LogMessage(Importance.Normal, "Writing output {0}", OutPath);
                    TemplateProcessor.FromFile(csharp, this, frameFile);
                }
                else
                {
                    args.LogMessage(Importance.Normal, "Using internal frame file");
                    //args.LogMessage(Importance.Normal, "Writing output {0}", OutPath);
                    TemplateProcessor.FromAssembly(csharp, this, "Opal.FrameFiles.Parser.txt");
                }
            }

            return(isOk);
        }
 public JsonResult Update(ProductionList productionList)
 {
     return(Json(productionListDB.Insert(productionList), JsonRequestBehavior.AllowGet));
 }