WSC is a transpiler from a readable programming language to the esoteric language Whitespace. Built with OCaml.
NOTE: This does not run whitespace programs; it generates them.
Install OCaml and opam. Install Menhir with
opam install menhir
Build the project with make.
cd <installDirectory>
make
./main.byte <inputFile.wsr>
This will output a whitespace file with a .ws
extension.
A .wsr file must contain a main
function that has no parameters. This is the entry point and where code execution will start.
function fname(arg1, arg2){
<statements>
}
A statement is one of the following:
if(<expression>){
<statements>
}
where expression evaluates to a boolean
if(<expression>){
<statements>
}else{
<statements>
}
where expression evaluates to a boolean
<expression>;
break;
loop <expression> {
<statements>
}
where expression evaluates to a positive integer
while(<expression>) {
<statements>
}
where expression evaluates to a boolean
do {
<statements>
} while(<expression>);
where expression evaluates to a boolean
print_int <expression>;
print_char <expression>;
read_int <variable>;
Reads in an integer and saves it to the variable .
read_char <variable>;
Reads in a character and saves it to the variable .
return <expression>;
An expression is one of the following.
Such as 42
or 0x3B
or 0o123
or 0b101101
Such as 'p'
or ' '
or '\n'
true
or false
Such as x
or foo
or potato
<variable> := <expression>
Example: x := 2 * 2
<expression> + <expression>
<expression> - <expression>
<expression> * <expression>
<expression> / <expression>
<expression> % <expression>
-<expression>
Where all expressions evaluate to integers.
(<expression>)
<expression> && <expression>
<expression> || <expression>
<expression> ^ <expression>
! <expression>
Where all expressions evaluate to booleans.
<expression> < <expression>
<expression> <= <expression>
<expression> > <expression>
<expression> >= <expression>
<expression> == <expression>
<expression> != <expression>
<functionName>(<expression>, <expression>, ...)
Example: double(1)
or foo()
or factorial(5 + 5)
function main(){
print_int factorial(5);
}
function factorial(n){
if(n == 0){
return 1;
}
return n * factorial(n-1);
}
More examples can be seen in the test
folder.
- Boolean short circuiting (and check that booleans work as intended)
- Builtin functions
- Including other files (preprocessor)
- Type checker
- Strings
- Arrays
- Structs / custom objects (to allow for fractions)
- Currently, no optimizations are done by the compiler.
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
Please make sure to test thoroughly.