コード例 #1
0
        private static void ComputeReductions()
        {
            LRConflictItem[] itemArray = new LRConflictItem[BuilderApp.BuildTables.Symbol.Count() + 1];
            short            num4      = (short)(BuilderApp.BuildTables.LALR.Count - 1);

            for (short i = 0; i <= num4; i = (short)(i + 1))
            {
                LRConflict   shiftReduce;
                LRStateBuild build = BuilderApp.BuildTables.LALR[i];
                short        num5  = (short)(BuilderApp.BuildTables.Symbol.Count() - 1);
                short        index = 0;
                while (index <= num5)
                {
                    itemArray[index] = new LRConflictItem(BuilderApp.BuildTables.Symbol[index]);
                    index            = (short)(index + 1);
                }
                short num6 = (short)(build.ConfigSet.Count() - 1);
                short num2 = 0;
                while (num2 <= num6)
                {
                    short    num7;
                    LRConfig item = build.ConfigSet[num2];
                    switch (((int)item.NextAction()))
                    {
                    case 1:
                        itemArray[item.NextSymbol(0).TableIndex].Shifts.Add(item);
                        goto Label_0137;

                    case 2:
                        num7  = (short)(item.LookaheadSet.Count() - 1);
                        index = 0;
                        goto Label_012D;

                    default:
                        goto Label_0137;
                    }
Label_0100:
                    itemArray[item.LookaheadSet[index].Parent.TableIndex].Reduces.Add(item);
                    index = (short)(index + 1);
Label_012D:
                    if (index <= num7)
                    {
                        goto Label_0100;
                    }
Label_0137:
                    num2 = (short)(num2 + 1);
                }
                short num8 = (short)(BuilderApp.BuildTables.Symbol.Count() - 1);
                index = 0;
                while (index <= num8)
                {
                    if ((itemArray[index].Shifts.Count() >= 1) & (itemArray[index].Reduces.Count() >= 1))
                    {
                        short num9 = (short)(itemArray[index].Shifts.Count() - 1);
                        num2 = 0;
                        while (num2 <= num9)
                        {
                            itemArray[index].Shifts[num2].Status = LRStatus.Warning;
                            num2 = (short)(num2 + 1);
                        }
                        short num10 = (short)(itemArray[index].Reduces.Count() - 1);
                        num2 = 0;
                        while (num2 <= num10)
                        {
                            itemArray[index].Reduces[num2].Status = LRStatus.Warning;
                            num2 = (short)(num2 + 1);
                        }
                        build.Status = LRStatus.Warning;
                        build.Note   = "Shift-Reduce Conflict";
                        build.ConflictList.Add(new LRConflictItem(itemArray[index], LRConflict.ShiftReduce));
                        shiftReduce = LRConflict.ShiftReduce;
                        BuilderApp.Log.Add(SysLogSection.LALR, SysLogAlert.Warning, "A Shift-Reduce Conflict was fixed", BuilderApp.BuildTables.Symbol[index].Text(false) + " can follow a completed rule and also be shifted." + GetConflictResolvedDesc(shiftReduce), Conversions.ToString((int)i));
                    }
                    index = (short)(index + 1);
                }
                short num11 = (short)(BuilderApp.BuildTables.Symbol.Count() - 1);
                for (index = 0; index <= num11; index = (short)(index + 1))
                {
                    if ((itemArray[index].Reduces.Count() == 1) & (itemArray[index].Shifts.Count() == 0))
                    {
                        SymbolBuild theSymbol = BuilderApp.BuildTables.Symbol[index];
                        build.Add(new LRAction(theSymbol, LRActionType.Reduce, itemArray[index].Reduces[0].Parent.TableIndex));
                    }
                    else if (itemArray[index].Reduces.Count() > 1)
                    {
                        short num12 = (short)(itemArray[index].Reduces.Count() - 1);
                        for (num2 = 0; num2 <= num12; num2 = (short)(num2 + 1))
                        {
                            itemArray[index].Reduces[num2].Status = LRStatus.Critical;
                        }
                        build.Status = LRStatus.Critical;
                        build.Note   = "Reduce-Reduce Conflict";
                        build.ConflictList.Add(new LRConflictItem(itemArray[index], LRConflict.ReduceReduce));
                        shiftReduce = LRConflict.ReduceReduce;
                        BuilderApp.Log.Add(SysLogSection.LALR, SysLogAlert.Critical, "Reduce-Reduce Conflict", BuilderApp.BuildTables.Symbol[index].Text(false) + " can follow more than one completed rule. " + GetConflictDesc(shiftReduce), Conversions.ToString((int)i));
                    }
                }
            }
        }
コード例 #2
0
 internal int Add(LRConflictItem item)
 {
     return(base.Add(item));
 }