Exemplo n.º 1
0
 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();
        }
Exemplo n.º 3
0
 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;
 }
Exemplo n.º 4
0
 public void loadGrammar(string fileName)
 {
     TextGrammarReader reader = new TextGrammarReader();
     _grammar = reader.read(fileName);
 }
Exemplo n.º 5
0
 public Analyzer(Grammar g)
 {
     _grammar = g;
 }