JVM inspired compiler and runtime to calculate simple arithmetic expressions with a stackmachine
Find a file
2024-07-21 12:17:38 +02:00
app fix: Encode constants using little endian 2024-07-20 22:47:36 +02:00
runtime feat(runtime): Implement add sub mult and div opcodes 2024-07-21 11:25:07 +02:00
.gitignore Create cabal project 2024-07-15 22:17:08 +02:00
arithmetic.txt Set a little more complex example calculation 2024-07-21 11:26:40 +02:00
CHANGELOG.md Create cabal project 2024-07-15 22:17:08 +02:00
LICENSE Create cabal project 2024-07-15 22:17:08 +02:00
README.md Add README.md 2024-07-21 12:17:38 +02:00
simple-arithmetic-compiler.cabal feat: Implement Assembler 2024-07-20 18:15:58 +02:00

What is this project?

This project contains a compiler and runtime environment to calculate simple arithmetic expressions (simple as in only +-*/).
The compiler is written in Haskell and the the runtimesystem is written in C.

How does it work?

The compiler restructures the arithmetic expression into an abstract syntax tree. The nodes of this tree contain the operation and the leafes are the constants of the expression. The syntax tree is then traversed in order to transform the expression into Reverse Polish Notation (RPN) and building the commands to calculate the results on a stack machine. The assembler then translates the commands into a bytestring an saves the result an a file. The runtime system reads the bytestring reconstructing the commands and executes them using an operand stack. This design is heavily influence by the Java Virtual Machine, but providing not nearly as much features.

But why?!

Mainly for the fun and learning. I need to learn Haskell for University so I figuered I try to write the compiler and assembler in it. However I also always wanted to write something more than a "Hello world!" in C and figured a stack machine would be the perfect fit, as it isn't too complex but also more than the simple "Hello world!".