forked from zaach/jison
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclassy.jison
84 lines (67 loc) · 1.12 KB
/
classy.jison
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/* description: ClassyLang grammar. Very classy. */
/*
To build parser:
$ ./bin/jison examples/classy.jison examples/classy.jisonlex
*/
/* author: Zach Carter */
%right ASSIGN
%left OR
%nonassoc EQUALITY GREATER
%left PLUS MINUS
%left TIMES
%right NOT
%left DOT
%%
pgm
: cdl MAIN LBRACE vdl el RBRACE ENDOFFILE
;
cdl
: c cdl
|
;
c
: CLASS id EXTENDS id LBRACE vdl mdl RBRACE
;
vdl
: VAR t id SEMICOLON vdl
|
;
mdl
: t id LPAREN t id RPAREN LBRACE vdl el RBRACE mdl
|
;
t
: NATTYPE
| id
;
id
: ID
;
el
: e SEMICOLON el
| e SEMICOLON
;
e
: NATLITERAL
| NUL
| id
| NEW id
| THIS
| IF LPAREN e RPAREN LBRACE el RBRACE ELSE LBRACE el RBRACE
| FOR LPAREN e SEMICOLON e SEMICOLON e RPAREN LBRACE el RBRACE
| READNAT LPAREN RPAREN
| PRINTNAT LPAREN e RPAREN
| e PLUS e
| e MINUS e
| e TIMES e
| e EQUALITY e
| e GREATER e
| NOT e
| e OR e
| e DOT id
| id ASSIGN e
| e DOT id ASSIGN e
| id LPAREN e RPAREN
| e DOT id LPAREN e RPAREN
| LPAREN e RPAREN
;