]> git.saurik.com Git - cycript.git/blame - Parser.hpp
Found the garbage collection bug from hell (classes apparently really need /something...
[cycript.git] / Parser.hpp
CommitLineData
4644480a 1/* Cycript - Remote Execution Server and Disassembler
b4aa79af
JF
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
4644480a
JF
283 operator CYStatement *() const {
284 return statements_;
285 }
286
3b52fd1a
JF
287 virtual CYStatement *Replace(CYContext &context);
288
289 virtual void Output(CYOutput &out) const;
fb98ac0c 290 virtual void Output(CYOutput &out, CYFlags flags) const;
cf7d4c69
JF
291};
292
db5e2840
JF
293enum CYState {
294 CYClear,
295 CYRestricted,
296 CYNewLine
297};
298
5999c315
JF
299class CYDriver {
300 public:
301 CYPool pool_;
e7ed5354 302
db5e2840 303 CYState state_;
e7ed5354
JF
304 void *scanner_;
305
306 const char *data_;
307 size_t size_;
48e3be8a 308 FILE *file_;
e7ed5354 309
b10bd496
JF
310 bool strict_;
311
63cd45c9
JF
312 enum Condition {
313 RegExStart,
314 RegExRest
315 };
316
5999c315 317 std::string filename_;
e7ed5354 318
5befe15e 319 struct Error {
b10bd496 320 bool warning_;
5befe15e
JF
321 cy::location location_;
322 std::string message_;
323 };
324
325 typedef std::vector<Error> Errors;
326
3b52fd1a 327 CYProgram *program_;
5befe15e 328 Errors errors_;
5999c315
JF
329
330 private:
331 void ScannerInit();
332 void ScannerDestroy();
333
334 public:
335 CYDriver(const std::string &filename);
336 ~CYDriver();
63cd45c9
JF
337
338 void SetCondition(Condition condition);
b10bd496
JF
339
340 void Warning(const cy::location &location, const char *message);
5999c315
JF
341};
342
cac61857 343struct CYForInitialiser {
652ec1ba 344 virtual void For(CYOutput &out) const = 0;
dea834b0
JF
345};
346
cac61857 347struct CYForInInitialiser {
652ec1ba 348 virtual void ForIn(CYOutput &out, CYFlags flags) const = 0;
75b0a457 349 virtual const char *ForEachIn() const = 0;
3b52fd1a 350 virtual CYExpression *ForEachIn(CYContext &out) = 0;
b09da87b
JF
351};
352
4644480a
JF
353struct CYNumber;
354struct CYString;
355
cf7d4c69 356struct CYExpression :
5999c315 357 CYNext<CYExpression>,
cf7d4c69 358 CYForInitialiser,
e5bc40db 359 CYForInInitialiser,
96a7e5c2
JF
360 CYClassName,
361 CYThing
63b4c5a8 362{
d35a3b07 363 virtual unsigned Precedence() const = 0;
75b0a457 364
fb98ac0c
JF
365 virtual bool RightHand() const {
366 return true;
367 }
368
652ec1ba
JF
369 virtual void For(CYOutput &out) const;
370 virtual void ForIn(CYOutput &out, CYFlags flags) const;
75b0a457 371
cac61857 372 virtual const char *ForEachIn() const;
3b52fd1a 373 virtual CYExpression *ForEachIn(CYContext &out);
75b0a457 374
96a7e5c2 375 virtual void Output(CYOutput &out) const;
652ec1ba
JF
376 virtual void Output(CYOutput &out, CYFlags flags) const = 0;
377 void Output(CYOutput &out, unsigned precedence, CYFlags flags) const;
dea834b0 378
3b52fd1a 379 virtual CYExpression *ClassName(CYContext &context, bool object);
652ec1ba 380 virtual void ClassName(CYOutput &out, bool object) const;
e5bc40db 381
3b52fd1a
JF
382 CYExpression *ReplaceAll(CYContext &context);
383
384 virtual CYExpression *Replace(CYContext &context) = 0;
385
4644480a
JF
386 virtual CYExpression *Primitive(CYContext &context) {
387 return this;
388 }
389
390 virtual CYNumber *Number(CYContext &context) {
391 return NULL;
392 }
393
394 virtual CYString *String(CYContext &context) {
395 return NULL;
396 }
397
dea834b0
JF
398 virtual const char *Word() const {
399 return NULL;
400 }
63b4c5a8
JF
401};
402
b09da87b
JF
403#define CYAlphabetic(value) \
404 virtual bool Alphabetic() const { \
405 return value; \
406 }
407
d35a3b07
JF
408#define CYPrecedence(value) \
409 virtual unsigned Precedence() const { \
410 return value; \
411 }
412
fb98ac0c
JF
413#define CYRightHand(value) \
414 virtual bool RightHand() const { \
415 return value; \
416 }
417
d35a3b07
JF
418struct CYCompound :
419 CYExpression
420{
421 CYExpression *expressions_;
422
423 CYCompound(CYExpression *expressions) :
424 expressions_(expressions)
425 {
426 }
427
428 void AddPrev(CYExpression *expression) {
429 CYExpression *last(expression);
430 while (last->next_ != NULL)
431 last = last->next_;
432 last->SetNext(expressions_);
433 expressions_ = expression;
434 }
435
436 CYPrecedence(17)
437
3b52fd1a 438 virtual CYExpression *Replace(CYContext &context);
652ec1ba 439 void Output(CYOutput &out, CYFlags flags) const;
d35a3b07 440};
5999c315 441
3b52fd1a
JF
442struct CYFunctionParameter :
443 CYNext<CYFunctionParameter>,
444 CYThing
445{
446 CYIdentifier *name_;
447
448 CYFunctionParameter(CYIdentifier *name, CYFunctionParameter *next = NULL) :
449 CYNext<CYFunctionParameter>(next),
450 name_(name)
451 {
452 }
453
454 virtual void Output(CYOutput &out) const;
455};
456
75b0a457 457struct CYComprehension :
96a7e5c2
JF
458 CYNext<CYComprehension>,
459 CYThing
75b0a457 460{
75b0a457
JF
461 virtual const char *Name() const = 0;
462
3b52fd1a
JF
463 virtual CYFunctionParameter *Parameter(CYContext &context) const = 0;
464 CYFunctionParameter *Parameters(CYContext &context) const;
465 virtual CYStatement *Replace(CYContext &context, CYStatement *statement) const;
4644480a 466 virtual void Output(CYOutput &out) const = 0;
75b0a457
JF
467};
468
469struct CYForInComprehension :
470 CYComprehension
471{
472 CYIdentifier *name_;
473 CYExpression *set_;
474
475 CYForInComprehension(CYIdentifier *name, CYExpression *set) :
476 name_(name),
477 set_(set)
478 {
479 }
480
481 virtual const char *Name() const {
482 return name_->Value();
483 }
484
3b52fd1a
JF
485 virtual CYFunctionParameter *Parameter(CYContext &context) const;
486 virtual CYStatement *Replace(CYContext &context, CYStatement *statement) const;
4644480a 487 virtual void Output(CYOutput &out) const;
75b0a457
JF
488};
489
490struct CYForEachInComprehension :
491 CYComprehension
492{
493 CYIdentifier *name_;
494 CYExpression *set_;
495
496 CYForEachInComprehension(CYIdentifier *name, CYExpression *set) :
497 name_(name),
498 set_(set)
499 {
500 }
501
502 virtual const char *Name() const {
503 return name_->Value();
504 }
505
3b52fd1a
JF
506 virtual CYFunctionParameter *Parameter(CYContext &context) const;
507 virtual CYStatement *Replace(CYContext &context, CYStatement *statement) const;
4644480a 508 virtual void Output(CYOutput &out) const;
75b0a457
JF
509};
510
511struct CYIfComprehension :
512 CYComprehension
513{
514 CYExpression *test_;
515
516 CYIfComprehension(CYExpression *test) :
517 test_(test)
518 {
519 }
520
521 virtual const char *Name() const {
522 return NULL;
523 }
524
3b52fd1a
JF
525 virtual CYFunctionParameter *Parameter(CYContext &context) const;
526 virtual CYStatement *Replace(CYContext &context, CYStatement *statement) const;
4644480a 527 virtual void Output(CYOutput &out) const;
75b0a457
JF
528};
529
530struct CYArrayComprehension :
531 CYExpression
532{
533 CYExpression *expression_;
534 CYComprehension *comprehensions_;
535
536 CYArrayComprehension(CYExpression *expression, CYComprehension *comprehensions) :
537 expression_(expression),
538 comprehensions_(comprehensions)
539 {
540 }
541
542 CYPrecedence(0)
543
3b52fd1a 544 virtual CYExpression *Replace(CYContext &context);
652ec1ba 545 virtual void Output(CYOutput &out, CYFlags flags) const;
75b0a457
JF
546};
547
cf7d4c69
JF
548struct CYLiteral :
549 CYExpression
63b4c5a8 550{
d35a3b07 551 CYPrecedence(0)
fb98ac0c 552 CYRightHand(false)
cf7d4c69 553};
63b4c5a8 554
3b52fd1a
JF
555struct CYTrivial :
556 CYLiteral
557{
558 virtual CYExpression *Replace(CYContext &context);
559};
560
478d4ed0
JF
561struct CYMagic :
562 CYExpression
563{
564 CYPrecedence(0)
fb98ac0c 565 CYRightHand(false)
478d4ed0
JF
566};
567
dea834b0
JF
568struct CYRange {
569 uint64_t lo_;
570 uint64_t hi_;
571
572 CYRange(uint64_t lo, uint64_t hi) :
573 lo_(lo), hi_(hi)
574 {
575 }
576
577 bool operator [](uint8_t value) const {
578 return !(value >> 7) && (value >> 6 ? hi_ : lo_) >> (value & 0x3f) & 0x1;
579 }
580
581 void operator()(uint8_t value) {
582 if (value >> 7)
583 return;
584 (value >> 6 ? hi_ : lo_) |= uint64_t(0x1) << (value & 0x3f);
585 }
586};
587
283e7e33 588extern CYRange DigitRange_;
dea834b0
JF
589extern CYRange WordStartRange_;
590extern CYRange WordEndRange_;
591
cf7d4c69 592struct CYString :
3b52fd1a 593 CYTrivial,
e5bc40db 594 CYPropertyName
cf7d4c69
JF
595{
596 const char *value_;
5999c315 597 size_t size_;
cf7d4c69 598
3b52fd1a
JF
599 CYString() :
600 value_(NULL),
601 size_(0)
602 {
603 }
604
605 CYString(const char *value) :
606 value_(value),
607 size_(strlen(value))
608 {
609 }
610
5999c315
JF
611 CYString(const char *value, size_t size) :
612 value_(value),
613 size_(size)
cf7d4c69
JF
614 {
615 }
616
3b52fd1a
JF
617 CYString(const CYWord *word) :
618 value_(word->Value()),
5999c315 619 size_(strlen(value_))
cf7d4c69
JF
620 {
621 }
622
5999c315 623 const char *Value() const {
cf7d4c69
JF
624 return value_;
625 }
626
11c1cc16 627 virtual const char *Word() const;
dea834b0 628
4644480a
JF
629 virtual CYNumber *Number(CYContext &context);
630 virtual CYString *String(CYContext &context);
631
632 virtual CYString *Concat(CYContext &out, CYString *rhs) const;
652ec1ba
JF
633 virtual void Output(CYOutput &out, CYFlags flags) const;
634 virtual void PropertyName(CYOutput &out) const;
63b4c5a8
JF
635};
636
cf7d4c69 637struct CYNumber :
3b52fd1a 638 CYTrivial,
e5bc40db 639 CYPropertyName
cf7d4c69 640{
5999c315
JF
641 double value_;
642
643 CYNumber(double value) :
644 value_(value)
645 {
646 }
647
648 double Value() const {
649 return value_;
cf7d4c69
JF
650 }
651
4644480a
JF
652 virtual CYNumber *Number(CYContext &context);
653 virtual CYString *String(CYContext &context);
654
652ec1ba
JF
655 virtual void Output(CYOutput &out, CYFlags flags) const;
656 virtual void PropertyName(CYOutput &out) const;
cf7d4c69
JF
657};
658
63cd45c9 659struct CYRegEx :
3b52fd1a 660 CYTrivial
63cd45c9
JF
661{
662 const char *value_;
663
664 CYRegEx(const char *value) :
665 value_(value)
666 {
667 }
668
669 const char *Value() const {
670 return value_;
671 }
672
673 virtual void Output(CYOutput &out, CYFlags flags) const;
674};
675
cf7d4c69
JF
676struct CYNull :
677 CYWord,
3b52fd1a 678 CYTrivial
cf7d4c69
JF
679{
680 CYNull() :
681 CYWord("null")
682 {
683 }
5999c315 684
4644480a
JF
685 virtual CYNumber *Number(CYContext &context);
686 virtual CYString *String(CYContext &context);
687
652ec1ba 688 virtual void Output(CYOutput &out, CYFlags flags) const;
cf7d4c69
JF
689};
690
691struct CYThis :
692 CYWord,
478d4ed0 693 CYMagic
cf7d4c69
JF
694{
695 CYThis() :
696 CYWord("this")
697 {
698 }
5999c315 699
3b52fd1a 700 virtual CYExpression *Replace(CYContext &context);
652ec1ba 701 virtual void Output(CYOutput &out, CYFlags flags) const;
cf7d4c69
JF
702};
703
704struct CYBoolean :
3b52fd1a 705 CYTrivial
cf7d4c69 706{
5999c315 707 virtual bool Value() const = 0;
652ec1ba 708 virtual void Output(CYOutput &out, CYFlags flags) const;
cf7d4c69
JF
709};
710
711struct CYFalse :
712 CYWord,
713 CYBoolean
714{
715 CYFalse() :
716 CYWord("false")
717 {
718 }
5999c315 719
11c1cc16
JF
720 virtual bool Value() const {
721 return false;
722 }
4644480a
JF
723
724 virtual CYNumber *Number(CYContext &context);
725 virtual CYString *String(CYContext &context);
cf7d4c69
JF
726};
727
728struct CYTrue :
729 CYWord,
730 CYBoolean
731{
732 CYTrue() :
733 CYWord("true")
734 {
735 }
5999c315 736
11c1cc16
JF
737 virtual bool Value() const {
738 return true;
739 }
4644480a
JF
740
741 virtual CYNumber *Number(CYContext &context);
742 virtual CYString *String(CYContext &context);
cf7d4c69
JF
743};
744
745struct CYVariable :
746 CYExpression
747{
748 CYIdentifier *name_;
749
750 CYVariable(CYIdentifier *name) :
751 name_(name)
752 {
753 }
5999c315 754
d35a3b07 755 CYPrecedence(0)
fb98ac0c 756 CYRightHand(false)
d35a3b07 757
3b52fd1a 758 virtual CYExpression *Replace(CYContext &context);
652ec1ba 759 virtual void Output(CYOutput &out, CYFlags flags) const;
cf7d4c69
JF
760};
761
762struct CYPrefix :
63b4c5a8
JF
763 CYExpression
764{
765 CYExpression *rhs_;
766
cf7d4c69 767 CYPrefix(CYExpression *rhs) :
63b4c5a8
JF
768 rhs_(rhs)
769 {
770 }
5999c315 771
b09da87b 772 virtual bool Alphabetic() const = 0;
5999c315
JF
773 virtual const char *Operator() const = 0;
774
3b52fd1a
JF
775 CYPrecedence(4)
776
777 virtual CYExpression *Replace(CYContext &context);
652ec1ba 778 virtual void Output(CYOutput &out, CYFlags flags) const;
63b4c5a8
JF
779};
780
cf7d4c69 781struct CYInfix :
63b4c5a8
JF
782 CYExpression
783{
784 CYExpression *lhs_;
785 CYExpression *rhs_;
786
cf7d4c69 787 CYInfix(CYExpression *lhs, CYExpression *rhs) :
63b4c5a8
JF
788 lhs_(lhs),
789 rhs_(rhs)
790 {
791 }
5999c315 792
0ff9f149
JF
793 void SetLeft(CYExpression *lhs) {
794 lhs_ = lhs;
795 }
796
b09da87b 797 virtual bool Alphabetic() const = 0;
5999c315
JF
798 virtual const char *Operator() const = 0;
799
3b52fd1a 800 virtual CYExpression *Replace(CYContext &context);
652ec1ba 801 virtual void Output(CYOutput &out, CYFlags flags) const;
63b4c5a8
JF
802};
803
cf7d4c69 804struct CYPostfix :
63b4c5a8
JF
805 CYExpression
806{
807 CYExpression *lhs_;
808
cf7d4c69 809 CYPostfix(CYExpression *lhs) :
63b4c5a8
JF
810 lhs_(lhs)
811 {
812 }
5999c315
JF
813
814 virtual const char *Operator() const = 0;
815
3b52fd1a
JF
816 CYPrecedence(3)
817
818 virtual CYExpression *Replace(CYContext &context);
652ec1ba 819 virtual void Output(CYOutput &out, CYFlags flags) const;
63b4c5a8
JF
820};
821
cf7d4c69 822struct CYAssignment :
d35a3b07 823 CYExpression
cf7d4c69 824{
d35a3b07
JF
825 CYExpression *lhs_;
826 CYExpression *rhs_;
827
cf7d4c69 828 CYAssignment(CYExpression *lhs, CYExpression *rhs) :
d35a3b07
JF
829 lhs_(lhs),
830 rhs_(rhs)
cf7d4c69
JF
831 {
832 }
5999c315 833
0ff9f149
JF
834 void SetLeft(CYExpression *lhs) {
835 lhs_ = lhs;
836 }
837
5999c315 838 virtual const char *Operator() const = 0;
d35a3b07 839
4de0686f
JF
840 CYPrecedence(16)
841
3b52fd1a 842 virtual CYExpression *Replace(CYContext &context);
652ec1ba 843 virtual void Output(CYOutput &out, CYFlags flags) const;
cf7d4c69
JF
844};
845
62014ea9 846struct CYArgument :
96a7e5c2
JF
847 CYNext<CYArgument>,
848 CYThing
62014ea9 849{
cf7d4c69
JF
850 CYWord *name_;
851 CYExpression *value_;
cf7d4c69 852
3b52fd1a
JF
853 CYArgument(CYExpression *value, CYArgument *next = NULL) :
854 CYNext<CYArgument>(next),
855 name_(NULL),
856 value_(value)
857 {
858 }
859
cf7d4c69 860 CYArgument(CYWord *name, CYExpression *value, CYArgument *next = NULL) :
62014ea9 861 CYNext<CYArgument>(next),
cf7d4c69 862 name_(name),
62014ea9 863 value_(value)
cf7d4c69
JF
864 {
865 }
5999c315 866
3b52fd1a 867 void Replace(CYContext &context);
652ec1ba 868 void Output(CYOutput &out) const;
cf7d4c69
JF
869};
870
871struct CYBlank :
872 public CYWord
873{
874 CYBlank() :
875 CYWord("")
876 {
877 }
878};
879
5999c315
JF
880struct CYClause :
881 CYThing,
882 CYNext<CYClause>
883{
cf7d4c69 884 CYExpression *case_;
3b52fd1a 885 CYStatement *statements_;
cf7d4c69 886
3b52fd1a 887 CYClause(CYExpression *_case, CYStatement *statements) :
cf7d4c69 888 case_(_case),
3b52fd1a 889 statements_(statements)
cf7d4c69
JF
890 {
891 }
892
fa389b0f 893 void Replace(CYContext &context);
652ec1ba 894 virtual void Output(CYOutput &out) const;
cf7d4c69
JF
895};
896
62014ea9 897struct CYElement :
96a7e5c2
JF
898 CYNext<CYElement>,
899 CYThing
62014ea9 900{
cf7d4c69 901 CYExpression *value_;
cf7d4c69
JF
902
903 CYElement(CYExpression *value, CYElement *next) :
62014ea9
JF
904 CYNext<CYElement>(next),
905 value_(value)
cf7d4c69
JF
906 {
907 }
5999c315 908
3b52fd1a 909 void Replace(CYContext &context);
652ec1ba 910 void Output(CYOutput &out) const;
5befe15e
JF
911};
912
913struct CYArray :
914 CYLiteral
915{
916 CYElement *elements_;
917
3b52fd1a 918 CYArray(CYElement *elements = NULL) :
5befe15e
JF
919 elements_(elements)
920 {
921 }
922
3b52fd1a 923 virtual CYExpression *Replace(CYContext &context);
652ec1ba 924 virtual void Output(CYOutput &out, CYFlags flags) const;
cf7d4c69
JF
925};
926
927struct CYDeclaration :
928 CYForInInitialiser
929{
930 CYIdentifier *identifier_;
931 CYExpression *initialiser_;
932
933 CYDeclaration(CYIdentifier *identifier, CYExpression *initialiser) :
934 identifier_(identifier),
935 initialiser_(initialiser)
936 {
937 }
5999c315 938
652ec1ba 939 virtual void ForIn(CYOutput &out, CYFlags flags) const;
75b0a457 940
cac61857 941 virtual const char *ForEachIn() const;
3b52fd1a
JF
942 virtual CYExpression *ForEachIn(CYContext &out);
943
944 void Replace(CYContext &context);
75b0a457 945
652ec1ba 946 virtual void Output(CYOutput &out, CYFlags flags) const;
cf7d4c69
JF
947};
948
949struct CYDeclarations :
cac61857 950 CYNext<CYDeclarations>,
96a7e5c2
JF
951 CYForInitialiser,
952 CYThing
cf7d4c69
JF
953{
954 CYDeclaration *declaration_;
cf7d4c69 955
cacd1a88 956 CYDeclarations(CYDeclaration *declaration, CYDeclarations *next = NULL) :
cac61857
JF
957 CYNext<CYDeclarations>(next),
958 declaration_(declaration)
959 {
960 }
961
652ec1ba 962 virtual void For(CYOutput &out) const;
96a7e5c2 963
3b52fd1a
JF
964 void Replace(CYContext &context);
965
96a7e5c2 966 virtual void Output(CYOutput &out) const;
652ec1ba 967 virtual void Output(CYOutput &out, CYFlags flags) const;
cac61857
JF
968};
969
970struct CYVar :
971 CYStatement
972{
973 CYDeclarations *declarations_;
974
975 CYVar(CYDeclarations *declarations) :
976 declarations_(declarations)
977 {
978 }
979
3b52fd1a 980 virtual CYStatement *Replace(CYContext &context);
fb98ac0c 981 virtual void Output(CYOutput &out, CYFlags flags) const;
cac61857
JF
982};
983
984struct CYLet :
985 CYStatement
986{
987 CYDeclarations *declarations_;
3b52fd1a 988 CYBlock code_;
cac61857
JF
989
990 CYLet(CYDeclarations *declarations, CYStatement *statements) :
991 declarations_(declarations),
3b52fd1a 992 code_(statements)
cf7d4c69
JF
993 {
994 }
5999c315 995
3b52fd1a 996 virtual CYStatement *Replace(CYContext &context);
fb98ac0c 997 virtual void Output(CYOutput &out, CYFlags flags) const;
cf7d4c69
JF
998};
999
cf7d4c69
JF
1000struct CYFor :
1001 CYStatement
1002{
1003 CYForInitialiser *initialiser_;
1004 CYExpression *test_;
1005 CYExpression *increment_;
1006 CYStatement *code_;
1007
1008 CYFor(CYForInitialiser *initialiser, CYExpression *test, CYExpression *increment, CYStatement *code) :
1009 initialiser_(initialiser),
1010 test_(test),
1011 increment_(increment),
1012 code_(code)
1013 {
1014 }
5999c315 1015
3b52fd1a 1016 virtual CYStatement *Replace(CYContext &context);
fb98ac0c 1017 virtual void Output(CYOutput &out, CYFlags flags) const;
cf7d4c69
JF
1018};
1019
1020struct CYForIn :
1021 CYStatement
1022{
1023 CYForInInitialiser *initialiser_;
1024 CYExpression *set_;
1025 CYStatement *code_;
1026
1027 CYForIn(CYForInInitialiser *initialiser, CYExpression *set, CYStatement *code) :
1028 initialiser_(initialiser),
1029 set_(set),
1030 code_(code)
1031 {
1032 }
5999c315 1033
3b52fd1a 1034 virtual CYStatement *Replace(CYContext &context);
fb98ac0c 1035 virtual void Output(CYOutput &out, CYFlags flags) const;
cf7d4c69
JF
1036};
1037
75b0a457
JF
1038struct CYForEachIn :
1039 CYStatement
1040{
1041 CYForInInitialiser *initialiser_;
1042 CYExpression *set_;
1043 CYStatement *code_;
1044
1045 CYForEachIn(CYForInInitialiser *initialiser, CYExpression *set, CYStatement *code) :
1046 initialiser_(initialiser),
1047 set_(set),
1048 code_(code)
1049 {
1050 }
1051
3b52fd1a 1052 virtual CYStatement *Replace(CYContext &context);
fb98ac0c 1053 virtual void Output(CYOutput &out, CYFlags flags) const;
75b0a457
JF
1054};
1055
62014ea9 1056struct CYProperty :
96a7e5c2
JF
1057 CYNext<CYProperty>,
1058 CYThing
62014ea9 1059{
e5bc40db 1060 CYPropertyName *name_;
cf7d4c69 1061 CYExpression *value_;
cf7d4c69 1062
3b52fd1a 1063 CYProperty(CYPropertyName *name, CYExpression *value, CYProperty *next = NULL) :
62014ea9 1064 CYNext<CYProperty>(next),
cf7d4c69 1065 name_(name),
62014ea9 1066 value_(value)
cf7d4c69
JF
1067 {
1068 }
5999c315 1069
3b52fd1a 1070 void Replace(CYContext &context);
652ec1ba 1071 virtual void Output(CYOutput &out) const;
cf7d4c69
JF
1072};
1073
693d501b
JF
1074struct CYObject :
1075 CYLiteral
1076{
3b52fd1a 1077 CYProperty *properties_;
693d501b 1078
3b52fd1a
JF
1079 CYObject(CYProperty *properties) :
1080 properties_(properties)
693d501b
JF
1081 {
1082 }
1083
3b52fd1a 1084 virtual CYExpression *Replace(CYContext &context);
652ec1ba 1085 void Output(CYOutput &out, CYFlags flags) const;
693d501b
JF
1086};
1087
5999c315
JF
1088struct CYCatch :
1089 CYThing
1090{
cf7d4c69 1091 CYIdentifier *name_;
3b52fd1a 1092 CYBlock code_;
cf7d4c69 1093
3b52fd1a 1094 CYCatch(CYIdentifier *name, CYStatement *statements) :
cf7d4c69 1095 name_(name),
3b52fd1a 1096 code_(statements)
cf7d4c69
JF
1097 {
1098 }
5999c315 1099
3b52fd1a 1100 void Replace(CYContext &context);
652ec1ba 1101 virtual void Output(CYOutput &out) const;
cf7d4c69
JF
1102};
1103
cf7d4c69
JF
1104struct CYMember :
1105 CYExpression
1106{
1107 CYExpression *object_;
1108 CYExpression *property_;
1109
1110 CYMember(CYExpression *object, CYExpression *property) :
1111 object_(object),
1112 property_(property)
1113 {
1114 }
5999c315 1115
9b5527f0
JF
1116 void SetLeft(CYExpression *object) {
1117 object_ = object;
1118 }
3b52fd1a
JF
1119
1120 void Replace_(CYContext &context);
9b5527f0
JF
1121};
1122
1123struct CYDirectMember :
1124 CYMember
1125{
1126 CYDirectMember(CYExpression *object, CYExpression *property) :
1127 CYMember(object, property)
1128 {
1129 }
1130
1131 CYPrecedence(1)
fb98ac0c 1132 CYRightHand(false)
9b5527f0 1133
3b52fd1a 1134 virtual CYExpression *Replace(CYContext &context);
652ec1ba 1135 virtual void Output(CYOutput &out, CYFlags flags) const;
9b5527f0
JF
1136};
1137
1138struct CYIndirectMember :
1139 CYMember
1140{
1141 CYIndirectMember(CYExpression *object, CYExpression *property) :
1142 CYMember(object, property)
1143 {
1144 }
1145
d35a3b07 1146 CYPrecedence(1)
fb98ac0c 1147 CYRightHand(false)
d35a3b07 1148
3b52fd1a 1149 virtual CYExpression *Replace(CYContext &context);
652ec1ba 1150 virtual void Output(CYOutput &out, CYFlags flags) const;
cf7d4c69
JF
1151};
1152
1153struct CYNew :
1154 CYExpression
1155{
1156 CYExpression *constructor_;
1157 CYArgument *arguments_;
1158
1159 CYNew(CYExpression *constructor, CYArgument *arguments) :
1160 constructor_(constructor),
1161 arguments_(arguments)
1162 {
1163 }
5999c315 1164
fb98ac0c
JF
1165 virtual unsigned Precedence() const {
1166 return arguments_ == NULL ? 2 : 1;
1167 }
1168
1169 CYRightHand(false)
d35a3b07 1170
3b52fd1a 1171 virtual CYExpression *Replace(CYContext &context);
652ec1ba 1172 virtual void Output(CYOutput &out, CYFlags flags) const;
cf7d4c69
JF
1173};
1174
1175struct CYCall :
1176 CYExpression
1177{
1178 CYExpression *function_;
1179 CYArgument *arguments_;
1180
3b52fd1a 1181 CYCall(CYExpression *function, CYArgument *arguments = NULL) :
cf7d4c69
JF
1182 function_(function),
1183 arguments_(arguments)
1184 {
1185 }
5999c315 1186
fb98ac0c
JF
1187 CYPrecedence(1)
1188 CYRightHand(false)
d35a3b07 1189
3b52fd1a 1190 virtual CYExpression *Replace(CYContext &context);
652ec1ba 1191 virtual void Output(CYOutput &out, CYFlags flags) const;
cf7d4c69
JF
1192};
1193
1194struct CYIf :
1195 CYStatement
1196{
1197 CYExpression *test_;
1198 CYStatement *true_;
1199 CYStatement *false_;
1200
3b52fd1a 1201 CYIf(CYExpression *test, CYStatement *_true, CYStatement *_false = NULL) :
cf7d4c69
JF
1202 test_(test),
1203 true_(_true),
1204 false_(_false)
1205 {
1206 }
5999c315 1207
3b52fd1a 1208 virtual CYStatement *Replace(CYContext &context);
fb98ac0c 1209 virtual void Output(CYOutput &out, CYFlags flags) const;
cf7d4c69
JF
1210};
1211
1212struct CYDoWhile :
1213 CYStatement
1214{
1215 CYExpression *test_;
1216 CYStatement *code_;
1217
1218 CYDoWhile(CYExpression *test, CYStatement *code) :
1219 test_(test),
1220 code_(code)
1221 {
1222 }
5999c315 1223
3b52fd1a 1224 virtual CYStatement *Replace(CYContext &context);
fb98ac0c 1225 virtual void Output(CYOutput &out, CYFlags flags) const;
cf7d4c69
JF
1226};
1227
1228struct CYWhile :
1229 CYStatement
1230{
1231 CYExpression *test_;
1232 CYStatement *code_;
1233
1234 CYWhile(CYExpression *test, CYStatement *code) :
1235 test_(test),
1236 code_(code)
1237 {
1238 }
5999c315 1239
3b52fd1a 1240 virtual CYStatement *Replace(CYContext &context);
fb98ac0c 1241 virtual void Output(CYOutput &out, CYFlags flags) const;
cf7d4c69
JF
1242};
1243
fb98ac0c 1244struct CYFunction {
cf7d4c69 1245 CYIdentifier *name_;
b09da87b 1246 CYFunctionParameter *parameters_;
3b52fd1a 1247 CYBlock code_;
cf7d4c69 1248
3b52fd1a 1249 CYFunction(CYIdentifier *name, CYFunctionParameter *parameters, CYStatement *statements) :
cf7d4c69
JF
1250 name_(name),
1251 parameters_(parameters),
3b52fd1a 1252 code_(statements)
cf7d4c69
JF
1253 {
1254 }
5999c315 1255
3b52fd1a 1256 virtual void Replace_(CYContext &context);
fb98ac0c
JF
1257 virtual void Output(CYOutput &out, CYFlags flags) const;
1258};
1259
1260struct CYFunctionExpression :
1261 CYFunction,
1262 CYExpression
1263{
3b52fd1a
JF
1264 CYFunctionExpression(CYIdentifier *name, CYFunctionParameter *parameters, CYStatement *statements) :
1265 CYFunction(name, parameters, statements)
fb98ac0c
JF
1266 {
1267 }
1268
d35a3b07 1269 CYPrecedence(0)
fb98ac0c 1270 CYRightHand(false)
d35a3b07 1271
3b52fd1a 1272 virtual CYExpression *Replace(CYContext &context);
652ec1ba 1273 virtual void Output(CYOutput &out, CYFlags flags) const;
cf7d4c69
JF
1274};
1275
fb98ac0c
JF
1276struct CYFunctionStatement :
1277 CYFunction,
b10bd496 1278 CYStatement
cf7d4c69 1279{
3b52fd1a
JF
1280 CYFunctionStatement(CYIdentifier *name, CYFunctionParameter *parameters, CYStatement *statements) :
1281 CYFunction(name, parameters, statements)
cf7d4c69
JF
1282 {
1283 }
5999c315 1284
3b52fd1a 1285 virtual CYStatement *Replace(CYContext &context);
fb98ac0c 1286 virtual void Output(CYOutput &out, CYFlags flags) const;
5999c315
JF
1287};
1288
1289struct CYExpress :
1290 CYStatement
1291{
1292 CYExpression *expression_;
1293
1294 CYExpress(CYExpression *expression) :
1295 expression_(expression)
1296 {
1297 }
1298
3b52fd1a 1299 virtual CYStatement *Replace(CYContext &context);
fb98ac0c 1300 virtual void Output(CYOutput &out, CYFlags flags) const;
cf7d4c69
JF
1301};
1302
1303struct CYContinue :
1304 CYStatement
1305{
1306 CYIdentifier *label_;
1307
1308 CYContinue(CYIdentifier *label) :
1309 label_(label)
1310 {
1311 }
5999c315 1312
3b52fd1a 1313 virtual CYStatement *Replace(CYContext &context);
fb98ac0c 1314 virtual void Output(CYOutput &out, CYFlags flags) const;
cf7d4c69
JF
1315};
1316
1317struct CYBreak :
1318 CYStatement
1319{
1320 CYIdentifier *label_;
1321
1322 CYBreak(CYIdentifier *label) :
1323 label_(label)
1324 {
1325 }
5999c315 1326
3b52fd1a 1327 virtual CYStatement *Replace(CYContext &context);
fb98ac0c 1328 virtual void Output(CYOutput &out, CYFlags flags) const;
cf7d4c69
JF
1329};
1330
1331struct CYReturn :
1332 CYStatement
1333{
1334 CYExpression *value_;
1335
1336 CYReturn(CYExpression *value) :
1337 value_(value)
1338 {
1339 }
5999c315 1340
3b52fd1a 1341 virtual CYStatement *Replace(CYContext &context);
fb98ac0c 1342 virtual void Output(CYOutput &out, CYFlags flags) const;
cf7d4c69
JF
1343};
1344
1345struct CYEmpty :
1346 CYStatement
1347{
3b52fd1a 1348 virtual CYStatement *Replace(CYContext &context);
fb98ac0c 1349 virtual void Output(CYOutput &out, CYFlags flags) const;
cf7d4c69
JF
1350};
1351
96a7e5c2
JF
1352struct CYFinally :
1353 CYThing
1354{
3b52fd1a 1355 CYBlock code_;
b10bd496 1356
3b52fd1a
JF
1357 CYFinally(CYStatement *statements) :
1358 code_(statements)
b10bd496
JF
1359 {
1360 }
1361
3b52fd1a 1362 void Replace(CYContext &context);
b10bd496
JF
1363 virtual void Output(CYOutput &out) const;
1364};
1365
cf7d4c69
JF
1366struct CYTry :
1367 CYStatement
1368{
3b52fd1a 1369 CYBlock code_;
cf7d4c69 1370 CYCatch *catch_;
b10bd496 1371 CYFinally *finally_;
cf7d4c69 1372
3b52fd1a
JF
1373 CYTry(CYStatement *statements, CYCatch *_catch, CYFinally *finally) :
1374 code_(statements),
cf7d4c69
JF
1375 catch_(_catch),
1376 finally_(finally)
1377 {
1378 }
5999c315 1379
3b52fd1a 1380 virtual CYStatement *Replace(CYContext &context);
fb98ac0c 1381 virtual void Output(CYOutput &out, CYFlags flags) const;
cf7d4c69
JF
1382};
1383
1384struct CYThrow :
1385 CYStatement
1386{
1387 CYExpression *value_;
1388
1389 CYThrow(CYExpression *value) :
1390 value_(value)
1391 {
1392 }
5999c315 1393
3b52fd1a 1394 virtual CYStatement *Replace(CYContext &context);
fb98ac0c 1395 virtual void Output(CYOutput &out, CYFlags flags) const;
cf7d4c69
JF
1396};
1397
1398struct CYWith :
1399 CYStatement
1400{
1401 CYExpression *scope_;
1402 CYStatement *code_;
1403
1404 CYWith(CYExpression *scope, CYStatement *code) :
1405 scope_(scope),
1406 code_(code)
1407 {
1408 }
5999c315 1409
3b52fd1a 1410 virtual CYStatement *Replace(CYContext &context);
fb98ac0c 1411 virtual void Output(CYOutput &out, CYFlags flags) const;
cf7d4c69
JF
1412};
1413
1414struct CYSwitch :
1415 CYStatement
1416{
1417 CYExpression *value_;
1418 CYClause *clauses_;
1419
1420 CYSwitch(CYExpression *value, CYClause *clauses) :
1421 value_(value),
1422 clauses_(clauses)
1423 {
1424 }
5999c315 1425
3b52fd1a 1426 virtual CYStatement *Replace(CYContext &context);
fb98ac0c 1427 virtual void Output(CYOutput &out, CYFlags flags) const;
cf7d4c69
JF
1428};
1429
1430struct CYCondition :
1431 CYExpression
1432{
1433 CYExpression *test_;
1434 CYExpression *true_;
1435 CYExpression *false_;
1436
1437 CYCondition(CYExpression *test, CYExpression *_true, CYExpression *_false) :
91a416e4 1438 test_(test),
cf7d4c69
JF
1439 true_(_true),
1440 false_(_false)
1441 {
1442 }
5999c315 1443
d35a3b07
JF
1444 CYPrecedence(15)
1445
3b52fd1a 1446 virtual CYExpression *Replace(CYContext &context);
652ec1ba 1447 virtual void Output(CYOutput &out, CYFlags flags) const;
5999c315
JF
1448};
1449
1450struct CYAddressOf :
1451 CYPrefix
1452{
1453 CYAddressOf(CYExpression *rhs) :
1454 CYPrefix(rhs)
1455 {
1456 }
1457
1458 virtual const char *Operator() const {
1459 return "&";
1460 }
1461
b09da87b 1462 CYAlphabetic(false)
d35a3b07 1463
3b52fd1a 1464 virtual CYExpression *Replace(CYContext &context);
5999c315
JF
1465};
1466
1467struct CYIndirect :
1468 CYPrefix
1469{
1470 CYIndirect(CYExpression *rhs) :
1471 CYPrefix(rhs)
1472 {
1473 }
1474
1475 virtual const char *Operator() const {
1476 return "*";
1477 }
1478
b09da87b 1479 CYAlphabetic(false)
d35a3b07 1480
3b52fd1a 1481 virtual CYExpression *Replace(CYContext &context);
cf7d4c69
JF
1482};
1483
4644480a
JF
1484#define CYReplace \
1485 virtual CYExpression *Replace(CYContext &context);
1486
1487#define CYPostfix_(op, name, args...) \
cf7d4c69
JF
1488 struct CY ## name : \
1489 CYPostfix \
4644480a 1490 { args \
cf7d4c69
JF
1491 CY ## name(CYExpression *lhs) : \
1492 CYPostfix(lhs) \
1493 { \
1494 } \
5999c315
JF
1495 \
1496 virtual const char *Operator() const { \
1497 return op; \
1498 } \
cf7d4c69
JF
1499 };
1500
4644480a 1501#define CYPrefix_(alphabetic, op, name, args...) \
cf7d4c69
JF
1502 struct CY ## name : \
1503 CYPrefix \
4644480a 1504 { args \
cf7d4c69
JF
1505 CY ## name(CYExpression *rhs) : \
1506 CYPrefix(rhs) \
1507 { \
1508 } \
d35a3b07 1509 \
b09da87b 1510 CYAlphabetic(alphabetic) \
5999c315
JF
1511 \
1512 virtual const char *Operator() const { \
1513 return op; \
1514 } \
cf7d4c69
JF
1515 };
1516
4644480a 1517#define CYInfix_(alphabetic, precedence, op, name, args...) \
cf7d4c69
JF
1518 struct CY ## name : \
1519 CYInfix \
4644480a 1520 { args \
cf7d4c69
JF
1521 CY ## name(CYExpression *lhs, CYExpression *rhs) : \
1522 CYInfix(lhs, rhs) \
1523 { \
1524 } \
d35a3b07 1525 \
b09da87b 1526 CYAlphabetic(alphabetic) \
d35a3b07 1527 CYPrecedence(precedence) \
5999c315
JF
1528 \
1529 virtual const char *Operator() const { \
1530 return op; \
1531 } \
cf7d4c69
JF
1532 };
1533
4644480a 1534#define CYAssignment_(op, name, args...) \
cf7d4c69
JF
1535 struct CY ## name ## Assign : \
1536 CYAssignment \
4644480a 1537 { args \
cf7d4c69
JF
1538 CY ## name ## Assign(CYExpression *lhs, CYExpression *rhs) : \
1539 CYAssignment(lhs, rhs) \
1540 { \
1541 } \
5999c315
JF
1542 \
1543 virtual const char *Operator() const { \
1544 return op; \
1545 } \
cf7d4c69
JF
1546 };
1547
1548CYPostfix_("++", PostIncrement)
1549CYPostfix_("--", PostDecrement)
1550
b09da87b
JF
1551CYPrefix_(true, "delete", Delete)
1552CYPrefix_(true, "void", Void)
1553CYPrefix_(true, "typeof", TypeOf)
1554CYPrefix_(false, "++", PreIncrement)
1555CYPrefix_(false, "--", PreDecrement)
c0bc320e 1556CYPrefix_(false, "+", Affirm)
b09da87b
JF
1557CYPrefix_(false, "-", Negate)
1558CYPrefix_(false, "~", BitwiseNot)
1559CYPrefix_(false, "!", LogicalNot)
1560
1561CYInfix_(false, 5, "*", Multiply)
1562CYInfix_(false, 5, "/", Divide)
1563CYInfix_(false, 5, "%", Modulus)
4644480a 1564CYInfix_(false, 6, "+", Add, CYReplace)
b09da87b
JF
1565CYInfix_(false, 6, "-", Subtract)
1566CYInfix_(false, 7, "<<", ShiftLeft)
1567CYInfix_(false, 7, ">>", ShiftRightSigned)
1568CYInfix_(false, 7, ">>>", ShiftRightUnsigned)
1569CYInfix_(false, 8, "<", Less)
1570CYInfix_(false, 8, ">", Greater)
1571CYInfix_(false, 8, "<=", LessOrEqual)
1572CYInfix_(false, 8, ">=", GreaterOrEqual)
1573CYInfix_(true, 8, "instanceof", InstanceOf)
1574CYInfix_(true, 8, "in", In)
1575CYInfix_(false, 9, "==", Equal)
1576CYInfix_(false, 9, "!=", NotEqual)
1577CYInfix_(false, 9, "===", Identical)
1578CYInfix_(false, 9, "!==", NotIdentical)
1579CYInfix_(false, 10, "&", BitwiseAnd)
1580CYInfix_(false, 11, "^", BitwiseXOr)
1581CYInfix_(false, 12, "|", BitwiseOr)
1582CYInfix_(false, 13, "&&", LogicalAnd)
1583CYInfix_(false, 14, "||", LogicalOr)
cf7d4c69
JF
1584
1585CYAssignment_("=", )
1586CYAssignment_("*=", Multiply)
1587CYAssignment_("/=", Divide)
1588CYAssignment_("%=", Modulus)
1589CYAssignment_("+=", Add)
1590CYAssignment_("-=", Subtract)
1591CYAssignment_("<<=", ShiftLeft)
1592CYAssignment_(">>=", ShiftRightSigned)
1593CYAssignment_(">>>=", ShiftRightUnsigned)
1594CYAssignment_("&=", BitwiseAnd)
1595CYAssignment_("^=", BitwiseXOr)
1596CYAssignment_("|=", BitwiseOr)
1597
63b4c5a8 1598#endif/*CYPARSER_HPP*/