/stack-langc

StackVM langauge (postfix expression) compiler.

Primary LanguageRust

Stack-Langc

Stack-Langc compiler written in Rust to translate the given simple postfix expression into Stack-VM binary.


Language Spec

First 2 bits distinguishes between data and instruction.

bits Type
00 Data (Positive number)
01 Operation Instruction (OI)
10 Data (negative number)
11 undefined

VM operation instruction (OI)

0x40000001		ADD
0x40000010		SUB
0x40000011	   	MUL
0x40000100	   	DIV
0x40000000		HALT

All program must end with HALT instruction.


To run

cargo run source_file_name

or stack-langc source_file_name

output generated by this will be writtent to file called a.out in current working directory.

Example

Create file called program.vm as follows

32 22 + 

#order of evaluation Left to Right (ans=54)

compile the program using stack-langc, it will generate instruction as follows

Hex word VM Value
0x00000020 Data (32 in decimal)
0x00000016 Data (22 in decimal)
0x40000001 OI (ADD)
0x40000000 OI (HALT)