Exemplo n.º 1
0
            protected override ProductionBase <int> OnDefineGrammar()
            {
                var T = new Production <int>();

                ProductionBase <int> Num = from n in NUMBER select ParseInt32AnyWay(n);

                ProductionBase <int> U =
                    Num |
                    from lp in LEFT_PARENTHESIS
                    from exp in T
                    from rp in RIGHT_PARENTHESIS
                    select exp;

                var F = new Production <int>();

                F.Rule =
                    U |
                    from f in F
                    from op in ASTERISK
                    from u in U
                    select f * u;

                T.Rule =
                    F |
                    from t in T
                    from op in PLUS
                    from f in F
                    select t + f;

                ProductionBase <int> E = from t in T
                                         from eos in Grammar.Eos()
                                         select t;

                return(E);
            }
Exemplo n.º 2
0
        private ProductionBase <int> SetUpParser()
        {
            ProductionBase <int> T = null;

            ProductionBase <int> Num = from n in NUMBER.AsTerminal() select Int32.Parse(n);

            ProductionBase <int> U = Grammar.Union(
                Num,
                from lp in LEFT_PARENTHESIS.AsTerminal()
                from exp in T
                from rp in RIGHT_PARENTHESIS.AsTerminal()
                select exp
                );

            ProductionBase <IEnumerable <int> > F1 = null;

            F1 = Grammar.Union(
                from op in ASTERISK.AsTerminal()
                from u in U
                from f1 in F1
                select new[] { u }.Concat(f1),
                Grammar.Empty(Enumerable.Empty <int>())
                );

            ProductionBase <int> F =
                from u in U
                from f1 in F1
                select f1.Aggregate(u, (a, i) => a *i);

            ProductionBase <IEnumerable <int> > T1 = null;

            T1 = Grammar.Union(
                from op in PLUS.AsTerminal()
                from f in F
                from t1 in T1
                select new[] { f }.Concat(t1),
                Grammar.Empty(Enumerable.Empty <int>())
                );

            T =
                from f in F
                from t1 in T1
                select t1.Aggregate(f, (a, i) => a + i);

            ProductionBase <int> E = from t in T
                                     from eos in Grammar.Eos()
                                     select t;

            return(E);
        }
Exemplo n.º 3
0
 public AlternationProduction(ProductionBase <T> p1, ProductionBase <T> p2)
 {
     m_p1 = p1;
     m_p2 = p2;
 }
Exemplo n.º 4
0
        internal bool AddEdge(IProduction symbol, LR0State targetState)
        {
            ProductionBase production = symbol as ProductionBase;

            return(m_edges.Add(new LR0Edge(Index, production.Info.Index, targetState.Index)));
        }