Beispiel #1
0
def try_cast(stack, what_type):
    INTEGER, FLOAT, STRING, STACK, CHARACTER = "ℤℝ⅍℠ⁿ"
    if what_type == INTEGER:
        item = stack.pop()
        try:
            item = int(item)
        except:
            pass
        stack.push(item)

    elif what_type == FLOAT:
        item = stack.pop()
        try:
            item = float(item)
        except:
            pass
        stack.push(item)

    elif what_type == STRING:
        stack.push(str(stack.pop()))

    elif what_type == CHARACTER:
        item = stack.pop()
        if Coherse._type(item) == "Number":
            stack.push(_chr(int(item)))
        elif Coherse._type(item) == "Character":
            stack.push(item)
        elif Coherse._type(item) == "String":
            stack.push(char(item[0]))
        elif Coherse._type(item) == "Stack":
            stack.push(try_cast(item, CHARACTER))
Beispiel #2
0
    def pop(self):
        if self.__stack:
            return self.__stack.pop()
        try:
            temp = input()
        except:
            return None

        if input_raw:
            from Coherse import char
            for Char in reversed(temp):
                self.__stack.append(char(Char))
            return self.__stack.pop()

        try:
            if type(eval(temp)) is float:
                temp = float(temp)
            elif type(eval(temp)) is int:
                temp = int(temp)
            elif type(eval(temp)) is list:
                temp = Stack(eval(temp))
            elif type(eval(temp)) is str:
                for Char in reversed(temp):
                    self.__stack.append(Char)
                return self.__stack.pop()
        except:
            temp = temp

        self.inputs.append(temp)
        return temp
Beispiel #3
0
def multiline(stack):
    temp = 1
    while temp:
        temp = input()
        for Char in temp:
            stack.push(char(Char))
        stack.push("\n")
    stack.pop()
Beispiel #4
0
def Input(stack):
    #This is the first of many input functions.
    #"Why are there more than one input function though?"
    #Well, because ?¿᠀ and implict input. That's why.

    #This one is "take input and push as ord"
    item = input()
    if item:
        for Char in reversed(item):
            stack.push(char(Char))
        inputs.push(item)
    else:
        item = inputs.pop()
        inputs.push(item)
        if type(item) is str:
            for Char in reversed(item):
                stack.push(char(Char))
        else:
            stack.push(item)
    shift(inputs, "R")
Beispiel #5
0
def character(stack, letter):
    stack.push(char(letter))