Skip to content

A high-level programming language that compiles to Little Man instructions

License

Notifications You must be signed in to change notification settings

Syntox32/LittleMan

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

57 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Little Man Compiler & Assembler

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.

Usage

python3 main.py <file>

Script files need the .script extension.

If you want to run assembler written by hand, use the .man extension.

Assembler language

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

Scripting language

These things are sort of working:

  1. Variable assigmnent and re-assignment.
  2. Can evaluate expressions with the + and - operator. e.g.: bar = foo + 3;
  3. if can evaluate 0 to "false" and all positive integers to "true".
  4. Printing of variables.
  5. Reading into variables.
  6. Nested if- and block-statements.
  7. 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);
}

Requirements

A working version of Python 3.4+ is required.

About

A high-level programming language that compiles to Little Man instructions

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published