Skip to content

Instantly share code, notes, and snippets.

@crguezl
Created April 7, 2014 11:51
Show Gist options
  • Save crguezl/10018897 to your computer and use it in GitHub Desktop.
Save crguezl/10018897 to your computer and use it in GitHub Desktop.
Grammar for the PL= language in Jison
%token IDENT CONST VAR PROCEDURE COMPARISON expression NUMBER
%token CALL BEGIN END IF THEN WHILE DO ODD
%%
program
: block "."
;
block
: const var procedure statement
;
const
: /* empty */
| CONST IDENT "=" NUMBER ";" const
;
var
: /* empty */
| VAR identlist ";" var
;
identlist
: IDENT
| identlist "," IDENT
;
procedure
: /* empty */
| PROCEDURE IDENT ";" block ";" procedure
;
statement
: IDENT ":=" expression
| CALL IDENT
| BEGIN statements END
| IF condition THEN statement
| WHILE condition DO statement
;
statements
: statement
| statement ";" statements
;
condition
: ODD expression
| expression COMPARISON expression
;
/* expression as in the calculator example */
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment