Skip to content

damiansire/pascal-toolchain

Repository files navigation

pascal-toolchain

CI

A Pascal compiler frontend written in TypeScript, organized as an npm-workspaces monorepo. Each stage is published as its own npm package, but they evolve together here.

The pipeline

source.pas
   │
   ▼
┌──────────────────┐  tokens  ┌───────────────┐   AST   ┌────────────────────┐  JS
│ pascal-tokenizer │ ───────▶ │ pascal-parser │ ──────▶ │ pascal-js-compiler │ ────▶ output.js
└──────────────────┘          └───────────────┘         └────────────────────┘
   │ tokens
   ▼
┌────────────────────────┐
│ pascal-code-formatter   │ ──▶ pretty Pascal
└────────────────────────┘

Packages

Package npm Description
pascal-tokenizer npm Lexer: turns Pascal source into a token stream.
pascal-parser npm Builds an AST from the token stream.
pascal-js-compiler npm Code generation: emits JavaScript from the AST.
pascal-code-formatter npm Pretty-prints / formats Pascal source.

The pipeline is now complete end to end: pascal-js-compiler closes it by turning the parser's AST into runnable JavaScript.

Playground

Try it live →

playground/ is an interactive web app: type Pascal and watch the tokens, AST, formatted source and compiled JavaScript update live — then hit Run to execute the compiled output in the browser. Its editor is syntax-highlighted by the toolchain's own tokenizer.

Run it locally:

cd playground && npm install && npm run dev

Development

npm install         # install all workspace deps (links packages together)
npm run build       # build every package
npm test            # run every package's tests

Supported Pascal subset

The toolchain currently parses and compiles a usable procedural subset:

  • program, const, var, and procedure / function (with by-value parameters, local declarations, and recursion). var (by-reference) parameters are parsed but not compiled: the code generator rejects them rather than emit code that silently fails to propagate mutations to the caller.
  • statements: assignment (:=), if/then/else, while, for..to/downto, repeat..until, case..of, begin..end, and procedure calls
  • expressions with full precedence, parentheses, and the operators + - * /, div, mod, and, or, not (boolean operands only — the bitwise integer overload of and/or/not is not supported), and the relational set
  • one-dimensional arrays (array[lo..hi] of T) with 1-based indexing
  • writeln / write mapped to console.log / process.stdout.write

See ROADMAP.md for what's next (records, multi-dim arrays, …).

Releasing

Versioning and publishing are handled with Changesets; each package keeps its own version and is published under its own unique name.

npm run changeset          # describe the change + bump
npm run version-packages   # apply version bumps
npm run release            # build + publish changed packages

License

MIT © Damian Sire

About

A Pascal compiler frontend (tokenizer, parser, and code formatter) written in TypeScript.

Topics

Resources

License

Stars

1 star

Watchers

0 watching

Forks

Packages

 
 
 

Contributors