close
The Wayback Machine - https://web.archive.org/web/20201025152259/https://github.com/zakirullin/tiny-compiler
Skip to content

A tiny compiler for a language featuring LL(2) with Lexer, Parser, ASM-like codegen and VM. Complex enough to give you a flavour of how the "real" thing works whilst not being a mere toy example.

master
Go to file
Code

Latest commit

Fix safe_malloc infinite recursion and use safe_malloc
fb6d404

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
src
 
 
 
 
 
 
 
 
 
 

README.md

A tiny compiler for a simple synthetic language featuring LL(2) grammar, written in pure C

The compiler consist of typical parts, known as:

The compiler is implemented for educational purposes. Some parts are simplified for the sake of better understanding

Build

$ make

Usage

$ ./compiler <source>

An example program for Pythagorean theorem:

cath1 = 3;
cath2 = 4;
hypsquare = cath1 * cath1 + cath2 * cath2;

Execution result:

hypsquare = 25

Generated ASM:

PUSH 3
WRITE cath1
PUSH 4
WRITE cath2
READ cath1
READ cath1
MUL POP, POP
READ cath2
READ cath2
MUL POP, POP
ADD POP, POP
WRITE hypsquare

The language description in EBNF:

program = expr, ";", { program } ;
expr = id, "=", expr | term, { ("+"|"-"), term } ;
term = factor, { ("*"|"/"), factor } ;
factor = "id" | "num" | "(", expr, ")" ;

About

A tiny compiler for a language featuring LL(2) with Lexer, Parser, ASM-like codegen and VM. Complex enough to give you a flavour of how the "real" thing works whilst not being a mere toy example.

Topics

Resources

License

Releases

No releases published

Packages

No packages published
You can’t perform that action at this time.