Ecosyste.ms: Awesome

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

Awesome Lists | Featured Topics | Projects

https://github.com/matejamaric/tinyc-in-go

A Go implementation of Marc Feeley's TinyC
https://github.com/matejamaric/tinyc-in-go

bytecode-interpreter compiler functional-programming golang recursive-descent-parser

Last synced: 21 days ago
JSON representation

A Go implementation of Marc Feeley's TinyC

Awesome Lists containing this project

README

        

### About:

A Go implementation of Marc Feeley's TinyC "compiler" (bytecode interpreter) from 2001.

The are considerable differences between [the original Marc Feeley's implementation](https://www.iro.umontreal.ca/~felipe/IFT2030-Automne2002/Complements/tinyc.c) and this one:
1. The original has ~300loc, while this one has ~750loc.
Although, just by applying different formatting to the original, it would probably double it's loc count.
1. The original implementation heavily relied on global variables, this one does not.
In this implementation the lexer, the parser, the code generator and the virtual machine are implemented as pure functions.
1. This implementation has unit tests with coverage of ~93%.

### How to use:

The integer global variables "a" to "z" are predefined and initialized to zero.
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 in EBNF is:

```
::=
::= "if" |
"if" "else" |
"while" |
"do" "while" ";" |
"{" { } "}" |
";" |
";"
::= "(" ")"
::= | "="
::= | "<"
::= | "+" | "-"
::= | |
::= "a" | "b" | "c" | "d" | ... | "z"
::=
```

#### Example:

```bash
go build
echo "{ i=125; j=100; while (i-j) if (i