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