Пример #1
0
        public List <ISymbol>[,] ProcessTable()
        {
            Preprocessor preprocessor = new Preprocessor(_grammarRules);

            foreach (ISymbol symbolsValue in _grammarRules.SymbolList)
            {
                if (symbolsValue is Variable variable)
                {
                    var variableNumber = MapperToNumber.Map(variable);
                    foreach (IEnumerable <ISymbol> variableDefinition in variable.RuleSet.Definitions)
                    {
                        var firsts = preprocessor.FirstSet(new List <IEnumerable <ISymbol> >()
                        {
                            variableDefinition
                        });

                        foreach (Terminal terminal in firsts.Where(term => !term.Equals(Terminal.Epsilon)))
                        {
                            table[variableNumber, MapperToNumber.Map(terminal)] = variableDefinition.ToList();
                        }

                        if (firsts.Contains(Terminal.Epsilon))
                        {
                            var followTerminals = variable.Follows;
                            foreach (Terminal terminal in followTerminals)
                            {
                                var tableItem = table[variableNumber, MapperToNumber.Map(terminal)];
                                if (tableItem == null)
                                {
                                    table[variableNumber, MapperToNumber.Map(terminal)] = new List <ISymbol> {
                                        Terminal.Epsilon,
                                    }
                                }
 public LeftToRight_RightMost_Zero(GrammarRules grammarRules, LRType lrType, Preprocessor preprocessor)
 {
     _grammarRules      = grammarRules;
     _lrType            = lrType;
     _preprocessor      = preprocessor;
     MapperToNumber     = new MapperToNumber(_grammarRules);
     FiniteStateMachine = new FiniteStateMachine(_grammarRules, _preprocessor, lrType == LRType.ClR_One);
     Nodes = new Stack <TreeNode>();
 }
Пример #3
0
 public LeftToRight_LookAhead_One(GrammarRules grammarRules, IProgress <ParseReportModel> progress)
 {
     treeNodes = new Stack <TreeNode>();
     BaseNode  = new TreeNode(grammarRules.HeadVariable, _orderId);
     treeNodes.Push(BaseNode);
     _grammarRules  = grammarRules;
     _progress      = progress;
     MapperToNumber = new MapperToNumber(_grammarRules);
 }
Пример #4
0
 public void Init()
 {
     MapperToNumber.Initialize();
     table = new List <ISymbol> [MapperToNumber.VariableCount, MapperToNumber.TerminalCount];
 }