https://github.com/irishbruse/blang
B compiler written in C#
https://github.com/irishbruse/blang
aot-compilation b blang compiler dotnet dotnet-10 dotnet-aot qbe
Last synced: about 2 months ago
JSON representation
B compiler written in C#
- Host: GitHub
- URL: https://github.com/irishbruse/blang
- Owner: IrishBruse
- Created: 2021-09-23T21:46:36.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2025-11-16T19:10:19.000Z (7 months ago)
- Last Synced: 2025-11-16T20:21:58.526Z (7 months ago)
- Topics: aot-compilation, b, blang, compiler, dotnet, dotnet-10, dotnet-aot, qbe
- Language: C#
- Homepage:
- Size: 938 KB
- Stars: 2
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: Readme.md
Awesome Lists containing this project
README
# B Compiler
Implementing B in C# with qbe backend
## Quickstart
Run the HelloWorld example
`❯ ./bc run Examples/HelloWorld.b`
```
Hello, World
```
## Help
`❯ ./bc --help`
```
Description:
Compiler for the b programming lanaugage
Usage:
bc [command] [options]
Arguments:
Path to b file to build
Options:
--tokens Print tokenizers tokens
--symbols Print symbol table
--ast Dump compiler ast information
-v, --verbose Verbose output
-vv Very Verbose output
-?, -h, --help Show help and usage information
--version Show version information
Commands:
run Run .b file
test Test compiler output
```
## Testing
Run all the compiler tests
`❯ ./bc test`
```shell
✓ Tests/ok/comments.b (33ms)
✓ Tests/ok/empty.b (15ms)
✓ Tests/ok/helloworld.b (20ms)
✓ Tests/ok/integer.b (18ms)
✓ Tests/ok/pointers.b (18ms)
✓ Tests/ok/Statement/auto.b (15ms)
✓ Tests/ok/Statement/extrn.b (15ms)
✓ Tests/ok/Statement/function.b (16ms)
✓ Tests/ok/Statement/functionCall.b (16ms)
✓ Tests/ok/Statement/if.b (20ms)
✓ Tests/ok/Statement/ifelse.b (17ms)
✓ Tests/ok/Statement/while.b (16ms)
```
## Currently Implemented
- [x] function definitions
- [x] extrn
- [x] function calls
- [x] auto
- [x] variable assignment
- [x] math `foo = (1 + 2 * 3)` foo = 7
- [x] Global variables
- [x] if
- [x] else
- [x] while
- [x] pointers \* &
- [x] Array index [i]
- [ ] switch
## Targets
- qbe
## Dev Setup
- Dotnet 8
- QBE executable either build from source or use the linux-x86_64 one in `misc/qbe`
- cd into the BLang folder in the repo and run
- `dotnet run -- run '../Examples/HelloWorld.b'`
## References
- [QBE Docs](https://c9x.me/compile/doc/il.html)
- [tsoding/b](https://github.com/tsoding/b)
- [kbman](https://www.nokia.com/bell-labs/about/dennis-m-ritchie/kbman.html)