Skip to content
Ayotl

PScript in the browser

A 2021 school compiler brought to the web. You write in a made-up language and C comes out: the same journey a real compiler makes — lexical, syntactic, semantic and code generation — on a page you can poke at.

Compiles with no errors.

No output yet. Press Run.

The language, on one screen

programa            el programa empieza aquí
ent  @x;            entero        dec @y;  decimal      cart @c;  carácter
@x = 3 + 4 * 2;     asignación, con la precedencia de siempre
lec @x;             leer          imp @x;               imprimir

si @x > 10 inicio
  imp @x;
fin sino inicio
  imp 0;
fin endif

mientras @x > 0 hacer
inicio
  @x = @x - 1;
fin

The original is Java with JavaFX and uses an LR parser with hand-built tables; it translates to C and interprets nothing. This version rewrites the parser as recursive descent — same grammar, but readable — and adds an interpreter that didn't exist: without it you'd have to download the C and compile it just to see whether a program does what you thought.

Back in 2021 the hand-in worked exactly like this: compile the program, copy the C that came out, paste it into an online compiler and run it in front of the professor. The button above does that same trip in one click.

The Java original, on GitHub ↗