Final Fixes, Bundle and Ship

This commit is contained in:
2024-01-25 22:06:51 -05:00
parent 6232aae708
commit cfb1fc7093
3 changed files with 7 additions and 6 deletions
+1 -3
View File
@@ -1,10 +1,9 @@
COS301 - HW1 - PMPV LANGUAGE INTERPERTER
NICHOLAS PEASE
1/22/2024
1/25/2024
USAGE
EXECUTION OF THE PROGRAM IMMEDIATELY TRANSFERS CONTROL TO THE COMMANDLINE, ALTHOUGH NO INFORMATION WILL BE OUTPUT.
ALL OPERATIONS REQUIRE A SPACE BETWEEN ALL OPERANDS AND OPERATIONS. FAILURE TO DO SO MAY RESULT IN MALFORMED OUTPUT.
ALL COMMANDS MUST START WITH A VARIABLE, OPERAND, OR PARENTHESIS (NO OPERATIONS UNLESS TO INDICATE A NEGATION)
I.E ans = 5
@@ -13,7 +12,6 @@ I.E (5 + 5) + 9
COMMON ERRORS:
ALL PARENTHESIS MUST BE CLOSED ELSE AN ERROR WILL BE PRODUCED.
ADDIITONALLY, THE INPUT MUST CONTAIN SOME TEXT.
EACH LINE MUST CONTAIN A SINGLE ASSIGNMENT OPERATIONS, WITH THE ASSIGNMENT VARIABLE TO THE LEFT AND THE EXPRESSION TO THE RIGHT.
ASSIGNMENT OPERATIONS MUST ONLY CONTAIN A VARIABLE ON THE LEFT, NO OPERATIONS ARE PERMITTED.
Binary file not shown.
+6 -3
View File
@@ -26,9 +26,9 @@ class Interpreter:
try:
this.inputRaw = input("" if this.inputRaw == "" else "\n")
if this.inputRaw != "": this.processAssignments(this.inputRaw)
except EOFError:
except EOFError: #CTRL+D
break
except KeyboardInterrupt:
except KeyboardInterrupt: #CTRL+C
break
def processAssignments(this, inputString):
@@ -50,6 +50,7 @@ class Interpreter:
def processParenthesis(this,inputString):
# Second Step - Determine if expression contains parenthesis
# Recursively designed function to evaluate parenthesis from left to right, inner to outer until no more remain
#print(inputString)
if inputString.count('(') == 0:
# No parenthesis or all parenthesis evaluated
return this.evaluate(inputString)
@@ -94,8 +95,10 @@ class Interpreter:
# A combination + and - is ignored as the negation will be bound to the int and the plus will be discarded
elif expressionMap[i] == "-" and expressionMap[i+1] == "-":
expressionMap[i+1] = '+'
else: #simple math, jsut return what's there
elif len(expressionMap) == 1: #simple math, just return what's there
total = expressionMap[0]
else: #no math, return nothing
total = ""
return str(total)
PMPVInterpreter = Interpreter()