-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmpl.y
119 lines (110 loc) · 2.08 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
109
110
111
112
113
114
115
116
117
118
119
%{
#include <stdio.h>
#include <stdlib.h>
int yylex();
void yyerror(const char *str)
{
fprintf(stderr, "error: %s\n", str);
exit(0);
}
%}
%token INTEGER FLOAT CHARACTER
%token THINGS VAR DEFINE
%token OR AND
%token B JBE S JSE JE JNE
%token MULT DIV PLS MNS
%token LBRACKET RBRACKET LCURLBRACKET RCURLBRACKET ENDLINE
%token QUIT START END MOM
%token OUTPUT INPUT
%token WHITE DARK GREY
%token LOOPWHL DONE
%left OR
%left AND
%left B JBE S JSE JE JNE
%left PLS MNS
%left MULT DIV
%%
program:
START declarations MOM statements END
;
declarations:
declaration
| declaration declarations
;
declaration:
THINGS VAR ENDLINE
;
statements:
statement
| statement statements
;
statement:
assignment
| QUIT ENDLINE
| OUTPUT expression ENDLINE
| conditional
| loopwhl
;
assignment://+
VAR DEFINE expression ENDLINE
| VAR DEFINE INPUT ENDLINE
;
expression:
const
| VAR
| expression OR expression
| expression AND expression
| expression B expression
| expression JBE expression
| expression S expression
| expression JSE expression
| expression JE expression
| expression JNE expression
| expression PLS expression
| expression MNS expression
| expression MULT expression
| expression DIV expression
| LBRACKET expression RBRACKET
;
const://+
INTEGER
| FLOAT
| CHARACTER
;
conditional:
WHITE LBRACKET expression RBRACKET LCURLBRACKET
statements
RCURLBRACKET
DONE
| WHITE LBRACKET expression RBRACKET LCURLBRACKET
statements
RCURLBRACKET
DARK LCURLBRACKET
statements
RCURLBRACKET
DONE
| WHITE LBRACKET expression RBRACKET LCURLBRACKET
statements
RCURLBRACKET
GREY LBRACKET expression RBRACKET LCURLBRACKET
statements
RCURLBRACKET
DARK LCURLBRACKET
statements
RCURLBRACKET
DONE
;
loopwhl:
LOOPWHL LBRACKET expression RBRACKET
LCURLBRACKET
statements
RCURLBRACKET
DONE
;
%%
int main()
{
yyparse();
printf("OK!\n");
return 0;
}