def Resolver(self):
     self.Expect(Scanner.IF_Sym)
     self.Expect(Scanner.lparen_Sym)
     beg = self.la.pos
     col = self.la.col
     self.Condition()
     pos = Position(self.scanner.buffer, beg, self.token.pos - beg, col)
     return pos
    def SemText(self):
        self.Expect(Scanner.lparenpoint_Sym)
        beg = self.la.pos
        col = self.la.col
        while self.StartOf(17):
            if self.StartOf(18):
                self.Get()
            elif self.la.kind == Scanner.badString_Sym:
                self.Get()
                self.SemErr("bad string in semantic action")
            else:
                self.Get()
                self.SemErr("missing end of previous semantic action")

        self.Expect(Scanner.pointrparen_Sym)
        pos = Position(self.scanner.buffer, beg, self.token.pos - beg, col)
        return pos
    def Attribs(self, n):
        if self.la.kind == Scanner.less_Sym:
            self.Get()
            if self.la.kind == Scanner.uparrow_Sym or self.la.kind == Scanner.out_Sym:
                if self.la.kind == Scanner.uparrow_Sym:
                    self.Get()
                elif self.la.kind == Scanner.out_Sym:
                    self.Get()
                else:
                    self.SynErr(69)
                beg = self.la.pos
                while self.StartOf(25):
                    if self.StartOf(26):
                        self.Get()
                    else:
                        self.Get()
                        self.SemErr("bad string in attributes")

                n.retVar = self.scanner.buffer.getString(beg, self.la.pos)
                if self.la.kind == Scanner.greater_Sym:
                    self.Get()
                elif self.la.kind == Scanner.comma_Sym:
                    self.Get()
                    beg = self.la.pos
                    col = self.la.col
                    while self.StartOf(8):
                        if self.StartOf(9):
                            self.Get()
                        else:
                            self.Get()
                            self.SemErr("bad string in attributes")

                    self.Expect(Scanner.greater_Sym)
                    if self.token.pos > beg:
                        n.pos = Position(self.scanner.buffer, beg,
                                         self.token.pos - beg, col)
                else:
                    self.SynErr(70)
            elif self.StartOf(10):
                beg = self.la.pos
                col = self.la.col
                while self.StartOf(11):
                    if self.StartOf(12):
                        self.Get()
                    else:
                        self.Get()
                        self.SemErr("bad string in attributes")

                self.Expect(Scanner.greater_Sym)
                if self.token.pos > beg:
                    n.pos = Position(self.scanner.buffer, beg,
                                     self.token.pos - beg, col)
            else:
                self.SynErr(71)
        elif self.la.kind == Scanner.lesspoint_Sym:
            self.Get()
            if self.la.kind == Scanner.uparrow_Sym or self.la.kind == Scanner.out_Sym:
                if self.la.kind == Scanner.uparrow_Sym:
                    self.Get()
                elif self.la.kind == Scanner.out_Sym:
                    self.Get()
                else:
                    self.SynErr(72)
                beg = self.la.pos
                while self.StartOf(27):
                    if self.StartOf(28):
                        self.Get()
                    else:
                        self.Get()
                        self.SemErr("bad string in attributes")

                n.retVar = self.scanner.buffer.getString(beg, self.la.pos)
                if self.la.kind == Scanner.pointgreater_Sym:
                    self.Get()
                elif self.la.kind == Scanner.comma_Sym:
                    self.Get()
                    beg = self.la.pos
                    col = self.la.col
                    while self.StartOf(13):
                        if self.StartOf(14):
                            self.Get()
                        else:
                            self.Get()
                            self.SemErr("bad string in attributes")

                    self.Expect(Scanner.pointgreater_Sym)
                    if self.token.pos > beg:
                        n.pos = Position(self.scanner.buffer, beg,
                                         self.token.pos - beg, col)
                else:
                    self.SynErr(73)
            elif self.StartOf(10):
                beg = self.la.pos
                col = self.la.col
                while self.StartOf(15):
                    if self.StartOf(16):
                        self.Get()
                    else:
                        self.Get()
                        self.SemErr("bad string in attributes")

                self.Expect(Scanner.pointgreater_Sym)
                if self.token.pos > beg:
                    n.pos = Position(self.scanner.buffer, beg,
                                     self.token.pos - beg, col)
            else:
                self.SynErr(74)
        else:
            self.SynErr(75)
    def AttrDecl(self, sym):
        if self.la.kind == Scanner.less_Sym:
            self.Get()
            if self.la.kind == Scanner.uparrow_Sym or self.la.kind == Scanner.out_Sym:
                if self.la.kind == Scanner.uparrow_Sym:
                    self.Get()
                elif self.la.kind == Scanner.out_Sym:
                    self.Get()
                else:
                    self.SynErr(55)
                self.Expect(Scanner.ident_Sym)
                sym.retVar = self.token.val
                if self.la.kind == Scanner.greater_Sym:
                    self.Get()
                elif self.la.kind == Scanner.comma_Sym:
                    self.Get()
                    beg = self.la.pos
                    col = self.la.col
                    while self.StartOf(8):
                        if self.StartOf(9):
                            self.Get()
                        else:
                            self.Get()
                            self.SemErr("bad string in attributes")

                    self.Expect(Scanner.greater_Sym)
                    if self.token.pos > beg:
                        sym.attrPos = Position(self.scanner.buffer, beg,
                                               self.token.pos - beg, col)
                else:
                    self.SynErr(56)
            elif self.StartOf(10):
                beg = self.la.pos
                col = self.la.col
                while self.StartOf(11):
                    if self.StartOf(12):
                        self.Get()
                    else:
                        self.Get()
                        self.SemErr("bad string in attributes")

                self.Expect(Scanner.greater_Sym)
                if self.token.pos > beg:
                    sym.attrPos = Position(self.scanner.buffer, beg,
                                           self.token.pos - beg, col)
            else:
                self.SynErr(57)
        elif self.la.kind == Scanner.lesspoint_Sym:
            self.Get()
            if self.la.kind == Scanner.uparrow_Sym or self.la.kind == Scanner.out_Sym:
                if self.la.kind == Scanner.uparrow_Sym:
                    self.Get()
                elif self.la.kind == Scanner.out_Sym:
                    self.Get()
                else:
                    self.SynErr(58)
                self.Expect(Scanner.ident_Sym)
                sym.retVar = self.token.val
                if self.la.kind == Scanner.pointgreater_Sym:
                    self.Get()
                elif self.la.kind == Scanner.comma_Sym:
                    self.Get()
                    beg = self.la.pos
                    col = self.la.col
                    while self.StartOf(13):
                        if self.StartOf(14):
                            self.Get()
                        else:
                            self.Get()
                            self.SemErr("bad string in attributes")

                    self.Expect(Scanner.pointgreater_Sym)
                    if self.token.pos > beg:
                        sym.attrPos = Position(self.scanner.buffer, beg,
                                               self.token.pos - beg, col)
                else:
                    self.SynErr(59)
            elif self.StartOf(10):
                beg = self.la.pos
                col = self.la.col
                while self.StartOf(15):
                    if self.StartOf(16):
                        self.Get()
                    else:
                        self.Get()
                        self.SemErr("bad string in attributes")

                self.Expect(Scanner.pointgreater_Sym)
                if self.token.pos > beg:
                    sym.attrPos = Position(self.scanner.buffer, beg,
                                           self.token.pos - beg, col)
            else:
                self.SynErr(60)
        else:
            self.SynErr(61)
    def Imports(self):
        beg = None
        pos = None
        if (self.la.kind == Scanner.from_Sym):
            self.Get()
            beg = self.token.pos
            self.Expect(Scanner.ident_Sym)
            while self.la.kind == Scanner.point_Sym:
                self.Get()
                self.Expect(Scanner.ident_Sym)

        self.Expect(Scanner.import_Sym)
        if beg == None:
            beg = self.token.pos
        if self.la.kind == Scanner.ident_Sym:
            self.Get()
            while self.la.kind == Scanner.point_Sym:
                self.Get()
                self.Expect(Scanner.ident_Sym)

            while self.la.kind == Scanner.comma_Sym:
                self.Get()
                self.Expect(Scanner.ident_Sym)
                while self.la.kind == Scanner.point_Sym:
                    self.Get()
                    self.Expect(Scanner.ident_Sym)

        elif self.la.kind == Scanner.lparen_Sym:
            self.Get()
            self.Expect(Scanner.ident_Sym)
            while self.la.kind == Scanner.point_Sym:
                self.Get()
                self.Expect(Scanner.ident_Sym)

            while self.la.kind == Scanner.comma_Sym:
                self.Get()
                self.Expect(Scanner.ident_Sym)
                while self.la.kind == Scanner.point_Sym:
                    self.Get()
                    self.Expect(Scanner.ident_Sym)

            self.Expect(Scanner.rparen_Sym)
        elif self.la.kind == Scanner.star_Sym:
            self.Get()
        else:
            self.SynErr(50)
        while self.la.kind == Scanner.from_Sym or self.la.kind == Scanner.import_Sym:
            if (self.la.kind == Scanner.from_Sym):
                self.Get()
                self.Expect(Scanner.ident_Sym)
                while self.la.kind == Scanner.point_Sym:
                    self.Get()
                    self.Expect(Scanner.ident_Sym)

            self.Get()
            if self.la.kind == Scanner.ident_Sym:
                self.Get()
                while self.la.kind == Scanner.point_Sym:
                    self.Get()
                    self.Expect(Scanner.ident_Sym)

                while self.la.kind == Scanner.comma_Sym:
                    self.Get()
                    self.Expect(Scanner.ident_Sym)
                    while self.la.kind == Scanner.point_Sym:
                        self.Get()
                        self.Expect(Scanner.ident_Sym)

            elif self.la.kind == Scanner.lparen_Sym:
                self.Get()
                self.Expect(Scanner.ident_Sym)
                while self.la.kind == Scanner.point_Sym:
                    self.Get()
                    self.Expect(Scanner.ident_Sym)

                while self.la.kind == Scanner.comma_Sym:
                    self.Get()
                    self.Expect(Scanner.ident_Sym)
                    while self.la.kind == Scanner.point_Sym:
                        self.Get()
                        self.Expect(Scanner.ident_Sym)

                self.Expect(Scanner.rparen_Sym)
            else:
                self.SynErr(51)

        end = self.la.pos
        pos = Position(self.scanner.buffer, beg, end - beg, 0)
        return pos
    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)