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