Try it!
This runs as a Python CLI — clone the repo and run it locally to try it out.
Source Code
memory = {}
while True:
line = input("> ")
words = line.split()
if words[0] == 'set':
name = words[1]
value = words[3]
memory[name] = int(value)
elif words[0] == 'print':
name = words[1]
print(memory[name])
elif words[0] == 'add':
var1 = words[1]
var2 = words[3]
print(memory[var1] + memory[var2])
elif words[0] == 'subtract':
var1 = words[1]
var2 = words[3]
print(memory[var1] - memory[var2])
elif words[0] == 'exit':
break
else:
print("Unknown command. Available commands:")
print(" set <name> to <value> — store a variable")
print(" print <name> — display a variable")
print(" add <name1> and <name2> — add two variables")
print(" subtract <name1> and <name2> — subtract two variables")
print(" exit — quit")
Description
Challenges: Designing a readable command syntax that was still easy to parse with simple string splitting. The four commands — set, print, add, subtract — all follow a consistent word-position pattern so the interpreter stays straightforward.
Result: A working REPL-style interpreted language in one Python file. You can store integer variables, display them, and do addition and subtraction between named variables. Example session:
set x to 10
set y to 5
add x and y → 15
subtract x and y → 5
Previous Day
Next Day