Add runner portion of the interpreter
The interpreter is now complete. Apart from bugs that may be hiding in the code, it should work now.master
parent
fbdf2e42f2
commit
b8b23249a0
28
lambdaV.py
28
lambdaV.py
|
@ -75,6 +75,19 @@ def draw_field():
|
|||
print("")
|
||||
|
||||
|
||||
# returns "" or error message
|
||||
# Parsed code is the result of running the parser,
|
||||
# though at this point the input is assumed to be valid
|
||||
# and no additional checks are performed on what the parser produced.
|
||||
def run_code(parsed_code):
|
||||
for i in range(len(parsed_code[0])):
|
||||
result = parsed_code[0][i](*parsed_code[1][i])
|
||||
if not result=="":
|
||||
return result
|
||||
draw_field()
|
||||
return ""
|
||||
|
||||
|
||||
def condition_facing_north(inverted):
|
||||
if inverted:
|
||||
return not cursor_current == cursor_north
|
||||
|
@ -449,10 +462,19 @@ def parse_code(code, allowed_commands, allowed_conditions, unformatted_code=True
|
|||
return [[], [], parse_position, "Syntax error: Unknown control structure: "+control_structure, code]
|
||||
return parsed_code
|
||||
|
||||
# A wrapper for run_code that deals with potential errors produced by the parser.
|
||||
# returns success or error message
|
||||
# Parsed code is the result of running the parser.
|
||||
def run_code(parsed_code):
|
||||
return ""
|
||||
def evaluate_parser_result(parsed_code):
|
||||
if not parsed_code[2]==-1:
|
||||
# parser error
|
||||
return parsed_code[3] + "\n" + (" "*parsed_code[2]) + "↓\n" + parsed_code[4]
|
||||
outcome = run_code(parsed_code)
|
||||
if not outcome=="":
|
||||
# runtime error
|
||||
# TODO: pass back information about where the error occurred
|
||||
return outcome
|
||||
#TODO: check if goal reached
|
||||
return "Success!"
|
||||
|
||||
if __name__ == "__main__":
|
||||
pass
|
||||
|
|
Loading…
Reference in New Issue