def visit_const_item(self, node): name, _, konstant = node.children if konstant.type == sym.CHAR: val = AST.Char(node.value, node.context) else: assert konstant.type == sym.integer val = AST.Num(self.visit(konstant), konstant.context) return name.value, val
def visit_atom(self, node, context): first = node.first_child if first.type == sym.NAME: if len(node.children) == 1: # single name return AST.Name(first.value, context, first.context) # name with trailer: visit_trailer trailer = node.children[1] return self.visit(trailer, first.value, context) if first.type == sym.NUMBER: return AST.Num(int(first.value), first.context) if first.type == sym.CHAR: return AST.Char(first.value, first.context) else: assert first.value == '(' # parenthesis expr # visit_expr value = self.visit(node.children[1], context) return AST.ParenExpr(value, first.context)