public PlainTextParser(string buildString) { BuildString = buildString; PowerSets = new UniqueList <string>(); CharacterInfo = new RawCharacterInfo(); BuilderApp = new BuilderApp(); }
static void Main(string[] args) { #region Pattern de Criação Console.WriteLine("########### PATTERNS DE CRIAÇÃO #############"); Console.WriteLine(""); SingletonApp.Executar(); FactoryMethodApp.Executar(); BuilderApp.Executar(); PrototypeApp.Executar(); #endregion #region Pattern Estrutural Console.WriteLine("########### PATTERNS ESTRUTURAL #############"); Console.WriteLine(""); AdapterApp.Executar(); #endregion #region Pattern Comportamental Console.WriteLine("########### PATTERNS COMPORTAMENTAL #########"); Console.WriteLine(""); #endregion Console.ReadKey(); }
internal static void AddUsedSetName(string Name, int Line) { int num = UsedSetNames.ItemIndex(Name); if (!BuilderApp.IsPredefinedSet(Name) & (num == -1)) { UsedSetNames.Add(new GrammarIdentifier(Name, Line)); } }
internal static void AddUserSet(GrammarSet CharSet) { if (BuilderApp.IsPredefinedSet(CharSet.Name)) { BuilderApp.Log.Add(SysLogSection.Grammar, SysLogAlert.Critical, "Predined Set", "The set {" + CharSet.Name + "} is a set built into GOLD.", Conversions.ToString(CharSet.Line)); } else if (UserSets.ItemIndex(CharSet.Name) != -1) { BuilderApp.Log.Add(SysLogSection.Grammar, SysLogAlert.Warning, "Set redefined", "The set {" + CharSet.Name + "} was redefined", Conversions.ToString(CharSet.Line)); } else if (BuilderApp.UserDefinedSets.ItemIndex(CharSet.Name) == -1) { UserSets.Add(CharSet); } else { BuilderApp.Log.Add(SysLogSection.Grammar, SysLogAlert.Critical, "Duplicate set definition", "The set '" + CharSet.Name + "' was previously defined.", Conversions.ToString(CharSet.Line)); } }
public CharacterSetBuild Evaluate() { switch (this.m_Type) { case SetType.Chars: return(this.m_Characters); case SetType.Name: { CharacterSetBuild characterSet = (CharacterSetBuild)BuilderApp.GetCharacterSet(this.m_Text); if (characterSet != null) { return(new CharacterSetBuild(characterSet)); } BuilderApp.Log.Add(SysLogSection.Grammar, SysLogAlert.Critical, "Character set is not defined", "The character set {" + this.m_Text + "} was not defined in the grammar.", ""); return(new CharacterSetBuild()); } } return(new CharacterSetBuild()); }
private static AutomataType CreateAutomataItem(RegExpItem Item) { AutomataType type; int head; int num3; int num4; int tail; if (Item.Data is RegExp) { RegExpItem item2 = Item; RegExp data = (RegExp)item2.Data; item2.Data = data; AutomataType type3 = CreateSubAutomata(data); head = type3.Head; tail = type3.Tail; num3 = head; num4 = tail; } else if (!(Item.Data is SetItem)) { BuilderApp.Log.Add(SysLogSection.Grammar, SysLogAlert.Critical, "Invalid internal token at CreateAutomataItem(): " + Versioned.TypeName(RuntimeHelpers.GetObjectValue(Item.Data))); } else { CharacterSetBuild characters; SetItem item = (SetItem)Item.Data; switch (item.Type) { case SetItem.SetType.Chars: characters = (CharacterSetBuild)item.Characters; head = AddState(); tail = AddState(); NFA[head].AddEdge(characters, tail); num3 = head; num4 = tail; break; case SetItem.SetType.Name: characters = (CharacterSetBuild)BuilderApp.GetCharacterSet(item.Text); if (characters == null) { BuilderApp.Log.Add(SysLogSection.Grammar, SysLogAlert.Critical, "Unknown user-defined set: {" + item.Text + "}"); break; } tail = AddState(); head = AddState(); NFA[head].AddEdge(characters, tail); num3 = head; num4 = tail; break; case SetItem.SetType.Sequence: { int num6; head = AddState(); tail = head; string text = item.Text; short num7 = (short)(text.Length - 1); for (short i = 0; i <= num7; i = (short)(i + 1)) { num6 = tail; tail = AddState(); NFA[num6].AddEdge(new CharacterSetBuild(Conversions.ToString(text[i])), tail); } num3 = num6; num4 = tail; break; } default: BuilderApp.Log.Add(SysLogSection.Grammar, SysLogAlert.Critical, "Invalid internal token at CreateAutomataItem(): " + Versioned.TypeName(RuntimeHelpers.GetObjectValue(Item.Data))); break; } } if ((num3 == 0) | (num4 == 0)) { Debug.WriteLine("ERROR: BAD KLEENE DATA"); } switch (Item.Kleene) { case "*": NFA[num3].AddLambdaEdge(num4); NFA[num4].AddLambdaEdge(num3); break; case "+": NFA[num4].AddLambdaEdge(num3); break; case "?": NFA[num3].AddLambdaEdge(num4); break; } type.Head = (short)head; type.Tail = (short)tail; return(type); }
public static void Build() { short num3; NumberSet nFAList = new NumberSet(new int[0]); NumberSet set2 = new NumberSet(new int[0]); Notify.Started("Computing DFA States"); SetupForNFA(); BuilderApp.Mode = BuilderApp.ProgramMode.BuildingNFA; short num5 = (short)(BuilderApp.BuildTables.Symbol.Count() - 1); for (num3 = 0; num3 <= num5; num3 = (short)(num3 + 1)) { SymbolBuild sym = BuilderApp.BuildTables.Symbol[num3]; if (sym.UsesDFA) { Notify.Text = sym.Name; CreateNFAStates(sym); } } BuilderApp.Mode = BuilderApp.ProgramMode.NFAClosure; short num6 = (short)(NFA.Count - 1); for (num3 = 0; num3 <= num6; num3 = (short)(num3 + 1)) { NumberSet reachable = new NumberSet(new int[0]); reachable.Add(new int[] { num3 }); ClosureNFA(reachable); NFA[num3].NFAClosure = reachable; } BuilderApp.BuildTables.CharSet.Clear(); if (NFA.Count <= 1) { BuilderApp.Log.Add(SysLogSection.DFA, SysLogAlert.Critical, "There are no terminals in the grammar"); } else { short num2; BuilderApp.Log.Add(SysLogSection.DFA, SysLogAlert.Detail, "The initial Nondeterministic Finite Automata has " + Conversions.ToString(NFA.Count) + " states"); BuilderApp.BuildTables.DFA.Clear(); BuilderApp.Mode = BuilderApp.ProgramMode.NFACase; SetupMapCaseCharTables(BuilderApp.BuildTables.Properties["Case Sensitive"].Value.ToUpper() == "TRUE", BuilderApp.GetParamCharMapping()); BuilderApp.Mode = BuilderApp.ProgramMode.BuildingDFA; nFAList.Add(new int[] { Root }); StartState = BuildDFAState(nFAList); short num7 = (short)(BuilderApp.BuildTables.DFA.Count - 1); for (num3 = 0; num3 <= num7; num3 = (short)(num3 + 1)) { short num8 = (short)(BuilderApp.BuildTables.DFA[num3].Edges().Count() - 1); num2 = 0; while (num2 <= num8) { FAEdgeBuild build3 = BuilderApp.BuildTables.DFA[num3].Edges()[num2]; CharacterSetBuild characters = build3.Characters; build3.Characters = characters; short num4 = BuilderApp.AddCharacterSet(characters); BuilderApp.BuildTables.DFA[num3].Edges()[num2].Characters = BuilderApp.BuildTables.CharSet[num4]; num2 = (short)(num2 + 1); } } short num9 = (short)(BuilderApp.BuildTables.DFA.Count - 1); for (num3 = 0; num3 <= num9; num3 = (short)(num3 + 1)) { FAStateBuild build = BuilderApp.BuildTables.DFA[num3]; if (build.AcceptList.Count() == 0) { build.Accept = null; } else if (build.AcceptList.Count() == 1) { build.Accept = BuilderApp.BuildTables.Symbol[build.AcceptList[0].SymbolIndex]; } else { FAAccept accept = build.AcceptList[0]; set2.Clear(); set2.Add(new int[] { accept.SymbolIndex }); short priority = accept.Priority; short num10 = (short)(build.AcceptList.Count() - 1); num2 = 1; while (num2 <= num10) { accept = build.AcceptList[num2]; if (accept.Priority == priority) { set2.Add(new int[] { accept.SymbolIndex }); } else if (accept.Priority < priority) { set2.Clear(); set2.Add(new int[] { accept.SymbolIndex }); priority = accept.Priority; } num2 = (short)(num2 + 1); } build.AcceptList.Clear(); short num11 = (short)(set2.Count() - 1); for (num2 = 0; num2 <= num11; num2 = (short)(num2 + 1)) { build.AcceptList.Add((short)set2[num2], priority); } if (set2.Count() == 1) { build.Accept = BuilderApp.BuildTables.Symbol[set2[0]]; } } } CheckErrorsDFA(); Notify.Completed("DFA States Completed"); } }
public static void Main() { bool flag = true; BuilderApp.FatalLoadError = false; Setup(); Notify.OutputProgress = m_Verbose; BuilderApp.Setup(); if (BuilderApp.FatalLoadError) { BuilderApp.Log.Add(SysLogSection.System, SysLogAlert.Critical, "There was a fatal internal error."); flag = false; } if (m_GrammarFile == "") { BuilderApp.Log.Add(SysLogSection.CommandLine, SysLogAlert.Critical, "You must specify a grammar file."); flag = false; } else if (!LoadGrammar()) { BuilderApp.Log.Add(SysLogSection.CommandLine, SysLogAlert.Critical, "The grammar file could not be loaded."); flag = false; } if (flag) { TextReader metaGrammar = new StringReader(m_Grammar); BuilderApp.EnterGrammar(metaGrammar); if (BuilderApp.LoggedCriticalError()) { flag = false; } } if (flag) { BuilderApp.ComputeLALR(); if (BuilderApp.LoggedCriticalError()) { flag = false; } } if (flag) { BuilderApp.ComputeDFA(); if (BuilderApp.LoggedCriticalError()) { flag = false; } } if (flag) { BuilderApp.ComputeComplete(); } if (flag) { BuilderApp.Log.Add(SysLogSection.System, SysLogAlert.Success, "The grammar was successfully analyzed and the table file was created."); string str = FileUtility.GetExtension(m_TableFile).ToLower(); if (str == "xml") { if (m_Version == 1) { BuilderApp.BuildTables.SaveXML1(m_TableFile); } else { BuilderApp.BuildTables.SaveXML5(m_TableFile); } } else if (str == "cgt") { BuilderApp.BuildTables.SaveVer1(m_TableFile); } else { BuilderApp.BuildTables.SaveVer5(m_TableFile); } } BuilderApp.SaveLog(m_LogFile); if (m_Verbose) { int num2 = BuilderApp.Log.Count() - 1; for (int i = 0; i <= num2; i++) { SysLogItem item = BuilderApp.Log[i]; if ((item.Alert == SysLogAlert.Critical) | (item.Alert == SysLogAlert.Warning)) { Console.WriteLine(item.AlertName().ToUpper() + " : " + item.SectionName() + " : " + item.Title + " : " + item.Description); } item = null; } Console.WriteLine("Done"); } }