Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/williamfedele/tinycompiler
⚡ Compiler written in Zig for fun
https://github.com/williamfedele/tinycompiler
compiler compiler-design zig ziglang
Last synced: about 1 month ago
JSON representation
⚡ Compiler written in Zig for fun
- Host: GitHub
- URL: https://github.com/williamfedele/tinycompiler
- Owner: williamfedele
- License: mit
- Created: 2024-09-25T03:38:27.000Z (4 months ago)
- Default Branch: main
- Last Pushed: 2024-11-22T21:43:58.000Z (about 2 months ago)
- Last Synced: 2024-11-22T22:31:13.350Z (about 2 months ago)
- Topics: compiler, compiler-design, zig, ziglang
- Language: Zig
- Homepage:
- Size: 31.3 KB
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
⚡ TinyCompiler
A compiler written for fun to learn about Zig.
**Disclaimer**: The grammar, found in `grammar.ebnf`, has not been validated to reject erroneous code. There is also no semantic error handling at the moment so variables are not checked for existence for example. I need to generate a symbol table over the AST before the code generation phase.
## Syntax
The syntax is intentionally simple to make this a Zig learning experience rather than one purely of compiler design. I'm not a compiler engineer, so don't expect big things haha. I may extend it to include other features that are relatively simple like functions.
**Datatypes**: Only integers are valid at the moment.
**Keywords**: _var, int, if, while, end, print_.
### Example Usage
Source file:
```
var x: int = 10;
var y: int;
y = 5*2+1;if (x <= y)
print x;
else
print y;
endwhile (y >= x)
print y;
if (y == 7)
x = x - 1;
end
y = y - 1;
end
```Translated output (python for now):
```py
x = 10
y = 0
y = 5 * 2 + 1
if x <= y:
print(x)
else:
print(y)
while y >= x:
print(y)
if y == 7:
x = x - 1
y = y - 1
```## License
[MIT](https://github.com/williamfedele/tinycompiler/blob/main/LICENSE)