Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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
- Host: GitHub
- URL: https://github.com/furkanonder/pytiny-c
- Owner: furkanonder
- License: gpl-3.0
- Created: 2024-11-15T21:11:45.000Z (about 2 months ago)
- Default Branch: main
- Last Pushed: 2024-11-15T21:14:57.000Z (about 2 months ago)
- Last Synced: 2024-11-27T06:07:16.905Z (about 1 month ago)
- Topics: compiler, tiny-c
- Language: Python
- Homepage:
- Size: 14.6 KB
- Stars: 10
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
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