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); }
public bool analyze(String s, Analyzer analyzer) { if (analyzer is DescentRecursiveAnalyzer) _grammar = analyzer.getGrammar(); List<Symbol> symbolInput = _grammar.verifyString(s); bool result = analyzer.analyzeSymbolString(symbolInput); _history = analyzer.getHistory(); return result; }
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 DescentRecursiveAnalyzer() { _grammar = new Grammar { Nonterminals = new List<Nonterminal> { new Nonterminal("S"), new Nonterminal("A"), new Nonterminal("B") }, Terminals = new List<Terminal> { new Terminal("true"), new Terminal("false"), new Terminal("&"), new Terminal("!"), new Terminal("~"), new Terminal("a") }, Rules = new List<Rule> { new Rule { Left = new Nonterminal("S"), Right = new List<Symbol>{ new Terminal("true"), new Nonterminal("A") } }, // R1 new Rule { Left = new Nonterminal("S"), Right = new List<Symbol>{ new Terminal("false"), new Nonterminal("A") } }, // R2 new Rule { Left = new Nonterminal("S"), Right = new List<Symbol>{ new Terminal("a"), new Nonterminal("A") } }, // R3 new Rule { Left = new Nonterminal("S"), Right = new List<Symbol>{ new Terminal("~"), new Nonterminal("B") } }, // R4 new Rule { Left = new Nonterminal("A"), Right = new List<Symbol>{ new Terminal("&"), new Nonterminal("S") } }, // R5 new Rule { Left = new Nonterminal("A"), Right = new List<Symbol>{ new Terminal("!"), new Nonterminal("S") } }, // R6 new Rule { Left = new Nonterminal("A"), Right = new List<Symbol>{ new EmptySymbol()} }, // R7 new Rule { Left = new Nonterminal("B"), Right = new List<Symbol>{new Terminal("true"), new Nonterminal("A") } }, // R8 new Rule { Left = new Nonterminal("B"), Right = new List<Symbol>{new Terminal("false"), new Nonterminal("A") } }, // R9 new Rule { Left = new Nonterminal("B"), Right = new List<Symbol>{new Terminal("a"), new Nonterminal("A") } } // R10 }, DistinguishedSymbol = new Nonterminal("S") }; _history = new StringBuilder(); }
public void setGrammar(Grammar g) { _grammar = new Grammar(g); }
public void loadGrammar(string fileName) { TextGrammarReader reader = new TextGrammarReader(); _grammar = reader.read(fileName); }
public Analyzer(Grammar g) { _grammar = g; }