A program that compiles a simple imperative language into bcomp-ng assembler
bcompc #input from stdin, output to stdout
bcompc input.bc #output to stdout
bcompc input.bc output.asmPerhaps the required version is built already on the releases page
Open the project directory and type (will need cabal and ghc installed)
cabal installGo-like syntax
a := 3 /*comment*/
b := 45 //line comment
while a <= 6 {
a = a + 2
}
if a != 16 {
a = <<a + (a & b) - (a | b) + >>a + (-a) + ~b
} else {
a = -4
}
goto skip
a = 0
skip:
return a + b
All values represent integer signed 16 bit numbers (int16)
{var} := {expr}- assignment operator{var} = {expr}- modifying operatorgoto {label}- continues execution from the given label{label}:- label to which goto jumpsreturn {expr}- puts the result of the expression into the AC register and stops execution with HLTif {logic_expr} {stmts} [else {stmts}]- conditional executionwhile {logic_expr} {stmts}- preconditioned loop
{expr} == {expr}- equally{expr} != {expr}- not equal{expr} > {expr}- greater{expr} < {expr}- lower{expr} >= {expr}- greater or equally{expr} <= {expr}- lower or equally
+{expr}- does nothing-{expr}- negative value~{expr}- bitwise not<<{expr}- bitwise left shift (*2)>>{expr}- bitwise right shift (/2){expr} + {expr}- sum{expr} - {expr}- difference{expr} | {expr}- bitwise or{expr} & {expr}- bitwise and