public override bool Equals(object obj)
    {
        if (obj == null)
        {
            return(false);
        }
        if (obj is not ProductionInLR0)
        {
            return(false);
        }
        ProductionInLR0 production = obj as ProductionInLR0;

        return(base.Equals(production) && production.PointPos == pointPos);
    }
Beispiel #2
0
    protected List <ProductionInLR0> goTo <T>(List <ProductionInLR0> productions, string translation) where T : ProductionInLR0
    {
        List <ProductionInLR0> generatedList = new List <ProductionInLR0>();

        foreach (ProductionInLR0 production in productions)
        {
            string nextToken = production.NextTokenOfPoint;
            if (nextToken != null && nextToken == translation)
            {
                ProductionInLR0 newProduction = Activator.CreateInstance(typeof(T), new object[] { production }) as T;
                // 点符号前进
                newProduction.pointForward();
                generatedList.Add(newProduction);
            }
        }
        return(closure(generatedList));
    }
Beispiel #3
0
    protected override void setAcceptOrReduce(string row, ProductionInLR0 production)
    {
        bool hasStartSymbol = production.Key == inputGrammer.nonTerminalTokens[0];

        // 防止将acc覆盖
        table.Add(hasStartSymbol ?
                  new Item(row, PublicFunc.ENDSYMBOL, PublicFunc.ACCOMPLISH) :
                  new Item(row, PublicFunc.ENDSYMBOL, "r" + Convert.ToString(inputGrammer.userProductions.IndexOf(production))));
        foreach (string token in inputGrammer.terminalTokens.Where(i => i != PublicFunc.EPSILON))
        {
            Item item = new Item(row, token, "r" + Convert.ToString(inputGrammer.userProductions.IndexOf(production)));
            checkConflict(item);
            if (!table.Contains(item))
            {
                table.Add(item);
            }
        }
    }
Beispiel #4
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;
        }

        foreach (string token in generatedFollow[production.Key])
        {
            Item item = new Item(row, token, "r" + Convert.ToString(inputGrammer.userProductions.IndexOf(production)));
            checkConflict(item);
            if (!table.Contains(item))
            {
                table.Add(item);
            }
        }
    }
Beispiel #5
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++)
        {
            List <string> nextTokens = getNextTokens(generatedList);
            foreach (string token in nextTokens.Where(ii => (inputGrammer.nonTerminalTokens.Contains(ii))))
            {
                foreach (Production production in inputGrammer[token])
                {
                    ProductionInLR0 newProduction = new ProductionInLR0(production);
                    if (!generatedList.Contains(newProduction))
                    {
                        generatedList.Add(newProduction);
                    }
                }
            }
        }
        return(generatedList);
    }
 public ProductionInLR0(ProductionInLR0 production) : base(production.Key, production.Values)
 {
     this.pointPos = production.PointPos;
 }
Beispiel #7
0
 abstract protected void setAcceptOrReduce(string row, ProductionInLR0 production);