Created
April 7, 2014 11:51
-
-
Save crguezl/10018897 to your computer and use it in GitHub Desktop.
Grammar for the PL= language in Jison
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%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