Home

Awesome

Budget Pascal

A compiler for a small subset of Pascal (hence, "budget") to WebAssembly. Demo & blog.

Why Pascal?

When I was reorganizing my files, I found a hangman game that my friends and I wrote 10 years ago for a programming class project. I think it would be fun to try to compile and run it on the web.

Why WebAssembly?

I want something that can run on the web for easy demo, and compiling pascal to web assembly seems more challenging and fun than "just" making a custom VM or transpiling to javascript.

Building & Running

  1. Make sure to have node and yarn installed
  2. Run yarn install to install all dependencies
  3. Run yarn build to build the CLI, or yarn build-web for the web version.
  4. To use the CLI, run yarn start [pascal filename]. To use the web UI, just serve directory dist/web using serve or other http server.

Which Subset of Pascal?

Because implementing full-blown Pascal is really time consuming, I decided to just implement at least what I need to run that hangman game. What is and what is not included will seem arbitrary but I tried my best to include some basic features. I also try to make sure that the compiler compiles a strictly subset of Pascal, meaning if a program is successfully compiled by this compiler, it should also be successfully compiled in other major Pascal compilers like FreePascal.

If you actually need to compile Pascal codes to webassembly, I suggest first to use FreePascal to compile WebAssembly with LLVM.

Implemented data types:

Notable datatypes that didn't get included (non-exhaustive):

Implemented expressions, statements and other language constructs:

Notable language constructs that didn't get included (non-exhaustive):

Other limitation and details: