public Grammar(Grammar g) { _nonterminals = new List<Nonterminal>(g.Nonterminals); _terminals = new List<Terminal>(g.Terminals); _rules = new List<Rule>(g.Rules); _distinguishedSymbol = new Nonterminal(g.DistinguishedSymbol); _vanishingSymbols = new List<Nonterminal>(g.VanishingSymbols); }
private State _state; // текущее состояние #endregion Fields #region Constructors public DescendingBacktrackAnalyzer(Grammar g) : base(g) { _state = State.NORMAL; _position = 0; _currentString = new Stack<Symbol>(); _history = new Stack<HistoryItem>(); _orderedAlternatives = new Dictionary<string, List<Alternative>>(); _inputString = new List<Symbol>(); _altIdx = 0; _noMoreConfigurations = false; _configurationHistory = new StringBuilder(); }
public override Grammar read(string fname) { Grammar g = new Grammar(); StreamReader sr = new StreamReader(fname); string line; // читаем нетерминалы List<string> nonTerms = readBlock(sr); nonTerms.ForEach(s => g.Nonterminals.Add(new Nonterminal(s))); // читаем терминалы List<string> terms = readBlock(sr); terms.ForEach(s => g.Terminals.Add(new Terminal(s))); // читаем правила List<string> rules = readBlock(sr); g.Rules = parseRules(rules, terms, nonTerms); // читаем аксиому string axiom = readAxiom(sr); if (!nonTerms.Contains(axiom)) throw new FormatException("Некорректный формат файла."); g.DistinguishedSymbol = new Nonterminal(axiom); sr.Close(); g.findVanishingSymbols(); return g; }
public void loadGrammar(string fileName) { TextGrammarReader reader = new TextGrammarReader(); _grammar = reader.read(fileName); }
public Analyzer(Grammar g) { _grammar = g; }