This is an experimental Pascal .pas to WebAssembly text-format .wat compiler written in Rust.
- make SEMICOLON optional (no reason to require in input since omitted in webassembly)
- use func export for procedures (callable within module)
- see data.wat and data.js for implementing string using memory
Install Rust and Cargo, then:
-
cargo testto run unit tests -
cargo run <filename>.pasto run the compiler with<filename>.pasas input, output is<filename>.wat
The generated file is in WebAssembly text-format, test using wat2wasm online tool, or WebAssembly Binary Toolkit:
-
build the WebAssembly Binary Toolkit, make wat2wasm executable, and add to PATH, i.e.
export PATH=$PATH:/path/to/wat2wasm -
wat2wasm <filename>.watto compile text-format into binary format, output is<filename>.wasm -
wat2wasm <filename>.wat -vto view the binary format
For example, to compile the file test.pas and view output in binary format:
cargo run test.pas; wat2wasm test.wat -v
The compiler can be verbose:
- set
DEBUGas true to enter debug mode - set
DEBUG_WITH_INPUTas true to instruct the compiler to look for input file (otherwise expecting call to functions) - set
DEBUG_SHOW_CHARas true to show characters recognised by the lexer - set
DEBUG_SHOW_CHARas true to show characters recognised by the lexer - set
DEBUG_SHOW_TOKENas true to show tokens consumed by the parser - set
DEBUG_SHOW_TREEas true to show the AST representation of the Pascal program, this is the output from parser - set
DEBUG_SHOW_SYMBOL_TABLEas true to show the symbol table, which contains variable decalarations - set
DEBUG_SHOW_ASSIGNMENT_TABLEas true to show the assignment table, which contains variable assignments used by the evaluator
The compiler can generate verbose code:
- set
OUTPUT_VERBOSEas true to include compiler-related comments in the generated code, this does not include comments in the Pascal program (default is true)
