Beispiel #1
0
 def call(interpreter, args):
     if self.notEmpty():
         if args[0].value in self.value:
             return _boolean.Bool().call(self, [True])
         else:
             return _boolean.Bool().call(self, [False])
     else:
         raise _RuntimeError('String', "IndexError: cannot index from an empty string")
Beispiel #2
0
 def call(interpreter, args):
     if self.notEmpty():
         endlen = len(args[0].value)
         index = -(endlen)
         if args[0] == self.value[index:]:
             return _boolean.Bool().call(self, [True])
         else:
             return _boolean.Bool().call(self, [False])
     else:
         raise _RuntimeError('String', "IndexError: cannot index from an empty string")
Beispiel #3
0
            def call(interpreter, args):
                if self.notEmpty():
                    for i in range(len(self.elements)):
                        if args[0].value == self.elements[i].value:
                            return _boolean.Bool().call(self, [True])
                    
                    return _boolean.Bool().call(self, [False])

                else:
                    raise _RuntimeError('List', "IndexError: cannot index from an empty list")
Beispiel #4
0
    def visitLiteralExpr(self, expr: _Literal):
        if type(expr.value) == int:
            return _rocketNumber.Int().call(self, [expr.value])

        if type(expr.value) == float:
            return _rocketNumber.Float().call(self, [expr.value])

        if type(expr.value) == str:
            return _rocketString.String().call(self, [expr.value])

        if type(expr.value) == bool:
            return _rocketBoolean.Bool().call(self, [expr.value])

        return expr.value
Beispiel #5
0
    def __init__(self, KSL: list):
        self.globals = _Environment()  # For the native functions
        self.environment = _Environment()  # Functions / classes
        self.locals = {}
        self.errors = []
        self.KSL = KSL
        self.stackCount = 0  # tracks stmt repetitions, 'stackoverflow' errs
        self.fnCallee = None  # Tracks current fn callee

        # Statically define 'native' functions
        # random n between '0-1' {insecure}
        self.globals.define(_random.Random().callee, _random.Random)
        # print (escaped) output. i.e print("hello\tmr.Jim") -> "Hello	mr.Jim"
        self.globals.define(_output.Print().callee, _output.Print)
        # grab user input
        self.globals.define(_input.Input().callee, _input.Input)
        # 'locals' return all globally defined 'vars' and 'consts'
        self.globals.define(_locals.Locals().callee, _locals.Locals)
        # 'clock'
        self.globals.define(_clock.Clock().callee, _clock.Clock)
        # 'copyright'
        self.globals.define(_copyright.Copyright().callee,
                            _copyright.Copyright)
        # 'natives' -> names of nativr functions
        self.globals.define(_natives.Natives().callee, _natives.Natives)
        # 'type' -> check datatype
        self.globals.define(_kind.Type().callee, _kind.Type)

        # Datatypes
        self.globals.define(_rocketList.List().callee, _rocketList.List)
        self.globals.define(_rocketArray.Array().callee, _rocketArray.Array)
        self.globals.define(_rocketString.String().callee,
                            _rocketString.String)
        self.globals.define(_rocketNumber.Int().callee, _rocketNumber.Int)
        self.globals.define(_rocketNumber.Float().callee, _rocketNumber.Float)
        self.globals.define(_rocketBoolean.Bool().callee, _rocketBoolean.Bool)
Beispiel #6
0
            def call(interpreter, args):
                if self.notEmpty():
                    return _boolean.Bool().call(self, [self.value.isdecimal()])

                else:
                    raise _RuntimeError('String', "IndexError: cannot index from an empty string")