All Projects → zakirullin → Tiny Compiler

zakirullin / Tiny Compiler

Licence: mit
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

Programming Languages

c
50402 projects - #5 most used programming language

Projects that are alternatives of or similar to Tiny Compiler

Exprtk
C++ Mathematical Expression Parsing And Evaluation Library
Stars: ✭ 301 (-29.18%)
Mutual labels:  compiler, ast, lexer, parser
Charly Vm
Fibers, Closures, C-Module System | NaN-boxing, bytecode-VM written in C++
Stars: ✭ 66 (-84.47%)
Mutual labels:  compiler, ast, lexer, parser
Cub
The Cub Programming Language
Stars: ✭ 198 (-53.41%)
Mutual labels:  compiler, ast, lexer, parser
Lioness
The Lioness Programming Language
Stars: ✭ 155 (-63.53%)
Mutual labels:  compiler, ast, lexer, parser
Snapdragon
snapdragon is an extremely pluggable, powerful and easy-to-use parser-renderer factory.
Stars: ✭ 180 (-57.65%)
Mutual labels:  compiler, ast, lexer, parser
Csstree
A tool set for CSS including fast detailed parser, walker, generator and lexer based on W3C specs and browser implementations
Stars: ✭ 1,121 (+163.76%)
Mutual labels:  ast, lexer, parser
Participle
A parser library for Go
Stars: ✭ 2,302 (+441.65%)
Mutual labels:  ast, lexer, parser
Graphql Go Tools
Tools to write high performance GraphQL applications using Go/Golang.
Stars: ✭ 96 (-77.41%)
Mutual labels:  ast, lexer, parser
Minigo
minigo🐥is a small Go compiler made from scratch. It can compile itself.
Stars: ✭ 456 (+7.29%)
Mutual labels:  compiler, lexer, parser
Webassemblyjs
Toolchain for WebAssembly
Stars: ✭ 566 (+33.18%)
Mutual labels:  compiler, ast, parser
Phplrt
PHP Language Recognition Tool
Stars: ✭ 127 (-70.12%)
Mutual labels:  compiler, ast, parser
Ratel Core
High performance JavaScript to JavaScript compiler with a Rust core
Stars: ✭ 367 (-13.65%)
Mutual labels:  compiler, ast, parser
Php Parser
🌿 NodeJS PHP Parser - extract AST or tokens (PHP5 and PHP7)
Stars: ✭ 400 (-5.88%)
Mutual labels:  ast, lexer, parser
Pyverilog
Python-based Hardware Design Processing Toolkit for Verilog HDL
Stars: ✭ 267 (-37.18%)
Mutual labels:  compiler, parser
pascal-interpreter
A simple interpreter for a large subset of Pascal language written for educational purposes
Stars: ✭ 21 (-95.06%)
Mutual labels:  ast, lexer
Swiftpascalinterpreter
Simple Swift interpreter for the Pascal language inspired by the Let’s Build A Simple Interpreter article series.
Stars: ✭ 270 (-36.47%)
Mutual labels:  ast, lexer
Re Flex
The regex-centric, fast lexical analyzer generator for C++ with full Unicode support. Faster than Flex. Accepts Flex specifications. Generates reusable source code that is easy to understand. Introduces indent/dedent anchors, lazy quantifiers, functions for lex/syntax error reporting, and more. Seamlessly integrates with Bison and other parsers.
Stars: ✭ 274 (-35.53%)
Mutual labels:  compiler, lexer
bredon
A modern CSS value compiler in JavaScript
Stars: ✭ 39 (-90.82%)
Mutual labels:  ast, lexer
Jsqlparser
JSqlParser parses an SQL statement and translate it into a hierarchy of Java classes. The generated hierarchy can be navigated using the Visitor Pattern
Stars: ✭ 3,405 (+701.18%)
Mutual labels:  ast, parser
Bblfshd
A self-hosted server for source code parsing
Stars: ✭ 297 (-30.12%)
Mutual labels:  ast, parser

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

The compiler consist of typical parts, known as:

It is by no means a complete industry standard implementation. 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, ")" ;
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].