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