PL0 interpreter implemented in Rust
This project is to make me more familiar with Rust. It works right now, but maybe doesn't work well in some cases.
Welcome to any contribution, if you can READ (yes, it's not even readable) the project.
Wait, what is it, the PL/0? From Wikipedia:
PL/0 is a programming language, intended as an educational programming language, that is similar to but much simpler than Pascal, a general-purpose programming language.
It's EBNF representation is like:
program = block "." .
block = [ "const" ident "=" number {"," ident "=" number} ";"]
[ "var" ident {"," ident} ";"]
{ "procedure" ident ";" block ";" } statement .
statement = [ ident ":=" expression | "call" ident
| "?" ident | "!" expression
| "begin" statement {";" statement } "end"
| "if" condition "then" statement
| "while" condition "do" statement ].
condition = "odd" expression |
expression ("="|"#"|"<"|"<="|">"|">=") expression .
expression = [ "+"|"-"] term { ("+"|"-") term}.
term = factor {("*"|"/") factor}.
factor = ident | number | "(" expression ")".
There is a simple Virtual Machine(vm) in vm.rs
to execute the "code" generated.
And a parser in compile
to parse and generate vm code.
The lexer using in this project is Logos.
cargo build
cargo run <pl/0-file-path>
The output will be there.
Up to now, only the all samples can be run correctly (Congratulation) !!!sample1.pl0
and sample5.pl0
can be correctly executed and give the right output (WHAT A PITY).
There are some tests(unit test/integration test) in the project.
You can run them with
cargo test
Some of them might be broken by my latest commits. So, please be patient. All of them should be passed :)
sample/sample0.pl0
)