Exemplo n.º 1
0
        public ActionTable(Dfa <SYMBOL_ENUM, TREE_NODE> dfa,
                           Productions <SYMBOL_ENUM, TREE_NODE> productions,
                           int lookaheadWidth)
            : base(null, null, null,
                   productions.StartSymbol,
                   productions.EofSymbol,
                   productions.SyntaxErrorSymbol,
                   lookaheadWidth)
        {
            this.symbolsRep = productions.SymbolsRep;
            this.symbols    = productions.NonAndTerminals.ToList();

            int symbolValuesWidth = 1 + productions.NonAndTerminals.Concat(productions.EofSymbol).Select(it => (int)(object)it).Max();

            actionsTable = new IEnumerable <ParseAction <SYMBOL_ENUM, TREE_NODE> > [
                dfa.IndexRange(),
                (int)Math.Pow(symbolValuesWidth, lookaheadWidth)
                           ];

            edgesTable = CreateEdgesTable(dfa.IndexRange(), symbolValuesWidth);

            recoveryTable = new IEnumerable <NfaCell <SYMBOL_ENUM, TREE_NODE> > [dfa.IndexRange(), symbolValuesWidth];

            foreach (Node <SYMBOL_ENUM, TREE_NODE> node in dfa.Nodes)
            {
                foreach (KeyValuePair <SYMBOL_ENUM, Node <SYMBOL_ENUM, TREE_NODE> > edge in node.EdgesTo)
                {
                    int edge_int = (int)(object)edge.Key;

                    edgesTable[node.State.Index, edge_int] = edge.Value.State.Index;

                    IEnumerable <NfaCell <SYMBOL_ENUM, TREE_NODE> > recovery_items =
                        edge.Value.State.ParsingActiveItems.Where(it => it.IsAtRecoveryPoint).Select(it => it.CreateCell()).ToList();
                    if (recovery_items.Any())
                    {
                        recoveryTable[node.State.Index, edge_int] = recovery_items;
                    }
                }
            }
        }