IEnumerable <Production> EliminateNullables(Nonterminal v, HashSet <Nonterminal> nullables)
        {
            /*foreach (var p in this.productionMap[v])
             * {
             *  if (p.Rhs.Length == 0)
             *      yield break;
             *
             *  foreach (var symbols in EnumerateNullableFreeVariations(ConsList<GrammarSymbol>.Create(p.Rhs), nullables))
             *      if (symbols != null) //ignore the case when all nullables were replaced
             *          yield return new Production(v, symbols.ToArray());
             * }*/
            var res = new Dictionary <string, Production>();

            foreach (var p in this.productionMap[v])
            {
                if (p.Rhs.Length == 0)
                {
                    continue;
                }

                foreach (var symbols in EnumerateNullableFreeVariations(ConsList <GrammarSymbol> .Create(p.Rhs), nullables))
                {
                    if (symbols != null)
                    {//ignore the case when all nullables were replaced
                        var newProd = new Production(v, symbols.ToArray());
                        res[newProd.Description] = newProd;
                    }
                }
            }
            return(res.Values);
        }
Esempio n. 2
0
        public override STModel Convert(iterexpr ie, Symtab stab)
        {
            VarInfo I = new VarInfo(stb, stab, ie, charsort);

            var iterCases = ConsList <itercase> .Create(ie.GetNormalCases());

            var endCases = ConsList <itercase> .Create(ie.GetEndCases());

            BranchingRule <Expr> rule  = CreateBranchingRule(iterCases, stb.Solver.True, I);
            BranchingRule <Expr> frule = CreateBranchingRule(endCases, stb.Solver.True, I);

            STModel st = new STModel(stb.Solver, "iterSTb", charsort, charsort, I.regSort, I.initReg, 0);

            st.AssignRule(0, rule);
            st.AssignFinalRule(0, frule);
            return(st);
        }
Esempio n. 3
0
        IEnumerable <Production> EliminateNullables(Nonterminal v, HashSet <Nonterminal> nullables)
        {
            foreach (var p in this.productionMap[v])
            {
                if (p.Rhs.Length == 0)
                {
                    yield break;
                }

                foreach (var symbols in EnumerateNullableFreeVariations(ConsList <GrammarSymbol> .Create(p.Rhs), nullables))
                {
                    if (symbols != null) //ignore the case when all nullables were replaced
                    {
                        yield return(new Production(v, symbols.ToArray()));
                    }
                }
            }
        }