示例#1
0
    protected override List <ProductionInLR0> closure(List <ProductionInLR0> productions)
    {
        List <ProductionInLR0> generatedList = new List <ProductionInLR0>();

        generatedList.AddRange(productions);

        for (int i = 0; i < generatedList.Count; i++)
        {
            ProductionInLR1 oldProduction = generatedList[i] as ProductionInLR1;
            string          token         = generatedList[i].NextTokenOfPoint;
            if (token != null && inputGrammer.nonTerminalTokens.Contains(token))
            {
                foreach (Production production in inputGrammer[token])
                {
                    ProductionInLR1 newProduction = new ProductionInLR1(production, generatedFirst.getFirstFromPart(oldProduction.Values, oldProduction.PointPos + 1, oldProduction.searchTokens));
                    // 检查项集内是否有同心项(或者完全相同),有则不添加
                    bool noNeedToAdd = false;
                    foreach (ProductionInLR1 production1 in generatedList)
                    {
                        if (production1.hasSameCoreWith(newProduction))
                        {
                            noNeedToAdd = true;
                            production1.searchTokens = production1.searchTokens.Union(newProduction.searchTokens).ToList();
                        }
                    }
                    if (!noNeedToAdd)
                    {
                        generatedList.Add(newProduction);
                    }
                }
            }
        }
        return(generatedList);
    }
示例#2
0
    public override bool Equals(object obj)
    {
        if (obj == null)
        {
            return(false);
        }
        if (obj is not ProductionInLR1)
        {
            return(false);
        }

        ProductionInLR1 production = obj as ProductionInLR1;

        return
            (base.Equals(obj) &&
             searchTokens.Except(production.searchTokens).Count() == 0 &&
             production.searchTokens.Except(searchTokens).Count() == 0);
    }
示例#3
0
    protected override void setAcceptOrReduce(string row, ProductionInLR0 production)
    {
        if (production.Key == inputGrammer.nonTerminalTokens[0])
        {
            table.Add(new Item(row, PublicFunc.ENDSYMBOL, PublicFunc.ACCOMPLISH));
            return;
        }

        ProductionInLR1 newProduction = production as ProductionInLR1;

        foreach (string token in newProduction.searchTokens)
        {
            Item item = new Item(row, token, "r" + Convert.ToString(inputGrammer.userProductions.IndexOf(newProduction)));
            checkConflict(item);
            if (!table.Contains(item))
            {
                table.Add(item);
            }
        }
    }
示例#4
0
 public ProductionInLR1(ProductionInLR1 production) : base(production)
 {
     searchTokens = new List <string>();
     searchTokens.AddRange(production.searchTokens);
 }