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