This projects implements a Little Man Computer assembler and a high-level programming language compiler.
This was written for fun as an educational exercise, to understand a bit more of how a computer interprets rudimentary instructions, and how compilers are built.
python3 main.py <file>
Script files need the .script
extension.
If you want to run assembler written by hand, use the .man
extension.
All the Little Man instructions are implemented and working.
See: compiler/assembler.py
and compiler/executor.py
for the implementation.
Example:
LDA 6 # do '1 + 5'
ADD 5
OUT # should print '6'
HLT
MEM 1 # give mem an initial value of '1'
MEM 5
These things are sort of working:
- Variable assigmnent and re-assignment.
- Can evaluate expressions with the
+
and-
operator. e.g.:bar = foo + 3;
if
can evaluate0
to "false" and all positive integers to "true".- Printing of variables.
- Reading into variables.
- Nested if- and block-statements.
- Comments and inline-comments.
Example:
#
# Name: demo1.script
# Summary: Read one variable, then sum it with a constant.
#
foo = 13;
userInput = 0;
print(foo); # print variables
print(userInput);
read(userInput); # read input
foo = foo + userInput;
print(foo);
print(foo);
#
# Name: demo2.script
# Summary: Read user input. If true then print some number.
#
foo = 42;
userInput = 0;
read(userInput); # read input
if (userInput) {
var = 123;
print(var);
}
A working version of Python 3.4+ is required.