private static void ComputeLRState(LRStateBuild State) { short num2; SymbolBuild build2; short num3 = (short)(BuilderApp.BuildTables.Symbol.Count() - 1); for (num2 = 0; num2 <= num3; num2 = (short)(num2 + 1)) { GotoList[num2] = null; } short num4 = (short)(State.ConfigSet.Count() - 1); for (num2 = 0; num2 <= num4; num2 = (short)(num2 + 1)) { LRConfig config = State.ConfigSet[num2]; build2 = config.NextSymbol(0); if (build2 != null) { short tableIndex = build2.TableIndex; if (GotoList[tableIndex] == null) { GotoList[tableIndex] = new LRConfigSet(); } LRConfig item = new LRConfig(config.Parent, config.Position + 1, config.LookaheadSet); GotoList[tableIndex].Add(item); } } short num5 = (short)(BuilderApp.BuildTables.Symbol.Count() - 1); for (num2 = 0; num2 <= num5; num2 = (short)(num2 + 1)) { if (GotoList[num2] == null) { continue; } build2 = BuilderApp.BuildTables.Symbol[num2]; Closure(GotoList[num2]); LRStateBuild state = new LRStateBuild { ConfigSet = GotoList[num2] }; switch (build2.Type) { case SymbolType.Nonterminal: { State.Add(new LRAction(build2, LRActionType.Goto, CreateLRState(state))); Notify.Analyzed++; continue; } case SymbolType.End: { State.Add(new LRAction(build2, LRActionType.Accept)); continue; } } State.Add(new LRAction(build2, LRActionType.Shift, CreateLRState(state))); Notify.Analyzed++; } }
private static void RecomputeLRState(LRStateBuild State) { short num2 = (short)(State.Count - 1); for (short i = 0; i <= num2; i = (short)(i + 1)) { LRAction action = State[i]; switch (((int)action.Type())) { case 1: case 3: { Symbol symbol = action.Symbol; SymbolBuild theSymbol = (SymbolBuild)symbol; symbol = theSymbol; LRStateBuild build = GotoSymbol(State, theSymbol); LRStateBuild build2 = BuilderApp.BuildTables.LALR[action.Value()]; if (build.ConfigSet.CompareCore(build2.ConfigSet) == LRConfigCompare.EqualCore) { build2.ConfigSet.UnionWith(build.ConfigSet); build2.Modified = true; } Notify.Analyzed++; break; } } } }
private static short CreateLRState(LRStateBuild State) { LRConfigCompare unEqual; short tableIndex = (short)LRConfigSetLookup.get_TableIndex(State.ConfigSet); if (tableIndex != -1) { unEqual = State.ConfigSet.CompareCore(BuilderApp.BuildTables.LALR[tableIndex].ConfigSet); } else { unEqual = LRConfigCompare.UnEqual; } switch (((int)unEqual)) { case 0: case 1: return(tableIndex); case 2: { LRStateBuild build2 = BuilderApp.BuildTables.LALR[tableIndex]; build2.ConfigSet.UnionWith(State.ConfigSet); build2.Modified = true; build2 = null; return(tableIndex); } case 3: { LRStateBuild build = State; build.Expanded = false; build.Modified = true; build = null; tableIndex = (short)BuilderApp.BuildTables.LALR.Add(State); LRConfigSetLookup.Add(State.ConfigSet, tableIndex); Notify.Counter++; return(tableIndex); } } return(tableIndex); }
private static LRStateBuild CreateInitialState(Symbol StartSymbol) { ProductionBuild rule = new ProductionBuild(); SymbolBuild nonTerminal = new SymbolBuild { Type = SymbolType.Nonterminal, Name = "S'" }; rule.SetHead(nonTerminal); rule.Handle().Add((SymbolBuild)StartSymbol); rule.Handle().Add((SymbolBuild)BuilderApp.BuildTables.Symbol.GetFirstOfType(SymbolType.End)); LRConfig item = new LRConfig(rule); LRStateBuild build3 = new LRStateBuild(); build3.ConfigSet.Add(item); build3.Expanded = false; Closure(build3.ConfigSet); return(build3); }
private static LRStateBuild GotoSymbol(LRStateBuild State, SymbolBuild TheSymbol) { LRStateBuild build2 = new LRStateBuild(); short num2 = (short)(State.ConfigSet.Count() - 1); for (short i = 0; i <= num2; i = (short)(i + 1)) { LRConfig config = State.ConfigSet[i]; Symbol symbol = config.NextSymbol(0); if ((symbol != null) && symbol.IsEqualTo(TheSymbol)) { LRConfig item = new LRConfig(config.Parent, config.Position + 1, config.LookaheadSet); build2.ConfigSet.Add(item); } } if (build2.ConfigSet.Count() >= 1) { Closure(build2.ConfigSet); } return(build2); }
private static void StateNumber(LRStateBuild State, short Number, LRConfigCompare Status) { LRConfigCompare compare; short num = -1; for (short i = 0; (i < BuilderApp.BuildTables.LALR.Count) & (num == -1); i = (short)(i + 1)) { compare = State.ConfigSet.CompareCore(BuilderApp.BuildTables.LALR[i].ConfigSet); if (compare != LRConfigCompare.UnEqual) { num = i; } } Number = num; if (num == -1) { Status = LRConfigCompare.UnEqual; } else { Status = compare; } }
private static StateTableInfoType GetStateInfo(LRStateBuild State) { StateTableInfoType type2; type2.Index = -1; type2.Compare = LRConfigCompare.UnEqual; short num = 0; while ((num < BuilderApp.BuildTables.LALR.Count) & (type2.Index == -1)) { if (State.ConfigSet.EqualCore(BuilderApp.BuildTables.LALR[num].ConfigSet)) { LRConfigCompare compare = State.ConfigSet.CompareCore(BuilderApp.BuildTables.LALR[num].ConfigSet); type2.Index = num; type2.Compare = compare; } else { num = (short)(num + 1); } } return(type2); }
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)); } } } }