Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/varbhat/bast
Compiler for Tiny Toy BASIC Dialect
https://github.com/varbhat/bast
basic compiler golang golang-application
Last synced: 2 months ago
JSON representation
Compiler for Tiny Toy BASIC Dialect
- Host: GitHub
- URL: https://github.com/varbhat/bast
- Owner: varbhat
- License: mit
- Created: 2020-07-28T16:15:45.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2022-01-18T14:18:11.000Z (almost 3 years ago)
- Last Synced: 2024-06-20T12:02:18.292Z (7 months ago)
- Topics: basic, compiler, golang, golang-application
- Language: Go
- Homepage:
- Size: 33.2 KB
- Stars: 5
- Watchers: 2
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
bast
Compiler for BAST(Basic Tiny) - A Tiny Toy Basic Dialect
## Introduction
This compiler takes code written in bast and compiles(transpiles) to C code.You need to compile the C code with C compiler (gcc/tcc/clang are tested to work) to produce executable.This provided the opportunity to learn about lexing,parsing and to learn more Golang. I believe that this toy language will not be used other than for educational purpose(for people like past-me).
## Installation
You can download binary for your OS from [Releases](https://github.com/varbhat/bast/releases/latest) . Also , if you have [Go](https://golang.org/) installed , you can install `bast` by typing this in terminal.```bash
go install github.com/varbhat/bast@latest
```## Usage
* `bast --help` will print the help.
* `bast -in=filename.bast -out=filename.c` will compile bast source `filename.bast` to C source `filename.c`.
* You need to compile the emitted C file with C compiler like GCC/Clang/TCC.
* `cc ./filename.c -o filename` (where cc is gcc/clang/tcc)
* You can combine these steps :
```bash
bast -in=filename.bast -out=filename.c && cc filename.c -o filename
```And then run the executable binary `filename` it produced.
## Language
Language is small Dialect of BASIC same what AZHenly implemented.I only wrote compiler.
Grammer file can be found at [grammer.txt](https://github.com/varbhat/bast/blob/master/grammar.txt)It supports:
- Numerical variables
- Basic arithmetic
- If statements
- While loops
- Print text and numbers
- Input numbers
- Labels and goto
- Comments## Example code
```
PRINT "How many fibonacci numbers do you want?"
INPUT nums
PRINT ""LET a = 0
LET b = 1
WHILE nums > 0 REPEAT
PRINT a
LET c = a + b
LET a = b
LET b = c
LET nums = nums - 1
ENDWHILE
```
You can find more examples at [Examples](https://github.com/varbhat/bast/tree/master/examples)## Acknowledgements
Thanks to [AZHenly](https://github.com/AZHenley) for their post [Let's make a Teeny Tiny compiler](http://web.eecs.utk.edu/~azh/blog/teenytinycompiler1.html) which acted as reference.
But , instructions in that post are for Python and the compiler is implemented in Python. I who wanted to know more about compiler , read it as reference , wrote the compiler from scratch in Golang.Although the language for both the compilers are same,`bast` compiler is written from scratch in Golang ,implemented by instructions of their post.
## License
[MIT](LICENSE)