Beispiel #1
0
def psIfElse():

    codeArray2 = assignment1Functions.op_pop()
    codeArray1 = assignment1Functions.op_pop()
    boolValue = assignment1Functions.op_pop()

    if boolValue == True:
        interpretSPS(codeArray1)
    elif boolValue == False:
        interpretSPS(codeArray2)
Beispiel #2
0
def psFor():

    codeArray = assignment1Functions.op_pop()
    finalValue = assignment1Functions.op_pop()
    incrementValue = assignment1Functions.op_pop()
    initialValue = assignment1Functions.op_pop()

    if incrementValue < 0:
        while (initialValue >= finalValue):
            assignment1Functions.op_push(initialValue)
            interpretSPS(codeArray)
            initialValue += incrementValue

    elif incrementValue > 0:
        while (initialValue <= finalValue):
            assignment1Functions.op_push(initialValue)
            interpretSPS(codeArray)
            initialValue += incrementValue
Beispiel #3
0
def new_ps_def():

    # Check if there are enough values on the operand stack and if values are in the correct format
    if len(assignment1Functions.op_stack) < 2:
        print(
            "There are not enough values on the operand stack to perform the operation"
        )
        return

    # Get the first two variables from the operand stack
    value_1 = assignment1Functions.op_pop()
    value_2 = assignment1Functions.op_pop()

    if value_2[0] != '/':
        assignment1Functions.op_push(value_2)
        assignment1Functions.op_push(value_1)
        print("The entry is not in the correct format")

        # Take the '/' from the name and then add to the dictionary at the top of the dict stack
    else:
        newDef(value_2, value_1)
Beispiel #4
0
def psForAll():
    procedure = assignment1Functions.op_pop()
    intArray = assignment1Functions.op_pop()
    for item in intArray:
        assignment1Functions.op_push(item)
        interpretSPS(procedure)
Beispiel #5
0
def psIf():
    codeArray = assignment1Functions.op_pop()
    boolValue = assignment1Functions.op_pop()
    if boolValue == True:
        interpretSPS(codeArray)