A new compiler that can compile natural languages. Support simple arithmetic options based on numbers and floats. A file with natural language will be compiled as assembly code (x86_64 with FPU) and calculate results.
<expr>:
| let <bindings> in <expr>
| if <expr>: <expr> else: <expr>
| <decls> in <expr>
| <binop-expr>
<binop-expr>:
| IDENTIFIER
| NUMBER
| FLOAT
| true
| false
| !<binop-expr>
| <prim1>(<expr>)
| <expr> <prim2> <expr>
| IDENTIFIER(<exprs>)
| IDENTIFIER()
| (<expr>)
<prim1>:
| add1 | sub1
| print | isbool | isnum | isfloat
| cos | sqrt
<prim2>:
| + | - | * | / | //
| < | > | <= | >=
| ==
| && | ||
<decls>:
| <decls> and <decl>
| <decl>
<decl>:
| def IDENTIFIER(<ids>): <expr>
| def IDENTIFIER(): <expr>
<ids>:
| IDENTIFIER
| IDENTIFIER, <ids>
<exprs>:
| <expr>
| <expr>, <exprs>
<bindings>:
| IDENTIFIER = <expr>
| IDENTIFIER = <expr>, <bindings>
To install rustc
, run
sudo apt-get install rustc
To run the code, run
cargo run
To compile a program and emit assembly code to stdout use
snake INPUT_FILE
To compile a program, link it and run the produced binary use
snake --run INPUT_FILE
To run the reference interpreter use
snake --interp INPUT_FILE
To see this usage message run
snake --help
To test the examples in ./examples/
, run
cargo test
To add new tests, add new mk_test!
and mk_fail_test!
in ./tests/examples.rs
See in ./new_proposal.pdf