-
Notifications
You must be signed in to change notification settings - Fork 0
/
PLATYPUS Grammar Specification.txt
328 lines (230 loc) · 8.03 KB
/
PLATYPUS Grammar Specification.txt
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
# PLATYPUS Language Specification
### 2.1 Input Elements and Tokens
<input character> ->
ASCII characters but not SEOF
<input> ->
<input elements> SEOF
<input elements> ->
<input element> | <input elements> <input element>
<token> ->
<variable identifier> | <keyword> | <floating-point literal>
| <integer literal> | <string literal> | <separator> | <operator>
### 2.2 White Space
<white space> ->
ASCII SP character (space)
| ASCII HT character (horizontal tab)
| ASCII VT character (vertical tab)
| ASCII FF character (form feed)
| <line terminator>
<line terminator> ->
CR | LF | CR LF
### 2.3 Comments
<comment> ->
!< <opt_characters in line> <line terminator>
<characters in line> ->
<comment character> | <characters in line> <comment character>
<comment character> ->
<input character> but not <line terminator>
### 2.4 Variable Identifiers
<variable identifier> ->
<arithmetic variable identifier> | <string variable identifier>
<arithmetic identifier> ->
<letter> <opt_letters or digits>
<opt_letters or digits> ->
ε | <letters or digits>
<letters or digits> ->
<letter or digit> | <letters or digits> <letter or digit>
<letter> ->
[a-z] | [A-Z]
<letter or digit> ->
<letter> | <digit>
<string variable identifier> ->
<arithmetic variable identifier>#
### 2.5 Keywords
<keyword> ->
PLATYPUS | IF | THEN | ELSE | USING | REPEAT | INPUT | OUTPUT
### 2.6 Integer Literals
<integer literal> ->
<decimal integer literal> | <octal integer literal>
<decimal integer literal> ->
0 | <non-zero digit> <opt_digits>
<opt_digits> ->
ε | <digits>
<digits> ->
<digit> | <digits> <digit>
<digit> ->
0 | <non-zero digit>
<non-zero digit> -> one of
1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9
<octal integer literal> ->
0 <octal digit> <octal digits>
<octal digit> ->
0 | 1 | 2 | 3 | 4 | 5 | 6 | 7
<octal digits> ->
<octal digit> | <octal digits> <octal digit>
### 2.7 Floating-point Literals
<floating-point literal> ->
<decimal integer literal> . <opt_digits>
### 2.8 String Literals
<opt_string literal> ->
ε | <string literal>
<string literal> ->
"<opt_string characters>"
<opt_string characters> ->
ε | <string characters>
<string characters> ->
<input character> | <string characters> <input character>
### 2.9 Separators
<separator> ->
( | ) | { | } | , | ; | " |.
### 2.10 Operators
<operator> ->
<arithmetic operator> | <string concatenation operator>
| <relational operator> | <logical operator>
| <assignment operator>
<arithmetic operator> ->
+ | - | * | /
<string concatenation operator> ->
<<
<relational operator> ->
> | < | == | <>
<logical operator> ->
.AND. | .OR.
<assignment operator> ->
=
## 3. The PLATYPUS Syntactic Specification
### 3.1 PLATYPUS Program
<program> ->
PLATYPUS {<opt_statements>} SEOF
<opt_statements> ->
ε | <statements>
<statements> ->
<statement> | <statements> <statement>
### 3.2 Statements
<statement> ->
<assignment statement>
| <selection statement>
| <iteration statement>
| <input statement>
| <output statement>
### 3.3 Assignment Statement
<assignment statement> ->
<assignment expression> ;
<assignment expression> ->
<arithmetic variable identifier> = <arithmetic expression>
| <string variable identifier> = <string expression>
#### 3.2.2 Selection Statement (`if` statement)
<selection statement> ->
IF (<conditional expression>) THEN <opt_statements>
ELSE {<opt_statements>};
#### 3.2.3 Iteration Statement (the loop statement)
<iteration statement> ->
USING (<assignment expression> , <conditional expression>, <assignment expression>) REPEAT { <opt_statements> };
#### 3.2.4 Input Statement
<input statement> ->
INPUT (<variable list>);
<opt_variable list> ->
ε | <variable list>
/** New Variable List version below
<variable list> ->
<variable identifier> | <variable list>,<variable identifier>
**/
<variable list> ->
<variable identifier> <variable list'>
<variable list'> ->
, <variable identifier> <variable list'> | E
#### 3.2.5 Output Statement
<output statement> ->
OUTPUT(<opt_variable list> | <opt_string literal>);
### 3.3 Expressions
#### 3.3.1 Arithmetic Expressions
<arithmetic expression> ->
<unary arithmetic expression>
| <additive arithmetic expression>
<unary arithmetic expression> ->
- <primary arithmetic expression>
| + <primary arithmetic expression>
/** New Version of Additive Arithmetic Expressions below
<additive arithmetic expression> ->
<additive arithmetic expression> + <multiplicative arithmetic expression>
| <additive arithmetic expression> - <multiplicative arithmetic expression>
| <multiplicative arithmetic expression>
**/
<additive arihtmetic expression> ->
<multiplicative arithmetic expression> <additive arithmetic expression'>
<additive arithmetic expression'> ->
+ <multiplicative arithmetic expression> <additive arithmetic expression'>
| - <multiplicative arithmetic expression> <additive arithmetic expression'>
/** New Version of Mult. Arithmetic Expressions below
<multiplicative arithmetic expression> ->
<multiplicative arithmetic expression> * <primary arithmetic expression>
| <multiplicative arithmetic expression> / <primary arithmetic expression>
| <primary arithmetic expression>
**/
<multiplicative arithmetic expression> ->
<primary arithmetic expression> <multiplicative arithmetic expression'>
<multiplicative arithmetic expression'> ->
* <primary arithmetic expression> <multiplicative arithmetic expression'>
| / <primary arithmetic expression> <multiplicative arithmetic expression'>
<primary arithmetic expression> ->
<variable identifier>
| <floating-point literal>
| <integer literal>
| (<arithmetic expression>)
#### 3.3.2 String Expression
/** New version of String Expressions below
<string expression> ->
<primary string expression>
| <string expression> << <primary string expression>
**/
<string expression> ->
<primary string expression> <string expression'>
<string expression'> ->
<< <primary string expression> <string expression'> | E
<primary string expression> ->
<string variable identifier>
| <string literal>
#### 3.3.3 Conditional Expression
<conditional expression> ->
<logical OR expression>
/** New Logical OR and Logical AND expressions below
<logical OR expression> ->
<logical AND expression>
| <logical OR expression> .OR. <logical AND expression>
<logical AND expression> ->
<relational expression>
| <logical AND expression> .AND. <relational expression>
**/
<logical OR expression> ->
<logical AND expression> <logical OR expression'>
<logical OR expression'> ->
.OR. <logical AND expression> <logical OR expression'>
<logical AND expression> ->
<relational expression> <logical AND expression'>
<logical AND expression'> ->
.AND. <relational expression> <logical AND expression'>
#### 3.3.4 Relational Expressions
/** New version of Relational expressions below
<relational expression> ->
<primary a_relational expression> <relational operator> <primary a_relational expression>
| <primary s_relational expression> <relational operator> <primary s_relational expression>
**/
<relational expression> ->
<primary a_relational expression> <primary a_relational expression'>
| <primary s_relational expression> <primary s_relational expression'>
<primary a_relational expression> ->
<floating-point literal>
| <integer literal>
| <variable identifier>
<primary a_relational expression'> ->
== <primary a_relational expression>
| <> <primary a_relational expression>
| > <primary a_relational expression>
| < <primary a_relational expression>
<primary s_relational expression> ->
<string literal> | <string variable identifier>
<primary s_relational expression'> ->
== <primary s_relational expression>
| <> <primary s_relational expression>
| > <primary s_relational expression>
| < <primary s_relational expression>