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