ConvertToStates() public method

public ConvertToStates ( Node p, Symbol sym ) : void
p Node
sym Symbol
return void
示例#1
0
        void TokenDecl(int typ)
        {
            string name; int kind; Symbol sym; Graph g;

            Sym(out name, out kind);
            sym = tab.FindSym(name);
            if (sym != null)
            {
                SemErr("name declared twice");
            }
            else
            {
                sym           = tab.NewSym(typ, name, t.line);
                sym.tokenKind = Symbol.fixedToken;
            }
            tokenString = null;

            while (!(StartOf(5)))
            {
                SynErr(43); Get();
            }
            if (la.kind == 17)
            {
                Get();
                TokenExpr(out g);
                Expect(18);
                if (kind == str)
                {
                    SemErr("a literal must not be declared with a structure");
                }
                tab.Finish(g);
                if (tokenString == null || tokenString.Equals(noString))
                {
                    dfa.ConvertToStates(g.l, sym);
                }
                else           // TokenExpr is a single string
                {
                    if (tab.literals[tokenString] != null)
                    {
                        SemErr("token string declared twice");
                    }
                    tab.literals[tokenString] = sym;
                    dfa.MatchLiteral(tokenString, sym);
                }
            }
            else if (StartOf(6))
            {
                if (kind == id)
                {
                    genScanner = false;
                }
                else
                {
                    dfa.MatchLiteral(sym.name, sym);
                }
            }
            else
            {
                SynErr(44);
            }
            if (la.kind == 39)
            {
                SemText(out sym.semPos);
                if (typ != Node.pr)
                {
                    SemErr("semantic action not allowed here");
                }
            }
        }
示例#2
0
        static void TokenDecl(int typ)
        {
            string name; int kind; Symbol sym; Graph g;

            Sym(out name, out kind);
            sym = Symbol.Find(name);
            if (sym != null)
            {
                SemErr("name declared twice");
            }
            else
            {
                sym           = new Symbol(typ, name, t.line);
                sym.tokenKind = Symbol.classToken;
            }

            while (!(StartOf(13)))
            {
                SynErr(46); Get();
            }
            if (la.kind == 8)
            {
                Get();
                TokenExpr(out g);
                Expect(9);
                if (kind != id)
                {
                    SemErr("a literal must not be declared with a structure");
                }
                Graph.Finish(g);
                DFA.ConvertToStates(g.l, sym);
            }
            else if (la.kind == 9)
            {
                Get();
                if (typ != Node.rslv)
                {
                    SemErr("resolver is only allowed in RESOLVERS section");
                }
            }
            else if (StartOf(14))
            {
                if (kind == id)
                {
                    genScanner = false;
                }
                else
                {
                    DFA.MatchLiteral(sym);
                }
            }
            else
            {
                SynErr(47);
            }
            if (la.kind == 38)
            {
                SemText(out sym.semPos);
                if (typ == Node.t)
                {
                    SemErr("semantic action not allowed here");
                }
            }
            else if (StartOf(15))
            {
                if (typ == Node.rslv)
                {
                    SemErr("resolvers must have a semantic action");
                }
            }
            else
            {
                SynErr(48);
            }
        }