]>
Commit | Line | Data |
---|---|---|
63b4c5a8 JF |
1 | #ifndef CYPARSER_HPP |
2 | #define CYPARSER_HPP | |
3 | ||
cf7d4c69 | 4 | #include <cstdlib> |
5999c315 | 5 | #include <string> |
c3c20102 | 6 | #include <vector> |
cf7d4c69 | 7 | |
5befe15e | 8 | #include "location.hh" |
5999c315 | 9 | #include "Pooling.hpp" |
924f67b2 | 10 | |
5999c315 JF |
11 | template <typename Type_> |
12 | struct CYNext { | |
13 | Type_ *next_; | |
63b4c5a8 | 14 | |
5999c315 JF |
15 | CYNext() : |
16 | next_(NULL) | |
17 | { | |
18 | } | |
cf7d4c69 | 19 | |
62014ea9 JF |
20 | CYNext(Type_ *next) : |
21 | next_(next) | |
22 | { | |
23 | } | |
24 | ||
5999c315 | 25 | void SetNext(Type_ *next) { |
cf7d4c69 JF |
26 | next_ = next; |
27 | } | |
28 | }; | |
29 | ||
5999c315 JF |
30 | struct CYThing { |
31 | virtual void Output(std::ostream &out) const = 0; | |
32 | }; | |
33 | ||
34 | _finline std::ostream &operator <<(std::ostream &out, const CYThing &rhs) { | |
35 | rhs.Output(out); | |
36 | return out; | |
37 | } | |
38 | ||
39 | struct CYPart { | |
40 | virtual void Part(std::ostream &out) const = 0; | |
63b4c5a8 JF |
41 | }; |
42 | ||
5999c315 | 43 | struct CYSource : |
b1ff2d78 | 44 | CYNext<CYSource> |
5999c315 | 45 | { |
b1ff2d78 | 46 | virtual void Show(std::ostream &out) const; |
5999c315 JF |
47 | virtual void Output(std::ostream &out) const = 0; |
48 | virtual void Output(std::ostream &out, bool block) const; | |
49 | }; | |
50 | ||
51 | struct CYName : | |
52 | CYThing | |
53 | { | |
54 | virtual const char *Name() const = 0; | |
63b4c5a8 JF |
55 | }; |
56 | ||
cf7d4c69 | 57 | struct CYWord : |
cf7d4c69 | 58 | CYName |
63b4c5a8 | 59 | { |
cf7d4c69 JF |
60 | const char *word_; |
61 | ||
62 | CYWord(const char *word) : | |
63 | word_(word) | |
64 | { | |
65 | } | |
66 | ||
5999c315 | 67 | const char *Value() const { |
cf7d4c69 JF |
68 | return word_; |
69 | } | |
70 | ||
71 | virtual const char *Name() const { | |
5999c315 | 72 | return Value(); |
cf7d4c69 | 73 | } |
5999c315 JF |
74 | |
75 | virtual void Output(std::ostream &out) const; | |
63b4c5a8 JF |
76 | }; |
77 | ||
cf7d4c69 JF |
78 | struct CYIdentifier : |
79 | CYWord | |
63b4c5a8 | 80 | { |
5999c315 JF |
81 | CYIdentifier(const char *word) : |
82 | CYWord(word) | |
83 | { | |
cf7d4c69 | 84 | } |
63b4c5a8 JF |
85 | }; |
86 | ||
62014ea9 JF |
87 | struct CYLabel : |
88 | CYNext<CYLabel> | |
89 | { | |
cf7d4c69 | 90 | CYIdentifier *identifier_; |
cf7d4c69 JF |
91 | |
92 | CYLabel(CYIdentifier *identifier, CYLabel *next) : | |
62014ea9 JF |
93 | CYNext<CYLabel>(next), |
94 | identifier_(identifier) | |
cf7d4c69 JF |
95 | { |
96 | } | |
97 | }; | |
98 | ||
99 | struct CYStatement : | |
100 | CYSource | |
63b4c5a8 | 101 | { |
cf7d4c69 JF |
102 | CYLabel *label_; |
103 | ||
104 | void AddLabel(CYIdentifier *identifier) { | |
105 | label_ = new CYLabel(identifier, label_); | |
106 | } | |
107 | }; | |
108 | ||
db5e2840 JF |
109 | enum CYState { |
110 | CYClear, | |
111 | CYRestricted, | |
112 | CYNewLine | |
113 | }; | |
114 | ||
5999c315 JF |
115 | class CYDriver { |
116 | public: | |
117 | CYPool pool_; | |
e7ed5354 | 118 | |
db5e2840 | 119 | CYState state_; |
e7ed5354 JF |
120 | void *scanner_; |
121 | ||
122 | const char *data_; | |
123 | size_t size_; | |
124 | ||
5999c315 | 125 | std::string filename_; |
e7ed5354 | 126 | |
5befe15e JF |
127 | struct Error { |
128 | cy::location location_; | |
129 | std::string message_; | |
130 | }; | |
131 | ||
132 | typedef std::vector<Error> Errors; | |
133 | ||
134 | CYSource *source_; | |
135 | Errors errors_; | |
5999c315 JF |
136 | |
137 | private: | |
138 | void ScannerInit(); | |
139 | void ScannerDestroy(); | |
140 | ||
141 | public: | |
142 | CYDriver(const std::string &filename); | |
143 | ~CYDriver(); | |
144 | }; | |
145 | ||
146 | struct CYForInitialiser : | |
147 | CYPart | |
148 | { | |
cf7d4c69 JF |
149 | }; |
150 | ||
5999c315 JF |
151 | struct CYForInInitialiser : |
152 | CYPart | |
153 | { | |
63b4c5a8 JF |
154 | }; |
155 | ||
cf7d4c69 | 156 | struct CYExpression : |
5999c315 | 157 | CYNext<CYExpression>, |
cf7d4c69 JF |
158 | CYForInitialiser, |
159 | CYForInInitialiser | |
63b4c5a8 | 160 | { |
d35a3b07 | 161 | virtual unsigned Precedence() const = 0; |
5999c315 JF |
162 | virtual void Part(std::ostream &out) const; |
163 | virtual void Output(std::ostream &out) const = 0; | |
d35a3b07 | 164 | void Output(std::ostream &out, unsigned precedence) const; |
63b4c5a8 JF |
165 | }; |
166 | ||
d35a3b07 JF |
167 | #define CYPrecedence(value) \ |
168 | virtual unsigned Precedence() const { \ | |
169 | return value; \ | |
170 | } | |
171 | ||
172 | struct CYCompound : | |
173 | CYExpression | |
174 | { | |
175 | CYExpression *expressions_; | |
176 | ||
177 | CYCompound(CYExpression *expressions) : | |
178 | expressions_(expressions) | |
179 | { | |
180 | } | |
181 | ||
182 | void AddPrev(CYExpression *expression) { | |
183 | CYExpression *last(expression); | |
184 | while (last->next_ != NULL) | |
185 | last = last->next_; | |
186 | last->SetNext(expressions_); | |
187 | expressions_ = expression; | |
188 | } | |
189 | ||
190 | CYPrecedence(17) | |
191 | ||
192 | void Output(std::ostream &out) const; | |
193 | }; | |
5999c315 | 194 | |
cf7d4c69 JF |
195 | struct CYLiteral : |
196 | CYExpression | |
63b4c5a8 | 197 | { |
d35a3b07 | 198 | CYPrecedence(0) |
cf7d4c69 | 199 | }; |
63b4c5a8 | 200 | |
62014ea9 JF |
201 | struct CYSelectorPart : |
202 | CYNext<CYSelectorPart> | |
e7ed5354 JF |
203 | { |
204 | CYWord *name_; | |
205 | bool value_; | |
e7ed5354 | 206 | |
62014ea9 JF |
207 | CYSelectorPart(CYWord *name, bool value, CYSelectorPart *next) : |
208 | CYNext<CYSelectorPart>(next), | |
e7ed5354 | 209 | name_(name), |
62014ea9 JF |
210 | value_(value) |
211 | { | |
212 | } | |
213 | ||
214 | virtual void Output(std::ostream &out) const; | |
215 | }; | |
216 | ||
217 | struct CYSelector : | |
218 | CYLiteral | |
219 | { | |
220 | CYSelectorPart *name_; | |
221 | ||
222 | CYSelector(CYSelectorPart *name) : | |
223 | name_(name) | |
e7ed5354 JF |
224 | { |
225 | } | |
226 | ||
227 | virtual void Output(std::ostream &out) const; | |
228 | }; | |
229 | ||
cf7d4c69 JF |
230 | struct CYString : |
231 | CYLiteral, | |
232 | CYName | |
233 | { | |
234 | const char *value_; | |
5999c315 | 235 | size_t size_; |
cf7d4c69 | 236 | |
5999c315 JF |
237 | CYString(const char *value, size_t size) : |
238 | value_(value), | |
239 | size_(size) | |
cf7d4c69 JF |
240 | { |
241 | } | |
242 | ||
243 | CYString(const CYIdentifier *identifier) : | |
5999c315 JF |
244 | value_(identifier->Value()), |
245 | size_(strlen(value_)) | |
cf7d4c69 JF |
246 | { |
247 | } | |
248 | ||
5999c315 | 249 | const char *Value() const { |
cf7d4c69 JF |
250 | return value_; |
251 | } | |
252 | ||
253 | virtual const char *Name() const { | |
5999c315 | 254 | return Value(); |
63b4c5a8 | 255 | } |
5999c315 JF |
256 | |
257 | virtual void Output(std::ostream &out) const; | |
63b4c5a8 JF |
258 | }; |
259 | ||
cf7d4c69 | 260 | struct CYNumber : |
cf7d4c69 JF |
261 | CYLiteral, |
262 | CYName | |
263 | { | |
5999c315 JF |
264 | double value_; |
265 | ||
266 | CYNumber(double value) : | |
267 | value_(value) | |
268 | { | |
269 | } | |
270 | ||
271 | double Value() const { | |
272 | return value_; | |
cf7d4c69 JF |
273 | } |
274 | ||
275 | virtual const char *Name() const { | |
276 | throw; | |
277 | } | |
5999c315 JF |
278 | |
279 | virtual void Output(std::ostream &out) const; | |
cf7d4c69 JF |
280 | }; |
281 | ||
282 | struct CYNull : | |
283 | CYWord, | |
284 | CYLiteral | |
285 | { | |
286 | CYNull() : | |
287 | CYWord("null") | |
288 | { | |
289 | } | |
5999c315 JF |
290 | |
291 | virtual void Output(std::ostream &out) const; | |
cf7d4c69 JF |
292 | }; |
293 | ||
294 | struct CYThis : | |
295 | CYWord, | |
296 | CYExpression | |
297 | { | |
298 | CYThis() : | |
299 | CYWord("this") | |
300 | { | |
301 | } | |
5999c315 | 302 | |
d35a3b07 JF |
303 | CYPrecedence(0) |
304 | ||
5999c315 | 305 | virtual void Output(std::ostream &out) const; |
cf7d4c69 JF |
306 | }; |
307 | ||
308 | struct CYBoolean : | |
309 | CYLiteral | |
310 | { | |
5999c315 JF |
311 | virtual bool Value() const = 0; |
312 | virtual void Output(std::ostream &out) const; | |
cf7d4c69 JF |
313 | }; |
314 | ||
315 | struct CYFalse : | |
316 | CYWord, | |
317 | CYBoolean | |
318 | { | |
319 | CYFalse() : | |
320 | CYWord("false") | |
321 | { | |
322 | } | |
5999c315 JF |
323 | |
324 | virtual bool Value() const { | |
325 | return false; | |
326 | } | |
cf7d4c69 JF |
327 | }; |
328 | ||
329 | struct CYTrue : | |
330 | CYWord, | |
331 | CYBoolean | |
332 | { | |
333 | CYTrue() : | |
334 | CYWord("true") | |
335 | { | |
336 | } | |
5999c315 JF |
337 | |
338 | virtual bool Value() const { | |
339 | return true; | |
340 | } | |
cf7d4c69 JF |
341 | }; |
342 | ||
343 | struct CYVariable : | |
344 | CYExpression | |
345 | { | |
346 | CYIdentifier *name_; | |
347 | ||
348 | CYVariable(CYIdentifier *name) : | |
349 | name_(name) | |
350 | { | |
351 | } | |
5999c315 | 352 | |
d35a3b07 JF |
353 | CYPrecedence(0) |
354 | ||
5999c315 | 355 | virtual void Output(std::ostream &out) const; |
cf7d4c69 JF |
356 | }; |
357 | ||
358 | struct CYPrefix : | |
63b4c5a8 JF |
359 | CYExpression |
360 | { | |
361 | CYExpression *rhs_; | |
362 | ||
cf7d4c69 | 363 | CYPrefix(CYExpression *rhs) : |
63b4c5a8 JF |
364 | rhs_(rhs) |
365 | { | |
366 | } | |
5999c315 JF |
367 | |
368 | virtual const char *Operator() const = 0; | |
369 | ||
370 | virtual void Output(std::ostream &out) const; | |
63b4c5a8 JF |
371 | }; |
372 | ||
cf7d4c69 | 373 | struct CYInfix : |
63b4c5a8 JF |
374 | CYExpression |
375 | { | |
376 | CYExpression *lhs_; | |
377 | CYExpression *rhs_; | |
378 | ||
cf7d4c69 | 379 | CYInfix(CYExpression *lhs, CYExpression *rhs) : |
63b4c5a8 JF |
380 | lhs_(lhs), |
381 | rhs_(rhs) | |
382 | { | |
383 | } | |
5999c315 JF |
384 | |
385 | virtual const char *Operator() const = 0; | |
386 | ||
387 | virtual void Output(std::ostream &out) const; | |
63b4c5a8 JF |
388 | }; |
389 | ||
cf7d4c69 | 390 | struct CYPostfix : |
63b4c5a8 JF |
391 | CYExpression |
392 | { | |
393 | CYExpression *lhs_; | |
394 | ||
cf7d4c69 | 395 | CYPostfix(CYExpression *lhs) : |
63b4c5a8 JF |
396 | lhs_(lhs) |
397 | { | |
398 | } | |
5999c315 JF |
399 | |
400 | virtual const char *Operator() const = 0; | |
401 | ||
402 | virtual void Output(std::ostream &out) const; | |
63b4c5a8 JF |
403 | }; |
404 | ||
cf7d4c69 | 405 | struct CYAssignment : |
d35a3b07 | 406 | CYExpression |
cf7d4c69 | 407 | { |
d35a3b07 JF |
408 | CYExpression *lhs_; |
409 | CYExpression *rhs_; | |
410 | ||
cf7d4c69 | 411 | CYAssignment(CYExpression *lhs, CYExpression *rhs) : |
d35a3b07 JF |
412 | lhs_(lhs), |
413 | rhs_(rhs) | |
cf7d4c69 JF |
414 | { |
415 | } | |
5999c315 JF |
416 | |
417 | virtual const char *Operator() const = 0; | |
d35a3b07 JF |
418 | |
419 | virtual void Output(std::ostream &out) const; | |
cf7d4c69 JF |
420 | }; |
421 | ||
62014ea9 JF |
422 | struct CYArgument : |
423 | CYNext<CYArgument> | |
424 | { | |
cf7d4c69 JF |
425 | CYWord *name_; |
426 | CYExpression *value_; | |
cf7d4c69 JF |
427 | |
428 | CYArgument(CYWord *name, CYExpression *value, CYArgument *next = NULL) : | |
62014ea9 | 429 | CYNext<CYArgument>(next), |
cf7d4c69 | 430 | name_(name), |
62014ea9 | 431 | value_(value) |
cf7d4c69 JF |
432 | { |
433 | } | |
5999c315 | 434 | |
d35a3b07 | 435 | void Output(std::ostream &out) const; |
cf7d4c69 JF |
436 | }; |
437 | ||
438 | struct CYBlank : | |
439 | public CYWord | |
440 | { | |
441 | CYBlank() : | |
442 | CYWord("") | |
443 | { | |
444 | } | |
445 | }; | |
446 | ||
5999c315 JF |
447 | struct CYClause : |
448 | CYThing, | |
449 | CYNext<CYClause> | |
450 | { | |
cf7d4c69 JF |
451 | CYExpression *case_; |
452 | CYStatement *code_; | |
cf7d4c69 JF |
453 | |
454 | CYClause(CYExpression *_case, CYStatement *code) : | |
455 | case_(_case), | |
456 | code_(code) | |
457 | { | |
458 | } | |
459 | ||
5999c315 | 460 | virtual void Output(std::ostream &out) const; |
cf7d4c69 JF |
461 | }; |
462 | ||
62014ea9 JF |
463 | struct CYElement : |
464 | CYNext<CYElement> | |
465 | { | |
cf7d4c69 | 466 | CYExpression *value_; |
cf7d4c69 JF |
467 | |
468 | CYElement(CYExpression *value, CYElement *next) : | |
62014ea9 JF |
469 | CYNext<CYElement>(next), |
470 | value_(value) | |
cf7d4c69 JF |
471 | { |
472 | } | |
5999c315 | 473 | |
5befe15e JF |
474 | void Output(std::ostream &out) const; |
475 | }; | |
476 | ||
477 | struct CYArray : | |
478 | CYLiteral | |
479 | { | |
480 | CYElement *elements_; | |
481 | ||
482 | CYArray(CYElement *elements) : | |
483 | elements_(elements) | |
484 | { | |
485 | } | |
486 | ||
5999c315 | 487 | virtual void Output(std::ostream &out) const; |
cf7d4c69 JF |
488 | }; |
489 | ||
490 | struct CYDeclaration : | |
5999c315 | 491 | CYThing, |
cf7d4c69 JF |
492 | CYForInInitialiser |
493 | { | |
494 | CYIdentifier *identifier_; | |
495 | CYExpression *initialiser_; | |
496 | ||
497 | CYDeclaration(CYIdentifier *identifier, CYExpression *initialiser) : | |
498 | identifier_(identifier), | |
499 | initialiser_(initialiser) | |
500 | { | |
501 | } | |
5999c315 JF |
502 | |
503 | virtual void Part(std::ostream &out) const; | |
504 | virtual void Output(std::ostream &out) const; | |
cf7d4c69 JF |
505 | }; |
506 | ||
507 | struct CYDeclarations : | |
508 | CYStatement, | |
509 | CYForInitialiser | |
510 | { | |
511 | CYDeclaration *declaration_; | |
512 | CYDeclarations *next_; | |
513 | ||
514 | CYDeclarations(CYDeclaration *declaration, CYDeclarations *next) : | |
515 | declaration_(declaration), | |
516 | next_(next) | |
517 | { | |
518 | } | |
5999c315 JF |
519 | |
520 | virtual void Part(std::ostream &out) const; | |
521 | virtual void Output(std::ostream &out) const; | |
cf7d4c69 JF |
522 | }; |
523 | ||
5999c315 | 524 | struct CYParameter : |
62014ea9 | 525 | CYNext<CYParameter>, |
5999c315 JF |
526 | CYThing |
527 | { | |
cf7d4c69 | 528 | CYIdentifier *name_; |
cf7d4c69 JF |
529 | |
530 | CYParameter(CYIdentifier *name, CYParameter *next) : | |
62014ea9 JF |
531 | CYNext<CYParameter>(next), |
532 | name_(name) | |
cf7d4c69 JF |
533 | { |
534 | } | |
5999c315 JF |
535 | |
536 | virtual void Output(std::ostream &out) const; | |
cf7d4c69 JF |
537 | }; |
538 | ||
539 | struct CYFor : | |
540 | CYStatement | |
541 | { | |
542 | CYForInitialiser *initialiser_; | |
543 | CYExpression *test_; | |
544 | CYExpression *increment_; | |
545 | CYStatement *code_; | |
546 | ||
547 | CYFor(CYForInitialiser *initialiser, CYExpression *test, CYExpression *increment, CYStatement *code) : | |
548 | initialiser_(initialiser), | |
549 | test_(test), | |
550 | increment_(increment), | |
551 | code_(code) | |
552 | { | |
553 | } | |
5999c315 JF |
554 | |
555 | virtual void Output(std::ostream &out) const; | |
cf7d4c69 JF |
556 | }; |
557 | ||
558 | struct CYForIn : | |
559 | CYStatement | |
560 | { | |
561 | CYForInInitialiser *initialiser_; | |
562 | CYExpression *set_; | |
563 | CYStatement *code_; | |
564 | ||
565 | CYForIn(CYForInInitialiser *initialiser, CYExpression *set, CYStatement *code) : | |
566 | initialiser_(initialiser), | |
567 | set_(set), | |
568 | code_(code) | |
569 | { | |
570 | } | |
5999c315 JF |
571 | |
572 | virtual void Output(std::ostream &out) const; | |
cf7d4c69 JF |
573 | }; |
574 | ||
62014ea9 JF |
575 | struct CYProperty : |
576 | CYNext<CYProperty> | |
577 | { | |
cf7d4c69 JF |
578 | CYName *name_; |
579 | CYExpression *value_; | |
cf7d4c69 JF |
580 | |
581 | CYProperty(CYName *name, CYExpression *value, CYProperty *next) : | |
62014ea9 | 582 | CYNext<CYProperty>(next), |
cf7d4c69 | 583 | name_(name), |
62014ea9 | 584 | value_(value) |
cf7d4c69 JF |
585 | { |
586 | } | |
5999c315 | 587 | |
5999c315 | 588 | virtual void Output(std::ostream &out) const; |
cf7d4c69 JF |
589 | }; |
590 | ||
693d501b JF |
591 | struct CYObject : |
592 | CYLiteral | |
593 | { | |
594 | CYProperty *property_; | |
595 | ||
596 | CYObject(CYProperty *property) : | |
597 | property_(property) | |
598 | { | |
599 | } | |
600 | ||
601 | void Output(std::ostream &out) const; | |
602 | }; | |
603 | ||
5999c315 JF |
604 | struct CYCatch : |
605 | CYThing | |
606 | { | |
cf7d4c69 JF |
607 | CYIdentifier *name_; |
608 | CYStatement *code_; | |
609 | ||
610 | CYCatch(CYIdentifier *name, CYStatement *code) : | |
611 | name_(name), | |
612 | code_(code) | |
613 | { | |
614 | } | |
5999c315 JF |
615 | |
616 | virtual void Output(std::ostream &out) const; | |
cf7d4c69 JF |
617 | }; |
618 | ||
619 | struct CYMessage : | |
63b4c5a8 JF |
620 | CYExpression |
621 | { | |
cf7d4c69 JF |
622 | CYExpression *self_; |
623 | CYArgument *arguments_; | |
63b4c5a8 | 624 | |
cf7d4c69 JF |
625 | CYMessage(CYExpression *self, CYArgument *arguments) : |
626 | self_(self), | |
627 | arguments_(arguments) | |
63b4c5a8 JF |
628 | { |
629 | } | |
5999c315 | 630 | |
d35a3b07 JF |
631 | CYPrecedence(0) |
632 | ||
5999c315 | 633 | virtual void Output(std::ostream &out) const; |
63b4c5a8 JF |
634 | }; |
635 | ||
cf7d4c69 JF |
636 | struct CYMember : |
637 | CYExpression | |
638 | { | |
639 | CYExpression *object_; | |
640 | CYExpression *property_; | |
641 | ||
642 | CYMember(CYExpression *object, CYExpression *property) : | |
643 | object_(object), | |
644 | property_(property) | |
645 | { | |
646 | } | |
5999c315 | 647 | |
d35a3b07 JF |
648 | CYPrecedence(1) |
649 | ||
5999c315 | 650 | virtual void Output(std::ostream &out) const; |
cf7d4c69 JF |
651 | }; |
652 | ||
653 | struct CYNew : | |
654 | CYExpression | |
655 | { | |
656 | CYExpression *constructor_; | |
657 | CYArgument *arguments_; | |
658 | ||
659 | CYNew(CYExpression *constructor, CYArgument *arguments) : | |
660 | constructor_(constructor), | |
661 | arguments_(arguments) | |
662 | { | |
663 | } | |
5999c315 | 664 | |
d35a3b07 JF |
665 | CYPrecedence(1) |
666 | ||
5999c315 | 667 | virtual void Output(std::ostream &out) const; |
cf7d4c69 JF |
668 | }; |
669 | ||
670 | struct CYCall : | |
671 | CYExpression | |
672 | { | |
673 | CYExpression *function_; | |
674 | CYArgument *arguments_; | |
675 | ||
676 | CYCall(CYExpression *function, CYArgument *arguments) : | |
677 | function_(function), | |
678 | arguments_(arguments) | |
679 | { | |
680 | } | |
5999c315 | 681 | |
d35a3b07 JF |
682 | CYPrecedence(2) |
683 | ||
5999c315 | 684 | virtual void Output(std::ostream &out) const; |
cf7d4c69 JF |
685 | }; |
686 | ||
687 | struct CYIf : | |
688 | CYStatement | |
689 | { | |
690 | CYExpression *test_; | |
691 | CYStatement *true_; | |
692 | CYStatement *false_; | |
693 | ||
694 | CYIf(CYExpression *test, CYStatement *_true, CYStatement *_false) : | |
695 | test_(test), | |
696 | true_(_true), | |
697 | false_(_false) | |
698 | { | |
699 | } | |
5999c315 JF |
700 | |
701 | virtual void Output(std::ostream &out) const; | |
cf7d4c69 JF |
702 | }; |
703 | ||
704 | struct CYDoWhile : | |
705 | CYStatement | |
706 | { | |
707 | CYExpression *test_; | |
708 | CYStatement *code_; | |
709 | ||
710 | CYDoWhile(CYExpression *test, CYStatement *code) : | |
711 | test_(test), | |
712 | code_(code) | |
713 | { | |
714 | } | |
5999c315 JF |
715 | |
716 | virtual void Output(std::ostream &out) const; | |
cf7d4c69 JF |
717 | }; |
718 | ||
719 | struct CYWhile : | |
720 | CYStatement | |
721 | { | |
722 | CYExpression *test_; | |
723 | CYStatement *code_; | |
724 | ||
725 | CYWhile(CYExpression *test, CYStatement *code) : | |
726 | test_(test), | |
727 | code_(code) | |
728 | { | |
729 | } | |
5999c315 JF |
730 | |
731 | virtual void Output(std::ostream &out) const; | |
cf7d4c69 JF |
732 | }; |
733 | ||
734 | struct CYLambda : | |
735 | CYExpression | |
736 | { | |
737 | CYIdentifier *name_; | |
738 | CYParameter *parameters_; | |
739 | CYSource *body_; | |
740 | ||
741 | CYLambda(CYIdentifier *name, CYParameter *parameters, CYSource *body) : | |
742 | name_(name), | |
743 | parameters_(parameters), | |
744 | body_(body) | |
745 | { | |
746 | } | |
5999c315 | 747 | |
d35a3b07 JF |
748 | CYPrecedence(0) |
749 | ||
5999c315 | 750 | virtual void Output(std::ostream &out) const; |
cf7d4c69 JF |
751 | }; |
752 | ||
753 | struct CYFunction : | |
5999c315 JF |
754 | CYLambda, |
755 | CYSource | |
cf7d4c69 JF |
756 | { |
757 | CYFunction(CYIdentifier *name, CYParameter *parameters, CYSource *body) : | |
758 | CYLambda(name, parameters, body) | |
759 | { | |
760 | } | |
5999c315 JF |
761 | |
762 | virtual void Output(std::ostream &out) const; | |
763 | }; | |
764 | ||
765 | struct CYExpress : | |
766 | CYStatement | |
767 | { | |
768 | CYExpression *expression_; | |
769 | ||
770 | CYExpress(CYExpression *expression) : | |
771 | expression_(expression) | |
772 | { | |
773 | } | |
774 | ||
775 | virtual void Output(std::ostream &out) const; | |
cf7d4c69 JF |
776 | }; |
777 | ||
778 | struct CYContinue : | |
779 | CYStatement | |
780 | { | |
781 | CYIdentifier *label_; | |
782 | ||
783 | CYContinue(CYIdentifier *label) : | |
784 | label_(label) | |
785 | { | |
786 | } | |
5999c315 JF |
787 | |
788 | virtual void Output(std::ostream &out) const; | |
cf7d4c69 JF |
789 | }; |
790 | ||
791 | struct CYBreak : | |
792 | CYStatement | |
793 | { | |
794 | CYIdentifier *label_; | |
795 | ||
796 | CYBreak(CYIdentifier *label) : | |
797 | label_(label) | |
798 | { | |
799 | } | |
5999c315 JF |
800 | |
801 | virtual void Output(std::ostream &out) const; | |
cf7d4c69 JF |
802 | }; |
803 | ||
804 | struct CYReturn : | |
805 | CYStatement | |
806 | { | |
807 | CYExpression *value_; | |
808 | ||
809 | CYReturn(CYExpression *value) : | |
810 | value_(value) | |
811 | { | |
812 | } | |
5999c315 JF |
813 | |
814 | virtual void Output(std::ostream &out) const; | |
cf7d4c69 JF |
815 | }; |
816 | ||
817 | struct CYEmpty : | |
818 | CYStatement | |
819 | { | |
5999c315 JF |
820 | virtual void Output(std::ostream &out) const; |
821 | virtual void Output(std::ostream &out, bool block) const; | |
cf7d4c69 JF |
822 | }; |
823 | ||
824 | struct CYTry : | |
825 | CYStatement | |
826 | { | |
827 | CYStatement *try_; | |
828 | CYCatch *catch_; | |
829 | CYStatement *finally_; | |
830 | ||
831 | CYTry(CYStatement *_try, CYCatch *_catch, CYStatement *finally) : | |
832 | try_(_try), | |
833 | catch_(_catch), | |
834 | finally_(finally) | |
835 | { | |
836 | } | |
5999c315 JF |
837 | |
838 | virtual void Output(std::ostream &out) const; | |
cf7d4c69 JF |
839 | }; |
840 | ||
841 | struct CYThrow : | |
842 | CYStatement | |
843 | { | |
844 | CYExpression *value_; | |
845 | ||
846 | CYThrow(CYExpression *value) : | |
847 | value_(value) | |
848 | { | |
849 | } | |
5999c315 JF |
850 | |
851 | virtual void Output(std::ostream &out) const; | |
cf7d4c69 JF |
852 | }; |
853 | ||
854 | struct CYWith : | |
855 | CYStatement | |
856 | { | |
857 | CYExpression *scope_; | |
858 | CYStatement *code_; | |
859 | ||
860 | CYWith(CYExpression *scope, CYStatement *code) : | |
861 | scope_(scope), | |
862 | code_(code) | |
863 | { | |
864 | } | |
5999c315 JF |
865 | |
866 | virtual void Output(std::ostream &out) const; | |
cf7d4c69 JF |
867 | }; |
868 | ||
869 | struct CYSwitch : | |
870 | CYStatement | |
871 | { | |
872 | CYExpression *value_; | |
873 | CYClause *clauses_; | |
874 | ||
875 | CYSwitch(CYExpression *value, CYClause *clauses) : | |
876 | value_(value), | |
877 | clauses_(clauses) | |
878 | { | |
879 | } | |
5999c315 JF |
880 | |
881 | virtual void Output(std::ostream &out) const; | |
cf7d4c69 JF |
882 | }; |
883 | ||
884 | struct CYCondition : | |
885 | CYExpression | |
886 | { | |
887 | CYExpression *test_; | |
888 | CYExpression *true_; | |
889 | CYExpression *false_; | |
890 | ||
891 | CYCondition(CYExpression *test, CYExpression *_true, CYExpression *_false) : | |
91a416e4 | 892 | test_(test), |
cf7d4c69 JF |
893 | true_(_true), |
894 | false_(_false) | |
895 | { | |
896 | } | |
5999c315 | 897 | |
d35a3b07 JF |
898 | CYPrecedence(15) |
899 | ||
5999c315 JF |
900 | virtual void Output(std::ostream &out) const; |
901 | }; | |
902 | ||
903 | struct CYAddressOf : | |
904 | CYPrefix | |
905 | { | |
906 | CYAddressOf(CYExpression *rhs) : | |
907 | CYPrefix(rhs) | |
908 | { | |
909 | } | |
910 | ||
911 | virtual const char *Operator() const { | |
912 | return "&"; | |
913 | } | |
914 | ||
d35a3b07 JF |
915 | CYPrecedence(2) |
916 | ||
5999c315 JF |
917 | virtual void Output(std::ostream &out) const; |
918 | }; | |
919 | ||
920 | struct CYIndirect : | |
921 | CYPrefix | |
922 | { | |
923 | CYIndirect(CYExpression *rhs) : | |
924 | CYPrefix(rhs) | |
925 | { | |
926 | } | |
927 | ||
928 | virtual const char *Operator() const { | |
929 | return "*"; | |
930 | } | |
931 | ||
d35a3b07 JF |
932 | CYPrecedence(1) |
933 | ||
5999c315 | 934 | virtual void Output(std::ostream &out) const; |
cf7d4c69 JF |
935 | }; |
936 | ||
937 | #define CYPostfix_(op, name) \ | |
938 | struct CY ## name : \ | |
939 | CYPostfix \ | |
940 | { \ | |
941 | CY ## name(CYExpression *lhs) : \ | |
942 | CYPostfix(lhs) \ | |
943 | { \ | |
944 | } \ | |
d35a3b07 JF |
945 | \ |
946 | CYPrecedence(3) \ | |
5999c315 JF |
947 | \ |
948 | virtual const char *Operator() const { \ | |
949 | return op; \ | |
950 | } \ | |
cf7d4c69 JF |
951 | }; |
952 | ||
953 | #define CYPrefix_(op, name) \ | |
954 | struct CY ## name : \ | |
955 | CYPrefix \ | |
956 | { \ | |
957 | CY ## name(CYExpression *rhs) : \ | |
958 | CYPrefix(rhs) \ | |
959 | { \ | |
960 | } \ | |
d35a3b07 JF |
961 | \ |
962 | CYPrecedence(4) \ | |
5999c315 JF |
963 | \ |
964 | virtual const char *Operator() const { \ | |
965 | return op; \ | |
966 | } \ | |
cf7d4c69 JF |
967 | }; |
968 | ||
d35a3b07 | 969 | #define CYInfix_(precedence, op, name) \ |
cf7d4c69 JF |
970 | struct CY ## name : \ |
971 | CYInfix \ | |
972 | { \ | |
973 | CY ## name(CYExpression *lhs, CYExpression *rhs) : \ | |
974 | CYInfix(lhs, rhs) \ | |
975 | { \ | |
976 | } \ | |
d35a3b07 JF |
977 | \ |
978 | CYPrecedence(precedence) \ | |
5999c315 JF |
979 | \ |
980 | virtual const char *Operator() const { \ | |
981 | return op; \ | |
982 | } \ | |
cf7d4c69 JF |
983 | }; |
984 | ||
985 | #define CYAssignment_(op, name) \ | |
986 | struct CY ## name ## Assign : \ | |
987 | CYAssignment \ | |
988 | { \ | |
989 | CY ## name ## Assign(CYExpression *lhs, CYExpression *rhs) : \ | |
990 | CYAssignment(lhs, rhs) \ | |
991 | { \ | |
992 | } \ | |
d35a3b07 JF |
993 | \ |
994 | CYPrecedence(16) \ | |
5999c315 JF |
995 | \ |
996 | virtual const char *Operator() const { \ | |
997 | return op; \ | |
998 | } \ | |
cf7d4c69 JF |
999 | }; |
1000 | ||
1001 | CYPostfix_("++", PostIncrement) | |
1002 | CYPostfix_("--", PostDecrement) | |
1003 | ||
1004 | CYPrefix_("delete", Delete) | |
1005 | CYPrefix_("void", Void) | |
1006 | CYPrefix_("typeof", TypeOf) | |
1007 | CYPrefix_("++", PreIncrement) | |
1008 | CYPrefix_("--", PreDecrement) | |
1009 | CYPrefix_("-", Negate) | |
1010 | CYPrefix_("~", BitwiseNot) | |
1011 | CYPrefix_("!", LogicalNot) | |
cf7d4c69 | 1012 | |
d35a3b07 JF |
1013 | CYInfix_(5, "*", Multiply) |
1014 | CYInfix_(5, "/", Divide) | |
1015 | CYInfix_(5, "%", Modulus) | |
1016 | CYInfix_(6, "+", Add) | |
1017 | CYInfix_(6, "-", Subtract) | |
1018 | CYInfix_(7, "<<", ShiftLeft) | |
1019 | CYInfix_(7, ">>", ShiftRightSigned) | |
1020 | CYInfix_(7, ">>>", ShiftRightUnsigned) | |
1021 | CYInfix_(8, "<", Less) | |
1022 | CYInfix_(8, ">", Greater) | |
1023 | CYInfix_(8, "<=", LessOrEqual) | |
1024 | CYInfix_(8, ">=", GreaterOrEqual) | |
1025 | CYInfix_(8, "instanceof", InstanceOf) | |
1026 | CYInfix_(8, "in", In) | |
1027 | CYInfix_(9, "==", Equal) | |
1028 | CYInfix_(9, "!=", NotEqual) | |
1029 | CYInfix_(9, "===", Identical) | |
1030 | CYInfix_(9, "!==", NotIdentical) | |
1031 | CYInfix_(10, "&", BitwiseAnd) | |
1032 | CYInfix_(11, "^", BitwiseXOr) | |
1033 | CYInfix_(12, "|", BitwiseOr) | |
1034 | CYInfix_(13, "&&", LogicalAnd) | |
1035 | CYInfix_(14, "||", LogicalOr) | |
cf7d4c69 JF |
1036 | |
1037 | CYAssignment_("=", ) | |
1038 | CYAssignment_("*=", Multiply) | |
1039 | CYAssignment_("/=", Divide) | |
1040 | CYAssignment_("%=", Modulus) | |
1041 | CYAssignment_("+=", Add) | |
1042 | CYAssignment_("-=", Subtract) | |
1043 | CYAssignment_("<<=", ShiftLeft) | |
1044 | CYAssignment_(">>=", ShiftRightSigned) | |
1045 | CYAssignment_(">>>=", ShiftRightUnsigned) | |
1046 | CYAssignment_("&=", BitwiseAnd) | |
1047 | CYAssignment_("^=", BitwiseXOr) | |
1048 | CYAssignment_("|=", BitwiseOr) | |
1049 | ||
63b4c5a8 | 1050 | #endif/*CYPARSER_HPP*/ |