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