Example #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)
Example #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)
Example #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)
Example #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)
Example #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)
Example #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)
Example #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)
Example #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)
Example #9
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')
Example #10
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))
Example #11
0
 def visitImplicitSeq(self, explist):
     retval = []
     location = None
     for e in explist:
         val = self.visit(e)
         if location is None:
             location = val.location
         retval.append(val)
     #if there is an implicit seq, make it explicit
     if len(retval) > 1:
         retval.insert(0, Atom(SymbolTable.SEQ, location))
         return SExpression(Syntax.SEQ, tuple(retval), location)
     return retval[0]
Example #12
0
 def visitIdentifierLiteral(self, ctx):
     t = ctx.ID().getSymbol()
     location = Location(self.filename, t.line)
     return Atom(t.text, location)
Example #13
0
 def visitParameter(self, ctx):
     t = ctx.ID().getSymbol()
     location = Location(self.filename, t.line)
     return Atom(t.text, location)