def TokenFactor(self):
     g = None
     if self.la.kind == Scanner.ident_Sym or self.la.kind == Scanner.string_Sym:
         s = self.Sym()
         name, kind = s
         if kind == self.id:
             c = CharClass.Find(name)
             if c is None:
                 self.SemErr("undefined name")
                 c = CharClass(s.name, set())
             p = Node(Node.clas, None, 0)
             p.val = c.n
             g = Graph(p)
             self.tokenString = self.noString
         else:  # str
             g = Graph.StrToGraph(name)
             if self.tokenString is None:
                 self.tokenString = name
             else:
                 self.tokenString = self.noString
     elif self.la.kind == Scanner.lparen_Sym:
         self.Get()
         g = self.TokenExpr()
         self.Expect(Scanner.rparen_Sym)
     elif self.la.kind == Scanner.lbrack_Sym:
         self.Get()
         g = self.TokenExpr()
         self.Expect(Scanner.rbrack_Sym)
         Graph.MakeOption(g)
     elif self.la.kind == Scanner.lbrace_Sym:
         self.Get()
         g = self.TokenExpr()
         self.Expect(Scanner.rbrace_Sym)
         Graph.MakeIteration(g)
     else:
         self.SynErr(76)
     if g is None:  # invalid start of TokenFactor
         g = Graph(Node(Node.eps, None, 0))
     return g
 def Factor(self):
     weak = False
     g = None
     if self.la.kind == Scanner.ident_Sym or self.la.kind == Scanner.string_Sym or self.la.kind == Scanner.WEAK_Sym:
         if (self.la.kind == Scanner.WEAK_Sym):
             self.Get()
             weak = True
         s = self.Sym()
         name, kind = s
         sym = Symbol.Find(name)
         if (sym is None) and (kind == self.str):
             sym = Tab.literals.get(name)
         undef = (sym is None)
         if undef:
             if kind == self.id:
                 sym = Symbol(Node.nt, name, 0)  # forward nt
             elif self.genScanner:
                 sym = Symbol(Node.t, name, self.token.line)
                 DFA.MatchLiteral(sym.name, sym)
             else:  # undefined string in production
                 self.SemErr("undefined string in production")
                 sym = Tab.eofSy  # dummy
         typ = sym.typ
         if (typ != Node.t) and (typ != Node.nt):
             self.SemErr("this symbol kind is not allowed in a production")
         if weak:
             if typ == Node.t:
                 typ = Node.wt
             else:
                 self.SemErr("only terminals may be weak")
         p = Node(typ, sym, self.token.line)
         g = Graph(p)
         if (self.la.kind == Scanner.less_Sym
                 or self.la.kind == Scanner.lesspoint_Sym):
             self.Attribs(p)
             if kind != self.id:
                 self.SemErr("a literal must not have attributes")
         if undef:
             sym.attrPos = p.pos  # dummy
             sym.retVar = p.retVar  # AH - dummy
         elif ((p.pos is None) !=
               (sym.attrPos is None)) or ((p.retVar is None) !=
                                          (sym.retVar is None)):
             self.SemErr(
                 "attribute mismatch between declaration and use of this symbol"
             )
     elif self.la.kind == Scanner.lparen_Sym:
         self.Get()
         g = self.Expression()
         self.Expect(Scanner.rparen_Sym)
     elif self.la.kind == Scanner.lbrack_Sym:
         self.Get()
         g = self.Expression()
         self.Expect(Scanner.rbrack_Sym)
         Graph.MakeOption(g)
     elif self.la.kind == Scanner.lbrace_Sym:
         self.Get()
         g = self.Expression()
         self.Expect(Scanner.rbrace_Sym)
         Graph.MakeIteration(g)
     elif self.la.kind == Scanner.lparenpoint_Sym:
         pos = self.SemText()
         p = Node(Node.sem, None, 0)
         p.pos = pos
         g = Graph(p)
     elif self.la.kind == Scanner.ANY_Sym:
         self.Get()
         p = Node(Node.any, None, 0)  # p.set is set in Tab.SetupAnys
         g = Graph(p)
     elif self.la.kind == Scanner.SYNC_Sym:
         self.Get()
         p = Node(Node.sync, None, 0)
         g = Graph(p)
     else:
         self.SynErr(68)
     if g is None:  # invalid start of Factor
         g = Graph(Node(Node.eps, None, 0))
     return g