Esempio n. 1
0
 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)
Esempio n. 2
0
 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)
Esempio n. 3
0
 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)
Esempio n. 4
0
 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)
Esempio n. 5
0
 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)
Esempio n. 6
0
 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)
Esempio n. 7
0
 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)
Esempio n. 8
0
 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)
Esempio n. 9
0
 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))
Esempio n. 10
0
 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')
Esempio n. 11
0
 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))
Esempio n. 12
0
 def visitIdentifierLiteral(self, ctx):
     t = ctx.ID().getSymbol()
     location = Location(self.filename, t.line)
     return Atom(t.text, location)
Esempio n. 13
0
 def visitStringLiteral(self, ctx):
     t = ctx.STRING().getSymbol()
     location = Location(self.filename, t.line)
     return StringLiteral(deslashify(t.text), location)
Esempio n. 14
0
 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)
Esempio n. 15
0
 def visitParameter(self, ctx):
     t = ctx.ID().getSymbol()
     location = Location(self.filename, t.line)
     return Atom(t.text, location)