def TokenDecl(self, typ):
        s = self.Sym()
        name, kind = s
        sym = Symbol.Find(name)
        if sym is not None:
            self.SemErr("name declared twice")
        else:
            sym = Symbol(typ, name, self.token.line)
            sym.tokenKind = Symbol.fixedToken
        self.tokenString = None
        while not (self.StartOf(4)):
            self.SynErr(52)
            self.Get()
        if self.la.kind == Scanner.equal_Sym:
            self.Get()
            g = self.TokenExpr()
            self.Expect(Scanner.point_Sym)
            if kind == self.str:
                self.SemErr("a literal must not be declared with a structure")
            Graph.Finish(g)
            if (self.tokenString is None) or (self.tokenString
                                              == self.noString):
                DFA.ConvertToStates(g.l, sym)
            else:  # TokenExpr is a single string
                if Tab.literals.get(self.tokenString) is not None:
                    self.SemErr("token string declared twice")
                Tab.literals[self.tokenString] = sym
                DFA.MatchLiteral(self.tokenString, sym)

        elif self.StartOf(5):
            if kind == self.id:
                genScanner = False
            else:
                DFA.MatchLiteral(sym.name, sym)
        else:
            self.SynErr(53)
        if (self.la.kind == Scanner.lparenpoint_Sym):
            sym.semPos = self.SemText()
            if typ != Node.pr:
                self.SemErr("semantic action not allowed here")
    def Coco(self):
        g = Graph()
        g1 = Graph()
        g2 = Graph()
        s = set()
        if (self.la.kind == Scanner.from_Sym
                or self.la.kind == Scanner.import_Sym):
            ParserGen.usingPos = self.Imports()
        self.Expect(Scanner.COMPILER_Sym)
        self.genScanner = True
        Tab.ignored = set()
        self.Expect(Scanner.ident_Sym)
        gramName = self.token.val
        beg = self.la.pos
        while self.StartOf(1):
            self.Get()

        Tab.semDeclPos = Position(self.scanner.buffer, beg, self.la.pos - beg,
                                  0)
        if (self.la.kind == Scanner.IGNORECASE_Sym):
            self.Get()
            DFA.ignoreCase = True
        if (self.la.kind == Scanner.CHARACTERS_Sym):
            self.Get()
            while self.la.kind == Scanner.ident_Sym:
                self.SetDecl()

        if (self.la.kind == Scanner.TOKENS_Sym):
            self.Get()
            while self.la.kind == Scanner.ident_Sym or self.la.kind == Scanner.string_Sym:
                self.TokenDecl(Node.t)

        if (self.la.kind == Scanner.NAMES_Sym):
            self.Get()
            while self.la.kind == Scanner.ident_Sym:
                self.NameDecl()

        if (self.la.kind == Scanner.PRAGMAS_Sym):
            self.Get()
            while self.la.kind == Scanner.ident_Sym or self.la.kind == Scanner.string_Sym:
                self.TokenDecl(Node.pr)

        while self.la.kind == Scanner.COMMENTS_Sym:
            self.Get()
            nested = False
            self.Expect(Scanner.FROM_Sym)
            g1 = self.TokenExpr()
            self.Expect(Scanner.TO_Sym)
            g2 = self.TokenExpr()
            if (self.la.kind == Scanner.NESTED_Sym):
                self.Get()
                nested = True
            Comment(g1.l, g2.l, nested)

        while self.la.kind == Scanner.IGNORE_Sym:
            self.Get()
            s = self.Set()
            Tab.ignored |= s  # set union

        while not (self.la.kind == Scanner.EOF_SYM
                   or self.la.kind == Scanner.PRODUCTIONS_Sym):
            self.SynErr(49)
            self.Get()
        self.Expect(Scanner.PRODUCTIONS_Sym)
        if self.genScanner:
            DFA.MakeDeterministic()
        Graph.DeleteNodes()
        while self.la.kind == Scanner.ident_Sym:
            self.Get()
            sym = Symbol.Find(self.token.val)
            undef = (sym is None)
            if undef:
                sym = Symbol(Node.nt, self.token.val, self.token.line)
            else:
                if sym.typ == Node.nt:
                    if sym.graph is not None:
                        self.SemErr("name declared twice")
                else:
                    self.SemErr(
                        "this symbol kind not allowed on left side of production"
                    )
                sym.line = self.token.line
            noAttrs = (sym.attrPos is None)
            sym.attrPos = None
            noRet = (sym.retVar is None)
            sym.retVar = None
            if (self.la.kind == Scanner.less_Sym
                    or self.la.kind == Scanner.lesspoint_Sym):
                self.AttrDecl(sym)
            if not undef:
                if noAttrs != (sym.attrPos is None) or (noRet !=
                                                        (sym.retVar is None)):
                    self.SemErr(
                        "attribute mismatch between declaration and use of this symbol"
                    )
            if (self.la.kind == Scanner.lparenpoint_Sym):
                sym.semPos = self.SemText()
            self.ExpectWeak(Scanner.equal_Sym, 2)
            g = self.Expression()
            sym.graph = g.l
            Graph.Finish(g)
            self.ExpectWeak(Scanner.point_Sym, 3)

        self.Expect(Scanner.END_Sym)
        self.Expect(Scanner.ident_Sym)
        if gramName != self.token.val:
            self.SemErr("name does not match grammar name")
        Tab.gramSy = Symbol.Find(gramName)
        if Tab.gramSy is None:
            self.SemErr("missing production for grammar name")
        else:
            sym = Tab.gramSy
            if sym.attrPos is not None:
                self.SemErr("grammar symbol must not have attributes")
        Tab.noSym = Symbol(Node.t, "???", 0)  #noSym gets highest number
        Tab.SetupAnys()
        Tab.RenumberPragmas()
        if Tab.ddt[2]:
            Node.PrintNodes()
        if Errors.count == 0:
            sys.stdout.write("checking\n")
            Tab.CompSymbolSets()
            if Tab.ddt[7]:
                Tab.XRef()
            if Tab.GrammarOk():
                if not Tab.ddt[9]:
                    sys.stdout.write("parser")
                    ParserGen.WriteParser(Tab.ddt[10])
                    if self.genScanner:
                        sys.stdout.write(" + scanner")
                        DFA.WriteScanner(Tab.ddt[10])
                        if Tab.ddt[0]:
                            DFA.PrintStates()
                    if Tab.ddt[11]:
                        sys.stdout.write(" + driver")
                        DriverGen.WriteDriver()
                    sys.stdout.write(" generated\n")
                if Tab.ddt[8]:
                    ParserGen.WriteStatistics()
        if Tab.ddt[6]:
            Tab.PrintSymbolTable()
        self.Expect(Scanner.point_Sym)