def visitForExpression(self, ctx): lineno = ctx.FOR().getSymbol().line location = Location(self.filename, lineno) f = Atom(SymbolTable.FOR, location) t = ctx.ID().getSymbol() location = Location(self.filename, t.line) atom = Atom(t.text, location) return SExpression(Syntax.FOR, (f, atom, self.visit(ctx.rangeExpression()), self.visitImplicitSeq(ctx.expression())), location)
def visitLambdaExpression(self, ctx): lineno = ctx.LAMBDA().getSymbol().line location = Location(self.filename, lineno) params = self.visitParameterList(ctx.parameterList()) body = self.visitImplicitSeq(ctx.expression()) lamb = Atom(SymbolTable.LAMBDA, location) return SExpression(Syntax.LAMBDA, (lamb, params, body), location)
def visitExpressionList(self, code, tsym, explist): t = tsym.getSymbol() location = Location(self.filename, t.line) retval = [Atom(SymbolTable.canonicalize(t.text), location)] for e in explist: retval.append(self.visit(e)) return SExpression(code, tuple(retval), location)
def visitDataExpression(self, ctx): t = ctx.PRIMITIVE_DATA_OP().getSymbol() lineno = t.line location = Location(self.filename, lineno) op = Atom(SymbolTable.canonicalize(t.text), location) return SExpression(Syntax.PRIMITIVE_DATA_OP, (op, self.visitData(ctx.data())), location)
def visitCatchExpression(self, ctx): lineno = ctx.CATCH().getSymbol().line location = Location(self.filename, lineno) ctch = Atom(SymbolTable.CATCH, location) return SExpression(Syntax.CATCH, (ctch, self.visitParameter(ctx.parameter()), self.visitImplicitSeq(ctx.expression())), location)
def visitLetExpression(self, ctx): lineno = ctx.LET().getSymbol().line location = Location(self.filename, lineno) bindings = self.visitBindingList(ctx.bindingList()) body = self.visitImplicitSeq(ctx.expression()) let = Atom(SymbolTable.LET, location) return SExpression(Syntax.LET, (let, bindings, body), location)
def visitDefineExpression(self, ctx): lineno = ctx.DEFINE().getSymbol().line location = Location(self.filename, lineno) define = Atom(SymbolTable.DEFINE, location) paramList = ctx.parameterList() params = None if paramList is not None: params = self.visitParameterList(paramList) body = self.visitImplicitSeq(ctx.expression()) atom = Atom(sys.intern(str(ctx.ID().getSymbol().text)), Location(self.filename, ctx.ID().getSymbol().line)) if params is not None: return SExpression(Syntax.DEFINE, (define, atom, params, body), location) return SExpression(Syntax.DEFINE, (define, atom, body), location)
def visitTryExpression(self, ctx): lineno = ctx.TRY().getSymbol().line location = Location(self.filename, lineno) tr = Atom(SymbolTable.TRY, location) return SExpression(Syntax.TRY, (tr, self.visitImplicitSeq(ctx.expression()), self.visitCatchExpression(ctx.catchExpression())), location)
def visitParameterList(self, ctx): retval = [] lineno = None for p in ctx.parameter(): if lineno is None: lineno = p.ID().getSymbol().line retval.append(self.visitParameter(p)) return SExpression(None, tuple(retval), Location(self.filename, lineno))
def visitUnaryExpression(self, ctx): t = ctx.UNARY_OP().getSymbol() location = Location(self.filename, t.line) rawop = t.text canonicalop = SymbolTable.canonicalize(rawop) if canonicalop is not None: op = Atom(canonicalop, location) return SExpression(Syntax.UNARY_OP, (op, self.visit(ctx.expression())), location) raise ParseError(f'Ooopsy: {rawop} not found in the SymbolTable')
def visitData(self, ctx): data = None if ctx.ID() != None: data = ctx.ID() elif ctx.NUMBER() != None: data = ctx.NUMBER() else: data = ctx.CHARACTER() return Atom(data.getSymbol().text, Location(self.filename, data.getSymbol().line))
def visitIdentifierLiteral(self, ctx): t = ctx.ID().getSymbol() location = Location(self.filename, t.line) return Atom(t.text, location)
def visitStringLiteral(self, ctx): t = ctx.STRING().getSymbol() location = Location(self.filename, t.line) return StringLiteral(deslashify(t.text), location)
def visitBindingPair(self, ctx): lineno = ctx.parameter().ID().getSymbol().line location = Location(self.filename, lineno) return SExpression(None, (self.visitParameter( ctx.parameter()), self.visit(ctx.expression())), location)
def visitParameter(self, ctx): t = ctx.ID().getSymbol() location = Location(self.filename, t.line) return Atom(t.text, location)