-
Notifications
You must be signed in to change notification settings - Fork 0
/
mpl.y
108 lines (91 loc) · 1.71 KB
/
mpl.y
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
%{
#include <stdio.h>
#include <stdlib.h>
int yylex();
void yyerror(const char *str)
{
fprintf(stderr, "error: %s\n", str);
exit(0);
}
%}
%token EXIT DECLARATION MAIN END COMMENT IN OUT
%token TYPE VAR WALRUS ECPHONEME LBRACE RBRACE
%token INTEGER FLOAT CHARACTER
%token OR AND G GE L LE NE E
%token MULT DIV PLUS MINUS
%token LBRACKET RBRACKET THEN ELSE WHENEVER DONE
%left OR
%left AND
%left G GE L LE NE E
%left PLUS MINUS
%left MULT DIV
%%
program:
| DECLARATION declarations MAIN statements END
;
declarations:
declaration
| declaration declarations
;
declaration:
TYPE VAR ECPHONEME
| COMMENT
;
statements:
statement
| statement statements
;
statement:
assignment
| EXIT ECPHONEME
| COMMENT
| OUT expression ECPHONEME
| conditional
| whenever
;
assignment:
VAR WALRUS expression ECPHONEME
| VAR WALRUS IN ECPHONEME
;
expression:
const
| VAR
| expression OR expression
| expression AND expression
| expression G expression
| expression GE expression
| expression L expression
| expression LE expression
| expression E expression
| expression NE expression
| expression PLUS expression
| expression MINUS expression
| expression MULT expression
| expression DIV expression
| LBRACE expression RBRACE
;
const:
INTEGER
| FLOAT
| CHARACTER
;
conditional:
LBRACKET expression RBRACKET THEN
statements
DONE
| LBRACKET expression RBRACKET THEN
statements
ELSE
statements
DONE
;
whenever:
WHENEVER LBRACKET expression RBRACKET statements DONE
;
%%
int main()
{
yyparse();
printf("OK!\n");
return 0;
}