https://github.com/xplshn/cbc
C B Compiler, a working B compiler that is fully compliant with B, with nice warnings and errors, configurable via standard flags like -W/-Wno, and -F and -Fno to turn on/off warns/features. -std=B/-std=Bx for some extensions. Compatible with tsoding/b
https://github.com/xplshn/cbc
b blang c c11 compiler compiler-design language qbe suckless unix
Last synced: 3 months ago
JSON representation
C B Compiler, a working B compiler that is fully compliant with B, with nice warnings and errors, configurable via standard flags like -W/-Wno, and -F and -Fno to turn on/off warns/features. -std=B/-std=Bx for some extensions. Compatible with tsoding/b
- Host: GitHub
- URL: https://github.com/xplshn/cbc
- Owner: xplshn
- License: isc
- Created: 2025-07-18T23:21:00.000Z (6 months ago)
- Default Branch: master
- Last Pushed: 2025-08-13T02:58:10.000Z (5 months ago)
- Last Synced: 2025-08-13T04:27:20.690Z (5 months ago)
- Topics: b, blang, c, c11, compiler, compiler-design, language, qbe, suckless, unix
- Language: C
- Homepage:
- Size: 336 KB
- Stars: 4
- Watchers: 0
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
> __GBC__ - Go B Compiler - https://github.com/xplshn/gbc
>
> A much more capable and self-contained B compiler, written using modernc.org/libqbe
---
# (cbc) | The C B Compiler
This compiler is a project aiming to make a valid B compiler, with _optional_ extensions for C interoperability, and a modules system like Go's
```
]~/Documents/TrulyMine/cbc@ ./cbc
Copyright (c) 2025: xplshn and contributors
For more details refer to
Synopsis
./cbc [options] ...
Description
A compiler for the B programming language and its extensions.
Options
-o Place the output into .
-h, --help Display this information.
-std= Specify language standard (B, Bx). Default: Bx
-pedantic Issue all warnings demanded by the current B std.
Warning Flags
-Wall Enable most warnings.
-Wno-all Disable all warnings.
-W Enable a specific warning.
-Wno- Disable a specific warning.
Available warnings:
c-escapes Using C-style '\' escapes instead of B's '*' [x]
b-escapes Using historical B-style '*' escapes instead of C's '\' [x]
b-ops Using historical B assignment operators like '=+' [x]
c-ops Using C-style assignment operators like '+=' in -std=B mode [x]
unrecognized-escape Using unrecognized escape sequences [x]
truncated-char Character escape value is too large for a byte and has been truncated [x]
long-char-const Multi-character constant is too long for a word [x]
c-comments Using non-standard C-style '//' comments [-]
overflow Integer constant is out of range for its type [x]
pedantic Issues that violate the current strict -std= [-]
unreachable-code Unreachable code [x]
extra Extra warnings (e.g., poor choices, unrecognized flags) [x]
Feature Flags
-F Enable a specific feature.
-Fno- Disable a specific feature.
Available features:
extrn Allow the 'extrn' keyword [x]
asm Allow the '__asm__' keyword and blocks [x]
b-escapes Recognize B-style '*' character escapes [x]
c-escapes Recognize C-style '\' character escapes [x]
b-compound-assign Recognize B-style assignment operators like '=+' [x]
]~/Documents/TrulyMine/cbc@
```
The project is currently in its infancy, and the long-term goals are very ambitious. This is the current roadmap:
> ##### ROADMAP
>
> ###### (i) Tests
> * ~~Make a script that takes the tests from [tsoding/b](https://github.com/tsoding/b), and filters the tests.json to only include the IR tests~~
> * Make a Go program that runs each test, displays the passing/failing ones
>
> ###### (ii) Compatibility with [tsoding/b](https://github.com/tsoding/b)
> 1. ~~Support the "extrn" keyword, as well as inline assembly~~
> 2. ~~Use the same warning & error messages [tsoding/b](https://github.com/tsoding/b)~~ / our warnings n errors are much better
> 3. ~~Be able to pass the IR tests of [tsoding/b](https://github.com/tsoding/b)~~
>
> ###### (iii) Packages / Modules inspired by Go
> * ¿.. Namespaces based on .mod file ..?
> * Implement a way to import/export symbols from different .B files, in different namespaces
>
### Contributions are hyper-mega welcome
##### References
- https://research.swtch.com/b-lang
- https://www.nokia.com/bell-labs/about/dennis-m-ritchie/kbman.html
- https://www.nokia.com/bell-labs/about/dennis-m-ritchie/bref.html
- https://www.nokia.com/bell-labs/about/dennis-m-ritchie/btut.html
- https://github.com/Spydr06/BCause
- https://github.com/kparc/bcc
###### Not B-related, but I did find these helpful for learning how to write the compiler:
- [comp-bib](https://c9x.me/compile/bib/): "Resources for Amateur Compiler Writers"
- [qcc](https://c9x.me/qcc): dead-simple C compiler
- [cproc](https://github.com/michaelforney/cproc): QBE-backed compiler written in C99, with support for some C23 & GNU C extensions
###### Cool stuff used by this project:
- [QBE](https://c9x.me/compile/): The QBE compiler backend
---
###### TODO: ...I should write a Limbo compiler when I finish this project...