]> git.saurik.com Git - cycript.git/blame - Parser.hpp
Make sure the shell is bash!
[cycript.git] / Parser.hpp
CommitLineData
b4aa79af
JF
1/* Cycript - Remove Execution Server and Disassembler
2 * Copyright (C) 2009 Jay Freeman (saurik)
3*/
4
5/* Modified BSD License {{{ */
6/*
7 * Redistribution and use in source and binary
8 * forms, with or without modification, are permitted
9 * provided that the following conditions are met:
10 *
11 * 1. Redistributions of source code must retain the
12 * above copyright notice, this list of conditions
13 * and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the
15 * above copyright notice, this list of conditions
16 * and the following disclaimer in the documentation
17 * and/or other materials provided with the
18 * distribution.
19 * 3. The name of the author may not be used to endorse
20 * or promote products derived from this software
21 * without specific prior written permission.
22 *
23 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS''
24 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
25 * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
26 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE
28 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
29 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
30 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
31 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
34 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
35 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
36 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37*/
38/* }}} */
39
63b4c5a8
JF
40#ifndef CYPARSER_HPP
41#define CYPARSER_HPP
42
4de0686f
JF
43// XXX: wtf is this here?!
44#define CYPA 16
45
46#include <iostream>
47
5999c315 48#include <string>
c3c20102 49#include <vector>
cf7d4c69 50
4de0686f
JF
51#include <cstdlib>
52
5befe15e 53#include "location.hh"
5999c315 54#include "Pooling.hpp"
924f67b2 55
5999c315
JF
56template <typename Type_>
57struct CYNext {
58 Type_ *next_;
63b4c5a8 59
5999c315
JF
60 CYNext() :
61 next_(NULL)
62 {
63 }
cf7d4c69 64
62014ea9
JF
65 CYNext(Type_ *next) :
66 next_(next)
67 {
68 }
69
5999c315 70 void SetNext(Type_ *next) {
cf7d4c69
JF
71 next_ = next;
72 }
73};
74
5999c315 75struct CYThing {
652ec1ba 76 virtual void Output(struct CYOutput &out) const = 0;
5999c315
JF
77};
78
652ec1ba
JF
79struct CYOutput {
80 std::ostream &out_;
11c1cc16
JF
81 bool pretty_;
82 unsigned indent_;
652ec1ba 83
96a7e5c2
JF
84 enum {
85 NoMode,
86 NoLetter,
c0bc320e 87 NoPlus,
96a7e5c2
JF
88 NoHyphen,
89 Terminated
90 } mode_;
91
652ec1ba 92 CYOutput(std::ostream &out) :
11c1cc16
JF
93 out_(out),
94 pretty_(false),
96a7e5c2
JF
95 indent_(0),
96 mode_(NoMode)
652ec1ba
JF
97 {
98 }
99
96a7e5c2 100 void Check(char value);
1fdca2fa 101 void Terminate();
652ec1ba 102
96a7e5c2
JF
103 CYOutput &operator <<(char rhs);
104 CYOutput &operator <<(const char *rhs);
105
106 _finline CYOutput &operator <<(const CYThing *rhs) {
107 if (rhs != NULL)
108 rhs->Output(*this);
652ec1ba
JF
109 return *this;
110 }
111
112 _finline CYOutput &operator <<(const CYThing &rhs) {
113 rhs.Output(*this);
114 return *this;
115 }
116};
5999c315 117
e5bc40db 118struct CYPropertyName {
652ec1ba 119 virtual void PropertyName(CYOutput &out) const = 0;
e5bc40db
JF
120};
121
3b52fd1a
JF
122struct CYExpression;
123
124enum CYNeeded {
125 CYNever = -1,
126 CYSometimes = 0,
127 CYAlways = 1,
128};
129
130enum CYFlags {
131 CYNoFlags = 0,
132 CYNoBrace = (1 << 0),
133 CYNoFunction = (1 << 1),
134 CYNoIn = (1 << 2),
135 CYNoCall = (1 << 3),
136 CYNoRightHand = (1 << 4),
137 CYNoDangle = (1 << 5),
138 CYNoBF = (CYNoBrace | CYNoFunction),
139};
140
141struct CYContext {
142 apr_pool_t *pool_;
143
144 CYContext(apr_pool_t *pool) :
145 pool_(pool)
146 {
147 }
148
149 template <typename Type_>
150 void Replace(Type_ *&value) {
151 if (value != NULL)
152 while (Type_ *replace = value->Replace(*this))
153 value = replace;
154 }
155};
156
157struct CYStatement :
158 CYNext<CYStatement>
159{
160 void Single(CYOutput &out, CYFlags flags) const;
161 void Multiple(CYOutput &out, CYFlags flags = CYNoFlags) const;
162
163 CYStatement *ReplaceAll(CYContext &context);
164
165 virtual CYStatement *Replace(CYContext &context) = 0;
166
167 private:
168 virtual void Output(CYOutput &out, CYFlags flags) const = 0;
169};
170
171struct CYStatements {
172 CYStatement *first_;
173 CYStatement *last_;
174
175 CYStatements() :
176 first_(NULL),
177 last_(NULL)
178 {
179 }
180
181 operator CYStatement *() const {
182 return first_;
183 }
184
185 CYStatements &operator ->*(CYStatement *next) {
186 if (next != NULL)
187 if (first_ == NULL) {
188 first_ = next;
189 last_ = next;
190 } else for (;; last_ = last_->next_)
191 if (last_->next_ == NULL) {
192 last_->next_ = next;
193 last_ = next;
194 break;
195 }
196 return *this;
197 }
198};
199
e5bc40db 200struct CYClassName {
3b52fd1a 201 virtual CYExpression *ClassName(CYContext &context, bool object) = 0;
652ec1ba 202 virtual void ClassName(CYOutput &out, bool object) const = 0;
63b4c5a8
JF
203};
204
cf7d4c69 205struct CYWord :
e5bc40db
JF
206 CYThing,
207 CYPropertyName,
208 CYClassName
63b4c5a8 209{
cf7d4c69
JF
210 const char *word_;
211
212 CYWord(const char *word) :
213 word_(word)
214 {
215 }
216
5999c315 217 const char *Value() const {
cf7d4c69
JF
218 return word_;
219 }
220
652ec1ba 221 virtual void Output(CYOutput &out) const;
e5bc40db 222
3b52fd1a 223 virtual CYExpression *ClassName(CYContext &context, bool object);
652ec1ba
JF
224 virtual void ClassName(CYOutput &out, bool object) const;
225 virtual void PropertyName(CYOutput &out) const;
63b4c5a8
JF
226};
227
652ec1ba
JF
228_finline std::ostream &operator <<(std::ostream &lhs, const CYWord &rhs) {
229 return lhs << rhs.Value();
230}
231
cf7d4c69
JF
232struct CYIdentifier :
233 CYWord
63b4c5a8 234{
5999c315
JF
235 CYIdentifier(const char *word) :
236 CYWord(word)
237 {
cf7d4c69 238 }
63b4c5a8
JF
239};
240
62014ea9 241struct CYLabel :
3b52fd1a 242 CYStatement
62014ea9 243{
9e562cfc 244 CYIdentifier *name_;
3b52fd1a 245 CYStatement *statement_;
cf7d4c69 246
3b52fd1a
JF
247 CYLabel(CYIdentifier *name, CYStatement *statement) :
248 name_(name),
249 statement_(statement)
cf7d4c69
JF
250 {
251 }
fb98ac0c 252
3b52fd1a
JF
253 virtual CYStatement *Replace(CYContext &context);
254 virtual void Output(CYOutput &out, CYFlags flags) const;
fb98ac0c
JF
255};
256
3b52fd1a
JF
257struct CYProgram :
258 CYThing
63b4c5a8 259{
3b52fd1a 260 CYStatement *statements_;
9e562cfc 261
3b52fd1a
JF
262 CYProgram(CYStatement *statements) :
263 statements_(statements)
9e562cfc
JF
264 {
265 }
cf7d4c69 266
3b52fd1a 267 virtual void Replace(CYContext &context);
fb98ac0c 268
3b52fd1a 269 virtual void Output(CYOutput &out) const;
9e562cfc
JF
270};
271
272struct CYBlock :
3b52fd1a
JF
273 CYStatement,
274 CYThing
9e562cfc
JF
275{
276 CYStatement *statements_;
277
278 CYBlock(CYStatement *statements) :
279 statements_(statements)
280 {
cf7d4c69 281 }
9e562cfc 282
3b52fd1a
JF
283 virtual CYStatement *Replace(CYContext &context);
284
285 virtual void Output(CYOutput &out) const;
fb98ac0c 286 virtual void Output(CYOutput &out, CYFlags flags) const;
cf7d4c69
JF
287};
288
db5e2840
JF
289enum CYState {
290 CYClear,
291 CYRestricted,
292 CYNewLine
293};
294
5999c315
JF
295class CYDriver {
296 public:
297 CYPool pool_;
e7ed5354 298
db5e2840 299 CYState state_;
e7ed5354
JF
300 void *scanner_;
301
302 const char *data_;
303 size_t size_;
48e3be8a 304 FILE *file_;
e7ed5354 305
b10bd496
JF
306 bool strict_;
307
63cd45c9
JF
308 enum Condition {
309 RegExStart,
310 RegExRest
311 };
312
5999c315 313 std::string filename_;
e7ed5354 314
5befe15e 315 struct Error {
b10bd496 316 bool warning_;
5befe15e
JF
317 cy::location location_;
318 std::string message_;
319 };
320
321 typedef std::vector<Error> Errors;
322
3b52fd1a 323 CYProgram *program_;
5befe15e 324 Errors errors_;
5999c315
JF
325
326 private:
327 void ScannerInit();
328 void ScannerDestroy();
329
330 public:
331 CYDriver(const std::string &filename);
332 ~CYDriver();
63cd45c9
JF
333
334 void SetCondition(Condition condition);
b10bd496
JF
335
336 void Warning(const cy::location &location, const char *message);
5999c315
JF
337};
338
cac61857 339struct CYForInitialiser {
652ec1ba 340 virtual void For(CYOutput &out) const = 0;
dea834b0
JF
341};
342
cac61857 343struct CYForInInitialiser {
652ec1ba 344 virtual void ForIn(CYOutput &out, CYFlags flags) const = 0;
75b0a457 345 virtual const char *ForEachIn() const = 0;
652ec1ba 346 virtual void ForEachIn(CYOutput &out) const = 0;
3b52fd1a 347 virtual CYExpression *ForEachIn(CYContext &out) = 0;
b09da87b
JF
348};
349
cf7d4c69 350struct CYExpression :
5999c315 351 CYNext<CYExpression>,
cf7d4c69 352 CYForInitialiser,
e5bc40db 353 CYForInInitialiser,
96a7e5c2
JF
354 CYClassName,
355 CYThing
63b4c5a8 356{
d35a3b07 357 virtual unsigned Precedence() const = 0;
75b0a457 358
fb98ac0c
JF
359 virtual bool RightHand() const {
360 return true;
361 }
362
652ec1ba
JF
363 virtual void For(CYOutput &out) const;
364 virtual void ForIn(CYOutput &out, CYFlags flags) const;
75b0a457 365
cac61857 366 virtual const char *ForEachIn() const;
652ec1ba 367 virtual void ForEachIn(CYOutput &out) const;
3b52fd1a 368 virtual CYExpression *ForEachIn(CYContext &out);
75b0a457 369
96a7e5c2 370 virtual void Output(CYOutput &out) const;
652ec1ba
JF
371 virtual void Output(CYOutput &out, CYFlags flags) const = 0;
372 void Output(CYOutput &out, unsigned precedence, CYFlags flags) const;
dea834b0 373
3b52fd1a 374 virtual CYExpression *ClassName(CYContext &context, bool object);
652ec1ba 375 virtual void ClassName(CYOutput &out, bool object) const;
e5bc40db 376
3b52fd1a
JF
377 CYExpression *ReplaceAll(CYContext &context);
378
379 virtual CYExpression *Replace(CYContext &context) = 0;
380
dea834b0
JF
381 virtual const char *Word() const {
382 return NULL;
383 }
63b4c5a8
JF
384};
385
b09da87b
JF
386#define CYAlphabetic(value) \
387 virtual bool Alphabetic() const { \
388 return value; \
389 }
390
d35a3b07
JF
391#define CYPrecedence(value) \
392 virtual unsigned Precedence() const { \
393 return value; \
394 }
395
fb98ac0c
JF
396#define CYRightHand(value) \
397 virtual bool RightHand() const { \
398 return value; \
399 }
400
d35a3b07
JF
401struct CYCompound :
402 CYExpression
403{
404 CYExpression *expressions_;
405
406 CYCompound(CYExpression *expressions) :
407 expressions_(expressions)
408 {
409 }
410
411 void AddPrev(CYExpression *expression) {
412 CYExpression *last(expression);
413 while (last->next_ != NULL)
414 last = last->next_;
415 last->SetNext(expressions_);
416 expressions_ = expression;
417 }
418
419 CYPrecedence(17)
420
3b52fd1a 421 virtual CYExpression *Replace(CYContext &context);
652ec1ba 422 void Output(CYOutput &out, CYFlags flags) const;
d35a3b07 423};
5999c315 424
3b52fd1a
JF
425struct CYFunctionParameter :
426 CYNext<CYFunctionParameter>,
427 CYThing
428{
429 CYIdentifier *name_;
430
431 CYFunctionParameter(CYIdentifier *name, CYFunctionParameter *next = NULL) :
432 CYNext<CYFunctionParameter>(next),
433 name_(name)
434 {
435 }
436
437 virtual void Output(CYOutput &out) const;
438};
439
75b0a457 440struct CYComprehension :
96a7e5c2
JF
441 CYNext<CYComprehension>,
442 CYThing
75b0a457 443{
652ec1ba 444 void Output(CYOutput &out) const;
75b0a457
JF
445 virtual const char *Name() const = 0;
446
652ec1ba 447 virtual void Begin_(CYOutput &out) const = 0;
75b0a457 448
652ec1ba 449 virtual void End_(CYOutput &out) const {
75b0a457 450 }
3b52fd1a
JF
451
452 virtual CYFunctionParameter *Parameter(CYContext &context) const = 0;
453 CYFunctionParameter *Parameters(CYContext &context) const;
454 virtual CYStatement *Replace(CYContext &context, CYStatement *statement) const;
75b0a457
JF
455};
456
457struct CYForInComprehension :
458 CYComprehension
459{
460 CYIdentifier *name_;
461 CYExpression *set_;
462
463 CYForInComprehension(CYIdentifier *name, CYExpression *set) :
464 name_(name),
465 set_(set)
466 {
467 }
468
469 virtual const char *Name() const {
470 return name_->Value();
471 }
472
652ec1ba 473 virtual void Begin_(CYOutput &out) const;
3b52fd1a
JF
474
475 virtual CYFunctionParameter *Parameter(CYContext &context) const;
476 virtual CYStatement *Replace(CYContext &context, CYStatement *statement) const;
75b0a457
JF
477};
478
479struct CYForEachInComprehension :
480 CYComprehension
481{
482 CYIdentifier *name_;
483 CYExpression *set_;
484
485 CYForEachInComprehension(CYIdentifier *name, CYExpression *set) :
486 name_(name),
487 set_(set)
488 {
489 }
490
491 virtual const char *Name() const {
492 return name_->Value();
493 }
494
652ec1ba
JF
495 virtual void Begin_(CYOutput &out) const;
496 virtual void End_(CYOutput &out) const;
3b52fd1a
JF
497
498 virtual CYFunctionParameter *Parameter(CYContext &context) const;
499 virtual CYStatement *Replace(CYContext &context, CYStatement *statement) const;
75b0a457
JF
500};
501
502struct CYIfComprehension :
503 CYComprehension
504{
505 CYExpression *test_;
506
507 CYIfComprehension(CYExpression *test) :
508 test_(test)
509 {
510 }
511
512 virtual const char *Name() const {
513 return NULL;
514 }
515
652ec1ba 516 virtual void Begin_(CYOutput &out) const;
3b52fd1a
JF
517
518 virtual CYFunctionParameter *Parameter(CYContext &context) const;
519 virtual CYStatement *Replace(CYContext &context, CYStatement *statement) const;
75b0a457
JF
520};
521
522struct CYArrayComprehension :
523 CYExpression
524{
525 CYExpression *expression_;
526 CYComprehension *comprehensions_;
527
528 CYArrayComprehension(CYExpression *expression, CYComprehension *comprehensions) :
529 expression_(expression),
530 comprehensions_(comprehensions)
531 {
532 }
533
534 CYPrecedence(0)
535
3b52fd1a 536 virtual CYExpression *Replace(CYContext &context);
652ec1ba 537 virtual void Output(CYOutput &out, CYFlags flags) const;
75b0a457
JF
538};
539
cf7d4c69
JF
540struct CYLiteral :
541 CYExpression
63b4c5a8 542{
d35a3b07 543 CYPrecedence(0)
fb98ac0c 544 CYRightHand(false)
cf7d4c69 545};
63b4c5a8 546
3b52fd1a
JF
547struct CYTrivial :
548 CYLiteral
549{
550 virtual CYExpression *Replace(CYContext &context);
551};
552
478d4ed0
JF
553struct CYMagic :
554 CYExpression
555{
556 CYPrecedence(0)
fb98ac0c 557 CYRightHand(false)
478d4ed0
JF
558};
559
dea834b0
JF
560struct CYRange {
561 uint64_t lo_;
562 uint64_t hi_;
563
564 CYRange(uint64_t lo, uint64_t hi) :
565 lo_(lo), hi_(hi)
566 {
567 }
568
569 bool operator [](uint8_t value) const {
570 return !(value >> 7) && (value >> 6 ? hi_ : lo_) >> (value & 0x3f) & 0x1;
571 }
572
573 void operator()(uint8_t value) {
574 if (value >> 7)
575 return;
576 (value >> 6 ? hi_ : lo_) |= uint64_t(0x1) << (value & 0x3f);
577 }
578};
579
283e7e33 580extern CYRange DigitRange_;
dea834b0
JF
581extern CYRange WordStartRange_;
582extern CYRange WordEndRange_;
583
cf7d4c69 584struct CYString :
3b52fd1a 585 CYTrivial,
e5bc40db 586 CYPropertyName
cf7d4c69
JF
587{
588 const char *value_;
5999c315 589 size_t size_;
cf7d4c69 590
3b52fd1a
JF
591 CYString() :
592 value_(NULL),
593 size_(0)
594 {
595 }
596
597 CYString(const char *value) :
598 value_(value),
599 size_(strlen(value))
600 {
601 }
602
5999c315
JF
603 CYString(const char *value, size_t size) :
604 value_(value),
605 size_(size)
cf7d4c69
JF
606 {
607 }
608
3b52fd1a
JF
609 CYString(const CYWord *word) :
610 value_(word->Value()),
5999c315 611 size_(strlen(value_))
cf7d4c69
JF
612 {
613 }
614
5999c315 615 const char *Value() const {
cf7d4c69
JF
616 return value_;
617 }
618
11c1cc16 619 virtual const char *Word() const;
dea834b0 620
652ec1ba
JF
621 virtual void Output(CYOutput &out, CYFlags flags) const;
622 virtual void PropertyName(CYOutput &out) const;
63b4c5a8
JF
623};
624
cf7d4c69 625struct CYNumber :
3b52fd1a 626 CYTrivial,
e5bc40db 627 CYPropertyName
cf7d4c69 628{
5999c315
JF
629 double value_;
630
631 CYNumber(double value) :
632 value_(value)
633 {
634 }
635
636 double Value() const {
637 return value_;
cf7d4c69
JF
638 }
639
652ec1ba
JF
640 virtual void Output(CYOutput &out, CYFlags flags) const;
641 virtual void PropertyName(CYOutput &out) const;
cf7d4c69
JF
642};
643
63cd45c9 644struct CYRegEx :
3b52fd1a 645 CYTrivial
63cd45c9
JF
646{
647 const char *value_;
648
649 CYRegEx(const char *value) :
650 value_(value)
651 {
652 }
653
654 const char *Value() const {
655 return value_;
656 }
657
658 virtual void Output(CYOutput &out, CYFlags flags) const;
659};
660
cf7d4c69
JF
661struct CYNull :
662 CYWord,
3b52fd1a 663 CYTrivial
cf7d4c69
JF
664{
665 CYNull() :
666 CYWord("null")
667 {
668 }
5999c315 669
652ec1ba 670 virtual void Output(CYOutput &out, CYFlags flags) const;
cf7d4c69
JF
671};
672
673struct CYThis :
674 CYWord,
478d4ed0 675 CYMagic
cf7d4c69
JF
676{
677 CYThis() :
678 CYWord("this")
679 {
680 }
5999c315 681
3b52fd1a 682 virtual CYExpression *Replace(CYContext &context);
652ec1ba 683 virtual void Output(CYOutput &out, CYFlags flags) const;
cf7d4c69
JF
684};
685
686struct CYBoolean :
3b52fd1a 687 CYTrivial
cf7d4c69 688{
5999c315 689 virtual bool Value() const = 0;
652ec1ba 690 virtual void Output(CYOutput &out, CYFlags flags) const;
cf7d4c69
JF
691};
692
693struct CYFalse :
694 CYWord,
695 CYBoolean
696{
697 CYFalse() :
698 CYWord("false")
699 {
700 }
5999c315 701
11c1cc16
JF
702 virtual bool Value() const {
703 return false;
704 }
cf7d4c69
JF
705};
706
707struct CYTrue :
708 CYWord,
709 CYBoolean
710{
711 CYTrue() :
712 CYWord("true")
713 {
714 }
5999c315 715
11c1cc16
JF
716 virtual bool Value() const {
717 return true;
718 }
cf7d4c69
JF
719};
720
721struct CYVariable :
722 CYExpression
723{
724 CYIdentifier *name_;
725
726 CYVariable(CYIdentifier *name) :
727 name_(name)
728 {
729 }
5999c315 730
d35a3b07 731 CYPrecedence(0)
fb98ac0c 732 CYRightHand(false)
d35a3b07 733
3b52fd1a 734 virtual CYExpression *Replace(CYContext &context);
652ec1ba 735 virtual void Output(CYOutput &out, CYFlags flags) const;
cf7d4c69
JF
736};
737
738struct CYPrefix :
63b4c5a8
JF
739 CYExpression
740{
741 CYExpression *rhs_;
742
cf7d4c69 743 CYPrefix(CYExpression *rhs) :
63b4c5a8
JF
744 rhs_(rhs)
745 {
746 }
5999c315 747
b09da87b 748 virtual bool Alphabetic() const = 0;
5999c315
JF
749 virtual const char *Operator() const = 0;
750
3b52fd1a
JF
751 CYPrecedence(4)
752
753 virtual CYExpression *Replace(CYContext &context);
652ec1ba 754 virtual void Output(CYOutput &out, CYFlags flags) const;
63b4c5a8
JF
755};
756
cf7d4c69 757struct CYInfix :
63b4c5a8
JF
758 CYExpression
759{
760 CYExpression *lhs_;
761 CYExpression *rhs_;
762
cf7d4c69 763 CYInfix(CYExpression *lhs, CYExpression *rhs) :
63b4c5a8
JF
764 lhs_(lhs),
765 rhs_(rhs)
766 {
767 }
5999c315 768
0ff9f149
JF
769 void SetLeft(CYExpression *lhs) {
770 lhs_ = lhs;
771 }
772
b09da87b 773 virtual bool Alphabetic() const = 0;
5999c315
JF
774 virtual const char *Operator() const = 0;
775
3b52fd1a 776 virtual CYExpression *Replace(CYContext &context);
652ec1ba 777 virtual void Output(CYOutput &out, CYFlags flags) const;
63b4c5a8
JF
778};
779
cf7d4c69 780struct CYPostfix :
63b4c5a8
JF
781 CYExpression
782{
783 CYExpression *lhs_;
784
cf7d4c69 785 CYPostfix(CYExpression *lhs) :
63b4c5a8
JF
786 lhs_(lhs)
787 {
788 }
5999c315
JF
789
790 virtual const char *Operator() const = 0;
791
3b52fd1a
JF
792 CYPrecedence(3)
793
794 virtual CYExpression *Replace(CYContext &context);
652ec1ba 795 virtual void Output(CYOutput &out, CYFlags flags) const;
63b4c5a8
JF
796};
797
cf7d4c69 798struct CYAssignment :
d35a3b07 799 CYExpression
cf7d4c69 800{
d35a3b07
JF
801 CYExpression *lhs_;
802 CYExpression *rhs_;
803
cf7d4c69 804 CYAssignment(CYExpression *lhs, CYExpression *rhs) :
d35a3b07
JF
805 lhs_(lhs),
806 rhs_(rhs)
cf7d4c69
JF
807 {
808 }
5999c315 809
0ff9f149
JF
810 void SetLeft(CYExpression *lhs) {
811 lhs_ = lhs;
812 }
813
5999c315 814 virtual const char *Operator() const = 0;
d35a3b07 815
4de0686f
JF
816 CYPrecedence(16)
817
3b52fd1a 818 virtual CYExpression *Replace(CYContext &context);
652ec1ba 819 virtual void Output(CYOutput &out, CYFlags flags) const;
cf7d4c69
JF
820};
821
62014ea9 822struct CYArgument :
96a7e5c2
JF
823 CYNext<CYArgument>,
824 CYThing
62014ea9 825{
cf7d4c69
JF
826 CYWord *name_;
827 CYExpression *value_;
cf7d4c69 828
3b52fd1a
JF
829 CYArgument(CYExpression *value, CYArgument *next = NULL) :
830 CYNext<CYArgument>(next),
831 name_(NULL),
832 value_(value)
833 {
834 }
835
cf7d4c69 836 CYArgument(CYWord *name, CYExpression *value, CYArgument *next = NULL) :
62014ea9 837 CYNext<CYArgument>(next),
cf7d4c69 838 name_(name),
62014ea9 839 value_(value)
cf7d4c69
JF
840 {
841 }
5999c315 842
3b52fd1a 843 void Replace(CYContext &context);
652ec1ba 844 void Output(CYOutput &out) const;
cf7d4c69
JF
845};
846
847struct CYBlank :
848 public CYWord
849{
850 CYBlank() :
851 CYWord("")
852 {
853 }
854};
855
5999c315
JF
856struct CYClause :
857 CYThing,
858 CYNext<CYClause>
859{
cf7d4c69 860 CYExpression *case_;
3b52fd1a 861 CYStatement *statements_;
cf7d4c69 862
3b52fd1a 863 CYClause(CYExpression *_case, CYStatement *statements) :
cf7d4c69 864 case_(_case),
3b52fd1a 865 statements_(statements)
cf7d4c69
JF
866 {
867 }
868
fa389b0f 869 void Replace(CYContext &context);
652ec1ba 870 virtual void Output(CYOutput &out) const;
cf7d4c69
JF
871};
872
62014ea9 873struct CYElement :
96a7e5c2
JF
874 CYNext<CYElement>,
875 CYThing
62014ea9 876{
cf7d4c69 877 CYExpression *value_;
cf7d4c69
JF
878
879 CYElement(CYExpression *value, CYElement *next) :
62014ea9
JF
880 CYNext<CYElement>(next),
881 value_(value)
cf7d4c69
JF
882 {
883 }
5999c315 884
3b52fd1a 885 void Replace(CYContext &context);
652ec1ba 886 void Output(CYOutput &out) const;
5befe15e
JF
887};
888
889struct CYArray :
890 CYLiteral
891{
892 CYElement *elements_;
893
3b52fd1a 894 CYArray(CYElement *elements = NULL) :
5befe15e
JF
895 elements_(elements)
896 {
897 }
898
3b52fd1a 899 virtual CYExpression *Replace(CYContext &context);
652ec1ba 900 virtual void Output(CYOutput &out, CYFlags flags) const;
cf7d4c69
JF
901};
902
903struct CYDeclaration :
904 CYForInInitialiser
905{
906 CYIdentifier *identifier_;
907 CYExpression *initialiser_;
908
909 CYDeclaration(CYIdentifier *identifier, CYExpression *initialiser) :
910 identifier_(identifier),
911 initialiser_(initialiser)
912 {
913 }
5999c315 914
652ec1ba 915 virtual void ForIn(CYOutput &out, CYFlags flags) const;
75b0a457 916
cac61857 917 virtual const char *ForEachIn() const;
652ec1ba 918 virtual void ForEachIn(CYOutput &out) const;
3b52fd1a
JF
919 virtual CYExpression *ForEachIn(CYContext &out);
920
921 void Replace(CYContext &context);
75b0a457 922
652ec1ba 923 virtual void Output(CYOutput &out, CYFlags flags) const;
cf7d4c69
JF
924};
925
926struct CYDeclarations :
cac61857 927 CYNext<CYDeclarations>,
96a7e5c2
JF
928 CYForInitialiser,
929 CYThing
cf7d4c69
JF
930{
931 CYDeclaration *declaration_;
cf7d4c69
JF
932
933 CYDeclarations(CYDeclaration *declaration, CYDeclarations *next) :
cac61857
JF
934 CYNext<CYDeclarations>(next),
935 declaration_(declaration)
936 {
937 }
938
652ec1ba 939 virtual void For(CYOutput &out) const;
96a7e5c2 940
3b52fd1a
JF
941 void Replace(CYContext &context);
942
96a7e5c2 943 virtual void Output(CYOutput &out) const;
652ec1ba 944 virtual void Output(CYOutput &out, CYFlags flags) const;
cac61857
JF
945};
946
947struct CYVar :
948 CYStatement
949{
950 CYDeclarations *declarations_;
951
952 CYVar(CYDeclarations *declarations) :
953 declarations_(declarations)
954 {
955 }
956
3b52fd1a 957 virtual CYStatement *Replace(CYContext &context);
fb98ac0c 958 virtual void Output(CYOutput &out, CYFlags flags) const;
cac61857
JF
959};
960
961struct CYLet :
962 CYStatement
963{
964 CYDeclarations *declarations_;
3b52fd1a 965 CYBlock code_;
cac61857
JF
966
967 CYLet(CYDeclarations *declarations, CYStatement *statements) :
968 declarations_(declarations),
3b52fd1a 969 code_(statements)
cf7d4c69
JF
970 {
971 }
5999c315 972
3b52fd1a 973 virtual CYStatement *Replace(CYContext &context);
fb98ac0c 974 virtual void Output(CYOutput &out, CYFlags flags) const;
cf7d4c69
JF
975};
976
cf7d4c69
JF
977struct CYFor :
978 CYStatement
979{
980 CYForInitialiser *initialiser_;
981 CYExpression *test_;
982 CYExpression *increment_;
983 CYStatement *code_;
984
985 CYFor(CYForInitialiser *initialiser, CYExpression *test, CYExpression *increment, CYStatement *code) :
986 initialiser_(initialiser),
987 test_(test),
988 increment_(increment),
989 code_(code)
990 {
991 }
5999c315 992
3b52fd1a 993 virtual CYStatement *Replace(CYContext &context);
fb98ac0c 994 virtual void Output(CYOutput &out, CYFlags flags) const;
cf7d4c69
JF
995};
996
997struct CYForIn :
998 CYStatement
999{
1000 CYForInInitialiser *initialiser_;
1001 CYExpression *set_;
1002 CYStatement *code_;
1003
1004 CYForIn(CYForInInitialiser *initialiser, CYExpression *set, CYStatement *code) :
1005 initialiser_(initialiser),
1006 set_(set),
1007 code_(code)
1008 {
1009 }
5999c315 1010
3b52fd1a 1011 virtual CYStatement *Replace(CYContext &context);
fb98ac0c 1012 virtual void Output(CYOutput &out, CYFlags flags) const;
cf7d4c69
JF
1013};
1014
75b0a457
JF
1015struct CYForEachIn :
1016 CYStatement
1017{
1018 CYForInInitialiser *initialiser_;
1019 CYExpression *set_;
1020 CYStatement *code_;
1021
1022 CYForEachIn(CYForInInitialiser *initialiser, CYExpression *set, CYStatement *code) :
1023 initialiser_(initialiser),
1024 set_(set),
1025 code_(code)
1026 {
1027 }
1028
3b52fd1a 1029 virtual CYStatement *Replace(CYContext &context);
fb98ac0c 1030 virtual void Output(CYOutput &out, CYFlags flags) const;
75b0a457
JF
1031};
1032
62014ea9 1033struct CYProperty :
96a7e5c2
JF
1034 CYNext<CYProperty>,
1035 CYThing
62014ea9 1036{
e5bc40db 1037 CYPropertyName *name_;
cf7d4c69 1038 CYExpression *value_;
cf7d4c69 1039
3b52fd1a 1040 CYProperty(CYPropertyName *name, CYExpression *value, CYProperty *next = NULL) :
62014ea9 1041 CYNext<CYProperty>(next),
cf7d4c69 1042 name_(name),
62014ea9 1043 value_(value)
cf7d4c69
JF
1044 {
1045 }
5999c315 1046
3b52fd1a 1047 void Replace(CYContext &context);
652ec1ba 1048 virtual void Output(CYOutput &out) const;
cf7d4c69
JF
1049};
1050
693d501b
JF
1051struct CYObject :
1052 CYLiteral
1053{
3b52fd1a 1054 CYProperty *properties_;
693d501b 1055
3b52fd1a
JF
1056 CYObject(CYProperty *properties) :
1057 properties_(properties)
693d501b
JF
1058 {
1059 }
1060
3b52fd1a 1061 virtual CYExpression *Replace(CYContext &context);
652ec1ba 1062 void Output(CYOutput &out, CYFlags flags) const;
693d501b
JF
1063};
1064
5999c315
JF
1065struct CYCatch :
1066 CYThing
1067{
cf7d4c69 1068 CYIdentifier *name_;
3b52fd1a 1069 CYBlock code_;
cf7d4c69 1070
3b52fd1a 1071 CYCatch(CYIdentifier *name, CYStatement *statements) :
cf7d4c69 1072 name_(name),
3b52fd1a 1073 code_(statements)
cf7d4c69
JF
1074 {
1075 }
5999c315 1076
3b52fd1a 1077 void Replace(CYContext &context);
652ec1ba 1078 virtual void Output(CYOutput &out) const;
cf7d4c69
JF
1079};
1080
cf7d4c69
JF
1081struct CYMember :
1082 CYExpression
1083{
1084 CYExpression *object_;
1085 CYExpression *property_;
1086
1087 CYMember(CYExpression *object, CYExpression *property) :
1088 object_(object),
1089 property_(property)
1090 {
1091 }
5999c315 1092
9b5527f0
JF
1093 void SetLeft(CYExpression *object) {
1094 object_ = object;
1095 }
3b52fd1a
JF
1096
1097 void Replace_(CYContext &context);
9b5527f0
JF
1098};
1099
1100struct CYDirectMember :
1101 CYMember
1102{
1103 CYDirectMember(CYExpression *object, CYExpression *property) :
1104 CYMember(object, property)
1105 {
1106 }
1107
1108 CYPrecedence(1)
fb98ac0c 1109 CYRightHand(false)
9b5527f0 1110
3b52fd1a 1111 virtual CYExpression *Replace(CYContext &context);
652ec1ba 1112 virtual void Output(CYOutput &out, CYFlags flags) const;
9b5527f0
JF
1113};
1114
1115struct CYIndirectMember :
1116 CYMember
1117{
1118 CYIndirectMember(CYExpression *object, CYExpression *property) :
1119 CYMember(object, property)
1120 {
1121 }
1122
d35a3b07 1123 CYPrecedence(1)
fb98ac0c 1124 CYRightHand(false)
d35a3b07 1125
3b52fd1a 1126 virtual CYExpression *Replace(CYContext &context);
652ec1ba 1127 virtual void Output(CYOutput &out, CYFlags flags) const;
cf7d4c69
JF
1128};
1129
1130struct CYNew :
1131 CYExpression
1132{
1133 CYExpression *constructor_;
1134 CYArgument *arguments_;
1135
1136 CYNew(CYExpression *constructor, CYArgument *arguments) :
1137 constructor_(constructor),
1138 arguments_(arguments)
1139 {
1140 }
5999c315 1141
fb98ac0c
JF
1142 virtual unsigned Precedence() const {
1143 return arguments_ == NULL ? 2 : 1;
1144 }
1145
1146 CYRightHand(false)
d35a3b07 1147
3b52fd1a 1148 virtual CYExpression *Replace(CYContext &context);
652ec1ba 1149 virtual void Output(CYOutput &out, CYFlags flags) const;
cf7d4c69
JF
1150};
1151
1152struct CYCall :
1153 CYExpression
1154{
1155 CYExpression *function_;
1156 CYArgument *arguments_;
1157
3b52fd1a 1158 CYCall(CYExpression *function, CYArgument *arguments = NULL) :
cf7d4c69
JF
1159 function_(function),
1160 arguments_(arguments)
1161 {
1162 }
5999c315 1163
fb98ac0c
JF
1164 CYPrecedence(1)
1165 CYRightHand(false)
d35a3b07 1166
3b52fd1a 1167 virtual CYExpression *Replace(CYContext &context);
652ec1ba 1168 virtual void Output(CYOutput &out, CYFlags flags) const;
cf7d4c69
JF
1169};
1170
1171struct CYIf :
1172 CYStatement
1173{
1174 CYExpression *test_;
1175 CYStatement *true_;
1176 CYStatement *false_;
1177
3b52fd1a 1178 CYIf(CYExpression *test, CYStatement *_true, CYStatement *_false = NULL) :
cf7d4c69
JF
1179 test_(test),
1180 true_(_true),
1181 false_(_false)
1182 {
1183 }
5999c315 1184
3b52fd1a 1185 virtual CYStatement *Replace(CYContext &context);
fb98ac0c 1186 virtual void Output(CYOutput &out, CYFlags flags) const;
cf7d4c69
JF
1187};
1188
1189struct CYDoWhile :
1190 CYStatement
1191{
1192 CYExpression *test_;
1193 CYStatement *code_;
1194
1195 CYDoWhile(CYExpression *test, CYStatement *code) :
1196 test_(test),
1197 code_(code)
1198 {
1199 }
5999c315 1200
3b52fd1a 1201 virtual CYStatement *Replace(CYContext &context);
fb98ac0c 1202 virtual void Output(CYOutput &out, CYFlags flags) const;
cf7d4c69
JF
1203};
1204
1205struct CYWhile :
1206 CYStatement
1207{
1208 CYExpression *test_;
1209 CYStatement *code_;
1210
1211 CYWhile(CYExpression *test, CYStatement *code) :
1212 test_(test),
1213 code_(code)
1214 {
1215 }
5999c315 1216
3b52fd1a 1217 virtual CYStatement *Replace(CYContext &context);
fb98ac0c 1218 virtual void Output(CYOutput &out, CYFlags flags) const;
cf7d4c69
JF
1219};
1220
fb98ac0c 1221struct CYFunction {
cf7d4c69 1222 CYIdentifier *name_;
b09da87b 1223 CYFunctionParameter *parameters_;
3b52fd1a 1224 CYBlock code_;
cf7d4c69 1225
3b52fd1a 1226 CYFunction(CYIdentifier *name, CYFunctionParameter *parameters, CYStatement *statements) :
cf7d4c69
JF
1227 name_(name),
1228 parameters_(parameters),
3b52fd1a 1229 code_(statements)
cf7d4c69
JF
1230 {
1231 }
5999c315 1232
3b52fd1a 1233 virtual void Replace_(CYContext &context);
fb98ac0c
JF
1234 virtual void Output(CYOutput &out, CYFlags flags) const;
1235};
1236
1237struct CYFunctionExpression :
1238 CYFunction,
1239 CYExpression
1240{
3b52fd1a
JF
1241 CYFunctionExpression(CYIdentifier *name, CYFunctionParameter *parameters, CYStatement *statements) :
1242 CYFunction(name, parameters, statements)
fb98ac0c
JF
1243 {
1244 }
1245
d35a3b07 1246 CYPrecedence(0)
fb98ac0c 1247 CYRightHand(false)
d35a3b07 1248
3b52fd1a 1249 virtual CYExpression *Replace(CYContext &context);
652ec1ba 1250 virtual void Output(CYOutput &out, CYFlags flags) const;
cf7d4c69
JF
1251};
1252
fb98ac0c
JF
1253struct CYFunctionStatement :
1254 CYFunction,
b10bd496 1255 CYStatement
cf7d4c69 1256{
3b52fd1a
JF
1257 CYFunctionStatement(CYIdentifier *name, CYFunctionParameter *parameters, CYStatement *statements) :
1258 CYFunction(name, parameters, statements)
cf7d4c69
JF
1259 {
1260 }
5999c315 1261
3b52fd1a 1262 virtual CYStatement *Replace(CYContext &context);
fb98ac0c 1263 virtual void Output(CYOutput &out, CYFlags flags) const;
5999c315
JF
1264};
1265
1266struct CYExpress :
1267 CYStatement
1268{
1269 CYExpression *expression_;
1270
1271 CYExpress(CYExpression *expression) :
1272 expression_(expression)
1273 {
1274 }
1275
3b52fd1a 1276 virtual CYStatement *Replace(CYContext &context);
fb98ac0c 1277 virtual void Output(CYOutput &out, CYFlags flags) const;
cf7d4c69
JF
1278};
1279
1280struct CYContinue :
1281 CYStatement
1282{
1283 CYIdentifier *label_;
1284
1285 CYContinue(CYIdentifier *label) :
1286 label_(label)
1287 {
1288 }
5999c315 1289
3b52fd1a 1290 virtual CYStatement *Replace(CYContext &context);
fb98ac0c 1291 virtual void Output(CYOutput &out, CYFlags flags) const;
cf7d4c69
JF
1292};
1293
1294struct CYBreak :
1295 CYStatement
1296{
1297 CYIdentifier *label_;
1298
1299 CYBreak(CYIdentifier *label) :
1300 label_(label)
1301 {
1302 }
5999c315 1303
3b52fd1a 1304 virtual CYStatement *Replace(CYContext &context);
fb98ac0c 1305 virtual void Output(CYOutput &out, CYFlags flags) const;
cf7d4c69
JF
1306};
1307
1308struct CYReturn :
1309 CYStatement
1310{
1311 CYExpression *value_;
1312
1313 CYReturn(CYExpression *value) :
1314 value_(value)
1315 {
1316 }
5999c315 1317
3b52fd1a 1318 virtual CYStatement *Replace(CYContext &context);
fb98ac0c 1319 virtual void Output(CYOutput &out, CYFlags flags) const;
cf7d4c69
JF
1320};
1321
1322struct CYEmpty :
1323 CYStatement
1324{
3b52fd1a 1325 virtual CYStatement *Replace(CYContext &context);
fb98ac0c 1326 virtual void Output(CYOutput &out, CYFlags flags) const;
cf7d4c69
JF
1327};
1328
96a7e5c2
JF
1329struct CYFinally :
1330 CYThing
1331{
3b52fd1a 1332 CYBlock code_;
b10bd496 1333
3b52fd1a
JF
1334 CYFinally(CYStatement *statements) :
1335 code_(statements)
b10bd496
JF
1336 {
1337 }
1338
3b52fd1a 1339 void Replace(CYContext &context);
b10bd496
JF
1340 virtual void Output(CYOutput &out) const;
1341};
1342
cf7d4c69
JF
1343struct CYTry :
1344 CYStatement
1345{
3b52fd1a 1346 CYBlock code_;
cf7d4c69 1347 CYCatch *catch_;
b10bd496 1348 CYFinally *finally_;
cf7d4c69 1349
3b52fd1a
JF
1350 CYTry(CYStatement *statements, CYCatch *_catch, CYFinally *finally) :
1351 code_(statements),
cf7d4c69
JF
1352 catch_(_catch),
1353 finally_(finally)
1354 {
1355 }
5999c315 1356
3b52fd1a 1357 virtual CYStatement *Replace(CYContext &context);
fb98ac0c 1358 virtual void Output(CYOutput &out, CYFlags flags) const;
cf7d4c69
JF
1359};
1360
1361struct CYThrow :
1362 CYStatement
1363{
1364 CYExpression *value_;
1365
1366 CYThrow(CYExpression *value) :
1367 value_(value)
1368 {
1369 }
5999c315 1370
3b52fd1a 1371 virtual CYStatement *Replace(CYContext &context);
fb98ac0c 1372 virtual void Output(CYOutput &out, CYFlags flags) const;
cf7d4c69
JF
1373};
1374
1375struct CYWith :
1376 CYStatement
1377{
1378 CYExpression *scope_;
1379 CYStatement *code_;
1380
1381 CYWith(CYExpression *scope, CYStatement *code) :
1382 scope_(scope),
1383 code_(code)
1384 {
1385 }
5999c315 1386
3b52fd1a 1387 virtual CYStatement *Replace(CYContext &context);
fb98ac0c 1388 virtual void Output(CYOutput &out, CYFlags flags) const;
cf7d4c69
JF
1389};
1390
1391struct CYSwitch :
1392 CYStatement
1393{
1394 CYExpression *value_;
1395 CYClause *clauses_;
1396
1397 CYSwitch(CYExpression *value, CYClause *clauses) :
1398 value_(value),
1399 clauses_(clauses)
1400 {
1401 }
5999c315 1402
3b52fd1a 1403 virtual CYStatement *Replace(CYContext &context);
fb98ac0c 1404 virtual void Output(CYOutput &out, CYFlags flags) const;
cf7d4c69
JF
1405};
1406
1407struct CYCondition :
1408 CYExpression
1409{
1410 CYExpression *test_;
1411 CYExpression *true_;
1412 CYExpression *false_;
1413
1414 CYCondition(CYExpression *test, CYExpression *_true, CYExpression *_false) :
91a416e4 1415 test_(test),
cf7d4c69
JF
1416 true_(_true),
1417 false_(_false)
1418 {
1419 }
5999c315 1420
d35a3b07
JF
1421 CYPrecedence(15)
1422
3b52fd1a 1423 virtual CYExpression *Replace(CYContext &context);
652ec1ba 1424 virtual void Output(CYOutput &out, CYFlags flags) const;
5999c315
JF
1425};
1426
1427struct CYAddressOf :
1428 CYPrefix
1429{
1430 CYAddressOf(CYExpression *rhs) :
1431 CYPrefix(rhs)
1432 {
1433 }
1434
1435 virtual const char *Operator() const {
1436 return "&";
1437 }
1438
b09da87b 1439 CYAlphabetic(false)
d35a3b07 1440
3b52fd1a 1441 virtual CYExpression *Replace(CYContext &context);
5999c315
JF
1442};
1443
1444struct CYIndirect :
1445 CYPrefix
1446{
1447 CYIndirect(CYExpression *rhs) :
1448 CYPrefix(rhs)
1449 {
1450 }
1451
1452 virtual const char *Operator() const {
1453 return "*";
1454 }
1455
b09da87b 1456 CYAlphabetic(false)
d35a3b07 1457
3b52fd1a 1458 virtual CYExpression *Replace(CYContext &context);
cf7d4c69
JF
1459};
1460
1461#define CYPostfix_(op, name) \
1462 struct CY ## name : \
1463 CYPostfix \
1464 { \
1465 CY ## name(CYExpression *lhs) : \
1466 CYPostfix(lhs) \
1467 { \
1468 } \
5999c315
JF
1469 \
1470 virtual const char *Operator() const { \
1471 return op; \
1472 } \
cf7d4c69
JF
1473 };
1474
b09da87b 1475#define CYPrefix_(alphabetic, op, name) \
cf7d4c69
JF
1476 struct CY ## name : \
1477 CYPrefix \
1478 { \
1479 CY ## name(CYExpression *rhs) : \
1480 CYPrefix(rhs) \
1481 { \
1482 } \
d35a3b07 1483 \
b09da87b 1484 CYAlphabetic(alphabetic) \
5999c315
JF
1485 \
1486 virtual const char *Operator() const { \
1487 return op; \
1488 } \
cf7d4c69
JF
1489 };
1490
b09da87b 1491#define CYInfix_(alphabetic, precedence, op, name) \
cf7d4c69
JF
1492 struct CY ## name : \
1493 CYInfix \
1494 { \
1495 CY ## name(CYExpression *lhs, CYExpression *rhs) : \
1496 CYInfix(lhs, rhs) \
1497 { \
1498 } \
d35a3b07 1499 \
b09da87b 1500 CYAlphabetic(alphabetic) \
d35a3b07 1501 CYPrecedence(precedence) \
5999c315
JF
1502 \
1503 virtual const char *Operator() const { \
1504 return op; \
1505 } \
cf7d4c69
JF
1506 };
1507
1508#define CYAssignment_(op, name) \
1509 struct CY ## name ## Assign : \
1510 CYAssignment \
1511 { \
1512 CY ## name ## Assign(CYExpression *lhs, CYExpression *rhs) : \
1513 CYAssignment(lhs, rhs) \
1514 { \
1515 } \
5999c315
JF
1516 \
1517 virtual const char *Operator() const { \
1518 return op; \
1519 } \
cf7d4c69
JF
1520 };
1521
1522CYPostfix_("++", PostIncrement)
1523CYPostfix_("--", PostDecrement)
1524
b09da87b
JF
1525CYPrefix_(true, "delete", Delete)
1526CYPrefix_(true, "void", Void)
1527CYPrefix_(true, "typeof", TypeOf)
1528CYPrefix_(false, "++", PreIncrement)
1529CYPrefix_(false, "--", PreDecrement)
c0bc320e 1530CYPrefix_(false, "+", Affirm)
b09da87b
JF
1531CYPrefix_(false, "-", Negate)
1532CYPrefix_(false, "~", BitwiseNot)
1533CYPrefix_(false, "!", LogicalNot)
1534
1535CYInfix_(false, 5, "*", Multiply)
1536CYInfix_(false, 5, "/", Divide)
1537CYInfix_(false, 5, "%", Modulus)
1538CYInfix_(false, 6, "+", Add)
1539CYInfix_(false, 6, "-", Subtract)
1540CYInfix_(false, 7, "<<", ShiftLeft)
1541CYInfix_(false, 7, ">>", ShiftRightSigned)
1542CYInfix_(false, 7, ">>>", ShiftRightUnsigned)
1543CYInfix_(false, 8, "<", Less)
1544CYInfix_(false, 8, ">", Greater)
1545CYInfix_(false, 8, "<=", LessOrEqual)
1546CYInfix_(false, 8, ">=", GreaterOrEqual)
1547CYInfix_(true, 8, "instanceof", InstanceOf)
1548CYInfix_(true, 8, "in", In)
1549CYInfix_(false, 9, "==", Equal)
1550CYInfix_(false, 9, "!=", NotEqual)
1551CYInfix_(false, 9, "===", Identical)
1552CYInfix_(false, 9, "!==", NotIdentical)
1553CYInfix_(false, 10, "&", BitwiseAnd)
1554CYInfix_(false, 11, "^", BitwiseXOr)
1555CYInfix_(false, 12, "|", BitwiseOr)
1556CYInfix_(false, 13, "&&", LogicalAnd)
1557CYInfix_(false, 14, "||", LogicalOr)
cf7d4c69
JF
1558
1559CYAssignment_("=", )
1560CYAssignment_("*=", Multiply)
1561CYAssignment_("/=", Divide)
1562CYAssignment_("%=", Modulus)
1563CYAssignment_("+=", Add)
1564CYAssignment_("-=", Subtract)
1565CYAssignment_("<<=", ShiftLeft)
1566CYAssignment_(">>=", ShiftRightSigned)
1567CYAssignment_(">>>=", ShiftRightUnsigned)
1568CYAssignment_("&=", BitwiseAnd)
1569CYAssignment_("^=", BitwiseXOr)
1570CYAssignment_("|=", BitwiseOr)
1571
63b4c5a8 1572#endif/*CYPARSER_HPP*/