1
0
Fork
You've already forked bmc
0
toy compiler targeting the bonsai lehrcomputer
  • Rust 100%
Find a file
2026年02月01日 18:37:03 +01:00
basm it kinda works (we just use a lot more than 64 bytes) 2026年02月01日 14:52:40 +01:00
bcmp it kinda works (we just use a lot more than 64 bytes) 2026年02月01日 14:52:40 +01:00
cli it kinda works (we just use a lot more than 64 bytes) 2026年02月01日 14:52:40 +01:00
.gitignore add gitignore 2025年08月13日 13:56:12 +02:00
Cargo.lock prepare dependencies 2026年01月26日 11:53:27 +01:00
Cargo.toml move stuff to cli and remove dbg prints from parser 2026年01月23日 12:33:22 +01:00
demo.bmc update testfiles 2025年09月22日 20:30:04 +02:00
pda.txt work on pda 2025年09月12日 16:05:40 +02:00
README.md update grammar 2026年02月01日 18:37:03 +01:00
test.basm update demo file format 2026年01月30日 17:00:04 +01:00
test.bmc it kinda works (we just use a lot more than 64 bytes) 2026年02月01日 14:52:40 +01:00

bmc

toy compiler for the bonsai lehrcomputer

learning resources

https://norasandler.com/2017/11/29/Write-a-Compiler.html

noch ein link: https://craftinginterpreters.com/parsing-expressions.html

und: https://craftinginterpreters.com/compiling-expressions.html

und: https://web.stanford.edu/class/cs143/lectures/lecture06.pdf

"porth" von alexey kutepov: https://gitlab.com/tsoding/porth

CFGs: https://iccl.inf.tu-dresden.de/w/images/6/6d/FS2025-Vorlesung-11-print.pdf

instructions

inc 00
dec 01
jmp 10
tst 11

sim: https://bonsai.inf-schule.de/assembler/

https://github.com/KlausMerkert/Bonsai

EBNF

https://en.wikipedia.org/wiki/Extended_Backus%E2%80%93Naur_form

frontend lang

letter = "A" | "B" | "C" | "D" | "E" | "F" | "G"
 | "H" | "I" | "J" | "K" | "L" | "M" | "N"
 | "O" | "P" | "Q" | "R" | "S" | "T" | "U"
 | "V" | "W" | "X" | "Y" | "Z" | "a" | "b"
 | "c" | "d" | "e" | "f" | "g" | "h" | "i"
 | "j" | "k" | "l" | "m" | "n" | "o" | "p"
 | "q" | "r" | "s" | "t" | "u" | "v" | "w"
 | "x" | "y" | "z" ;
digit = "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9" ;
operator = "==" | "!=" ;
terminator = ";" ;
S = { " " | "\n" | "\t" } ;
identifier = { letter } ;
value = { digit } ;
expr = value | identifier ;
var = "let", S, identifier, S, "=", S, value, terminator ;
stmt = "(", expr, S, operator, S, expr, ")" ;
ifstmt = "if", S, stmt, S, block ;
block = "{", { var | ifstmt }, "}" ;
grammar = { block } ;

backend lang

letter = "A" | "B" | "C" | "D" | "E" | "F" | "G"
 | "H" | "I" | "J" | "K" | "L" | "M" | "N"
 | "O" | "P" | "Q" | "R" | "S" | "T" | "U"
 | "V" | "W" | "X" | "Y" | "Z" | "a" | "b"
 | "c" | "d" | "e" | "f" | "g" | "h" | "i"
 | "j" | "k" | "l" | "m" | "n" | "o" | "p"
 | "q" | "r" | "s" | "t" | "u" | "v" | "w"
 | "x" | "y" | "z" ;
digit = "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9" ;
label = ":", { letter }, ":" ;
instruction = "inc" | "dec" | "jmp" | "tst" ;
line = [ label ] | [ instruction ], digit ;
grammar = { line } ;