Exemplo n.º 1
0
 def visitLiteral(self, ctx: BKITParser.LiteralContext):
     if ctx.INTLIT():
         a = ctx.INTLIT().getText()
         inlit = 0
         if len(a) > 1:
             if a[1] == 'x' or a[1] == 'X':
                 inlit = int(a, 16)
                 return 123
             elif a[1] == 'o' or a[1] == 'O':
                 inlit = int(a, 8)
             else:
                 inlit = int(a)
         else:
             inlit = int(a)
         return IntLiteral(inlit)
     elif ctx.FLOATLIT():
         return FloatLiteral(float(ctx.FLOATLIT().getText()))
     elif ctx.BOOLEAN():
         if ctx.BOOLEAN.getText() == 'True':
             return BooleanLiteral(True)
         else:
             return BooleanLiteral(False)
     elif ctx.STRINGLIT():
         return StringLiteral(ctx.STRINGLIT().getText())
     else:
         return self.visit(ctx.array())
Exemplo n.º 2
0
 def visitLiteral(self,ctx:BKITParser.LiteralContext):
     if ctx.INTLIT():
         return IntLiteral(int(ctx.INTLIT().getText(),0))
     elif ctx.FLOATLIT():
         return FloatLiteral(float(ctx.FLOATLIT().getText(),))
     elif ctx.BOOLIT():
         return BooleanLiteral(ctx.BOOLIT().getText())
     elif ctx.arrlit():
         return ArrayLiteral(ctx.arrlit().accept(self))
     else:
         return StringLiteral(ctx.STRLIT().getText())
Exemplo n.º 3
0
 def visitLiteral(self, ctx: BKITParser.LiteralContext):
     if ctx.INTLIT():
         a = ctx.INTLIT().getText()
         if a[0] == '0' and len(a) == 1:
             return IntLiteral(0)
         elif a[0] == '0' and (a[1] == 'x' or a[1] == 'X'):
             result = int(a, 16)
             return IntLiteral(result)
         elif a[0] == '0' and (a[1] == 'o' or a[1] == 'O'):
             result = int(a, 8)
             return IntLiteral(result)
         else:
             return IntLiteral(int(ctx.INTLIT().getText()))
     elif ctx.boollit():
         return self.visit(ctx.boollit())
     elif ctx.STRINGLIT():
         return StringLiteral(ctx.STRINGLIT().getText())
     elif ctx.FLOATLIT():
         return FloatLiteral(float(ctx.FLOATLIT().getText()))
     elif ctx.array():
         return self.visit(ctx.array())