Skip to content

A browser-based interactive runtime and interpreter for PL/0

Notifications You must be signed in to change notification settings

mxsjoberg/pasrb

Repository files navigation

pasrb: Pascal in Ruby

Experimental


Grammar (PL/0)

Basically wikipedia.org/wiki/PL/0 with some minor modifications.

(* program *)

program = { statement };

statement = assign_stmt | input_stmt | output_stmt | if_stmt | while_stmt ;

assign_stmt = identifier ':=' expr ';';

input_stmt = '?' identifier ';';

output_stmt = '!' expr ';';

(* control flow *)

if_stmt = 'if' condition ('then' | '{') statement ('end' | '}');

while_stmt = 'while' condition ('do' | '{') statement ('end' | '}');

(* condition *)

condition = cond_odd | cond_expr;

cond_odd = 'odd' expr;

cond_expr = expr ('=' | '<' | '>') expr;

(* expression *)

expr = term {('+' | '-') term};

term = factor {('*' | '/') factor};

factor = identifier | number | '(' expr ')';

Examples

Example 1: This example simply increments and outputs x.

x := 0;
while x<5 {
    x := x + 1;
}
!x;

Example 2: This example takes inputs from user (input boxes are automatically generated) and outputs the sum. User inputs currently persists until reloading page (so reload to remove inputs).

x := 0;
y := 0;

?x;
?y;

!(x + y);

Releases

No releases published

Packages

No packages published