Пример #1
0
        //construct an Production with grammar rule
        // the place should start with 0 on default
        //lhandle should be '#' on default
        public Production(string rule, int initplace = 0, int nexttok = -1)
        {
            mrule = rule;
            List <int> toks = new List <int>();

            string[] lr = rule.Split(' ');
            for (int i = 0; i < lr.Length; ++i)
            {
                //reserved for SDT
                if (lr[i] == "|")
                {
                    break;
                }
                if (i == 0)
                {
                    lhandle = Token.getID(lr[i]);
                    continue;
                }
                if (i == 1)
                {
                    continue;
                }

                int tokid = Token.getID(lr[i]);
                if (tokid != -1)
                {
                    toks.Add(tokid);
                }
            }
            tokens       = toks.ToArray();
            place        = initplace;
            this.nexttok = nexttok;
        }
Пример #2
0
        public static Closure gotoClosure(Closure I, Token X)
        {
            Closure J = new Closure();

            foreach (Production Production in I.entities)
            {
                if (Production.GetNext() == Token.getID(X))
                {
                    J.entities.Add(Production.MoveForward());
                }
            }
            J.genClosure();
            return(J);
        }