Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/furkanonder/pytiny-c

A Tiny-C language compiler, rewritten in Python
https://github.com/furkanonder/pytiny-c

compiler tiny-c

Last synced: about 1 month ago
JSON representation

A Tiny-C language compiler, rewritten in Python

Awesome Lists containing this project

README

        

# PyTiny-C

A Tiny-C language compiler, rewritten in Python(It has been converted from C to Python with as much one-to-one
correlation as possible).

Tiny-C is a considerably stripped down version of C and it is meant as a pedagogical tool for learning about compilers.
The integer global variables "a" to "z" are predefined and initialized to zero, and it is not possible to declare new
variables. The compiler reads the program from standard input and prints out the value of the variables that are not
zero.

The grammar of Tiny-C in EBNF is:
```ebnf
::=
::= "if" |
"if" "else" |
"while" |
"do" "while" ";" |
"{" { } "}" |
";" |
";"
::= "(" ")"
::= | "="
::= | "<"
::= | "+" | "-"
::= | |
::= "a" | "b" | "c" | "d" | ... | "z"
::=
```

Here are a few invocations of the compiler:
```sh
$ echo "a=b=c=2<3;" | python tinyc.py
a = 1
b = 1
c = 1
$ echo "{ i=1; while (i<100) i=i+i; }" | python tinyc.py
i = 128
$ echo "{ i=125; j=100; while (i-j) if (i