]> git.saurik.com Git - cycript.git/blob - Syntax.hpp
Detect Ruby library installation during configure.
[cycript.git] / Syntax.hpp
1 /* Cycript - Optimizing JavaScript Compiler/Runtime
2 * Copyright (C) 2009-2015 Jay Freeman (saurik)
3 */
4
5 /* GNU Affero General Public License, Version 3 {{{ */
6 /*
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Affero General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Affero General Public License for more details.
16
17 * You should have received a copy of the GNU Affero General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 **/
20 /* }}} */
21
22 #ifndef CYCRIPT_SYNTAX_HPP
23 #define CYCRIPT_SYNTAX_HPP
24
25 #include <cstdio>
26 #include <cstdlib>
27
28 #include <streambuf>
29 #include <string>
30 #include <vector>
31
32 #include "List.hpp"
33 #include "Location.hpp"
34 #include "Options.hpp"
35 #include "Pooling.hpp"
36 #include "String.hpp"
37
38 double CYCastDouble(const char *value, size_t size);
39 double CYCastDouble(const char *value);
40 double CYCastDouble(CYUTF8String value);
41
42 void CYNumerify(std::ostringstream &str, double value);
43 void CYStringify(std::ostringstream &str, const char *data, size_t size, bool c = false);
44
45 // XXX: this really should not be here ... :/
46 void *CYPoolFile(CYPool &pool, const char *path, size_t *psize);
47 CYUTF8String CYPoolFileUTF8String(CYPool &pool, const char *path);
48
49 struct CYContext;
50
51 struct CYThing {
52 virtual void Output(struct CYOutput &out) const = 0;
53 };
54
55 struct CYOutput {
56 std::streambuf &out_;
57 CYPosition position_;
58
59 CYOptions &options_;
60 bool pretty_;
61 unsigned indent_;
62 unsigned recent_;
63 bool right_;
64
65 enum {
66 NoMode,
67 NoLetter,
68 NoPlus,
69 NoHyphen,
70 Terminated
71 } mode_;
72
73 CYOutput(std::streambuf &out, CYOptions &options) :
74 out_(out),
75 options_(options),
76 pretty_(false),
77 indent_(0),
78 recent_(0),
79 right_(false),
80 mode_(NoMode)
81 {
82 }
83
84 void Check(char value);
85 void Terminate();
86
87 _finline void operator ()(char value) {
88 _assert(out_.sputc(value) != EOF);
89 recent_ = indent_;
90 if (value == '\n')
91 position_.Lines(1);
92 else
93 position_.Columns(1);
94 }
95
96 _finline void operator ()(const char *data, std::streamsize size) {
97 _assert(out_.sputn(data, size) == size);
98 recent_ = indent_;
99 position_.Columns(size);
100 }
101
102 _finline void operator ()(const char *data) {
103 return operator ()(data, strlen(data));
104 }
105
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);
112 return *this;
113 }
114
115 _finline CYOutput &operator <<(const CYThing &rhs) {
116 rhs.Output(*this);
117 return *this;
118 }
119 };
120
121 struct CYExpression;
122 struct CYAssignment;
123
124 struct CYPropertyName {
125 virtual bool Computed() const {
126 return false;
127 }
128
129 virtual bool Constructor() const {
130 return false;
131 }
132
133 virtual CYExpression *PropertyName(CYContext &context) = 0;
134 virtual void PropertyName(CYOutput &out) const = 0;
135 };
136
137 enum CYNeeded {
138 CYNever = -1,
139 CYSometimes = 0,
140 CYAlways = 1,
141 };
142
143 enum CYFlags {
144 CYNoFlags = 0,
145 CYNoBrace = (1 << 0),
146 CYNoFunction = (1 << 1),
147 CYNoClass = (1 << 2),
148 CYNoIn = (1 << 3),
149 CYNoCall = (1 << 4),
150 CYNoRightHand = (1 << 5),
151 CYNoDangle = (1 << 6),
152 CYNoInteger = (1 << 7),
153 CYNoColon = (1 << 8),
154 CYNoBFC = (CYNoBrace | CYNoFunction | CYNoClass),
155 };
156
157 _finline CYFlags operator ~(CYFlags rhs) {
158 return static_cast<CYFlags>(~static_cast<unsigned>(rhs));
159 }
160
161 _finline CYFlags operator &(CYFlags lhs, CYFlags rhs) {
162 return static_cast<CYFlags>(static_cast<unsigned>(lhs) & static_cast<unsigned>(rhs));
163 }
164
165 _finline CYFlags operator |(CYFlags lhs, CYFlags rhs) {
166 return static_cast<CYFlags>(static_cast<unsigned>(lhs) | static_cast<unsigned>(rhs));
167 }
168
169 _finline CYFlags &operator |=(CYFlags &lhs, CYFlags rhs) {
170 return lhs = lhs | rhs;
171 }
172
173 _finline CYFlags CYLeft(CYFlags flags) {
174 return flags & ~(CYNoDangle | CYNoInteger);
175 }
176
177 _finline CYFlags CYRight(CYFlags flags) {
178 return flags & ~CYNoBFC;
179 }
180
181 _finline CYFlags CYCenter(CYFlags flags) {
182 return CYLeft(CYRight(flags));
183 }
184
185 enum CYCompactType {
186 CYCompactNone,
187 CYCompactLong,
188 CYCompactShort,
189 };
190
191 #define CYCompact(type) \
192 virtual CYCompactType Compact() const { \
193 return CYCompact ## type; \
194 }
195
196 struct CYStatement :
197 CYNext<CYStatement>,
198 CYThing
199 {
200 void Single(CYOutput &out, CYFlags flags, CYCompactType request) const;
201 void Multiple(CYOutput &out, CYFlags flags = CYNoFlags) const;
202 virtual void Output(CYOutput &out) const;
203
204 virtual CYStatement *Replace(CYContext &context) = 0;
205
206 virtual CYCompactType Compact() const = 0;
207 virtual CYStatement *Return();
208
209 private:
210 virtual void Output(CYOutput &out, CYFlags flags) const = 0;
211 };
212
213 typedef CYList<CYStatement> CYStatements;
214
215 struct CYForInitializer :
216 CYStatement
217 {
218 virtual CYForInitializer *Replace(CYContext &context) = 0;
219 virtual void Output(CYOutput &out, CYFlags flags) const = 0;
220 };
221
222 struct CYWord :
223 CYThing,
224 CYPropertyName
225 {
226 const char *word_;
227
228 CYWord(const char *word) :
229 word_(word)
230 {
231 }
232
233 virtual bool Constructor() const {
234 return strcmp(word_, "constructor") == 0;
235 }
236
237 virtual const char *Word() const;
238 virtual void Output(CYOutput &out) const;
239
240 virtual CYExpression *PropertyName(CYContext &context);
241 virtual void PropertyName(CYOutput &out) const;
242 };
243
244 _finline std::ostream &operator <<(std::ostream &lhs, const CYWord &rhs) {
245 lhs << &rhs << '=';
246 return lhs << rhs.Word();
247 }
248
249 enum CYIdentifierKind {
250 CYIdentifierArgument,
251 CYIdentifierCatch,
252 CYIdentifierGlobal,
253 CYIdentifierLexical,
254 CYIdentifierMagic,
255 CYIdentifierOther,
256 CYIdentifierVariable,
257 };
258
259 struct CYIdentifier :
260 CYNext<CYIdentifier>,
261 CYWord
262 {
263 CYLocation location_;
264 size_t offset_;
265 size_t usage_;
266
267 CYIdentifier(const char *word) :
268 CYWord(word),
269 offset_(0),
270 usage_(0)
271 {
272 }
273
274 virtual const char *Word() const;
275 CYIdentifier *Replace(CYContext &context, CYIdentifierKind);
276 };
277
278 struct CYLabel :
279 CYStatement
280 {
281 CYIdentifier *name_;
282 CYStatement *statement_;
283
284 CYLabel(CYIdentifier *name, CYStatement *statement) :
285 name_(name),
286 statement_(statement)
287 {
288 }
289
290 CYCompact(Short)
291
292 virtual CYStatement *Replace(CYContext &context);
293 virtual void Output(CYOutput &out, CYFlags flags) const;
294 };
295
296 struct CYCStringLess :
297 std::binary_function<const char *, const char *, bool>
298 {
299 _finline bool operator ()(const char *lhs, const char *rhs) const {
300 return strcmp(lhs, rhs) < 0;
301 }
302 };
303
304 struct CYIdentifierValueLess :
305 std::binary_function<CYIdentifier *, CYIdentifier *, bool>
306 {
307 _finline bool operator ()(CYIdentifier *lhs, CYIdentifier *rhs) const {
308 return CYCStringLess()(lhs->Word(), rhs->Word());
309 }
310 };
311
312 struct CYIdentifierFlags :
313 CYNext<CYIdentifierFlags>
314 {
315 CYIdentifier *identifier_;
316 CYIdentifierKind kind_;
317 unsigned count_;
318 unsigned offset_;
319
320 CYIdentifierFlags(CYIdentifier *identifier, CYIdentifierKind kind, CYIdentifierFlags *next = NULL) :
321 CYNext<CYIdentifierFlags>(next),
322 identifier_(identifier),
323 kind_(kind),
324 count_(0),
325 offset_(0)
326 {
327 }
328 };
329
330 struct CYScope {
331 bool transparent_;
332 CYScope *parent_;
333 bool damaged_;
334 CYIdentifierFlags *shadow_;
335
336 CYIdentifierFlags *internal_;
337
338 CYScope(bool transparent, CYContext &context);
339
340 CYIdentifierFlags *Lookup(CYContext &context, const char *word);
341 CYIdentifierFlags *Lookup(CYContext &context, CYIdentifier *identifier);
342
343 CYIdentifierFlags *Declare(CYContext &context, CYIdentifier *identifier, CYIdentifierKind kind);
344 void Merge(CYContext &context, const CYIdentifierFlags *flags);
345
346 void Close(CYContext &context, CYStatement *&statements);
347 void Close(CYContext &context);
348 void Damage();
349 };
350
351 struct CYScript :
352 CYThing
353 {
354 CYStatement *code_;
355
356 CYScript(CYStatement *code) :
357 code_(code)
358 {
359 }
360
361 virtual void Replace(CYContext &context);
362 virtual void Output(CYOutput &out) const;
363 };
364
365 struct CYNonLocal;
366 struct CYThisScope;
367
368 struct CYContext {
369 CYOptions &options_;
370
371 CYScope *scope_;
372 CYThisScope *this_;
373 CYIdentifier *super_;
374
375 CYNonLocal *nonlocal_;
376 CYNonLocal *nextlocal_;
377 unsigned unique_;
378
379 std::vector<CYIdentifier *> replace_;
380
381 CYContext(CYOptions &options) :
382 options_(options),
383 scope_(NULL),
384 this_(NULL),
385 super_(NULL),
386 nonlocal_(NULL),
387 nextlocal_(NULL),
388 unique_(0)
389 {
390 }
391
392 void ReplaceAll(CYStatement *&statement) {
393 if (statement == NULL)
394 return;
395 CYStatement *next(statement->next_);
396
397 Replace(statement);
398 ReplaceAll(next);
399
400 if (statement == NULL)
401 statement = next;
402 else
403 statement->SetNext(next);
404 }
405
406 template <typename Type_>
407 void Replace(Type_ *&value) {
408 for (;;) if (value == NULL)
409 break;
410 else {
411 Type_ *replace(value->Replace(*this));
412 if (replace != value)
413 value = replace;
414 else break;
415 }
416 }
417
418 void NonLocal(CYStatement *&statements);
419 CYIdentifier *Unique();
420 };
421
422 struct CYNonLocal {
423 CYIdentifier *identifier_;
424
425 CYNonLocal() :
426 identifier_(NULL)
427 {
428 }
429
430 CYIdentifier *Target(CYContext &context) {
431 if (identifier_ == NULL)
432 identifier_ = context.Unique();
433 return identifier_;
434 }
435 };
436
437 struct CYThisScope :
438 CYNext<CYThisScope>
439 {
440 CYIdentifier *identifier_;
441
442 CYThisScope() :
443 identifier_(NULL)
444 {
445 }
446
447 CYIdentifier *Identifier(CYContext &context) {
448 if (next_ != NULL)
449 return next_->Identifier(context);
450 if (identifier_ == NULL)
451 identifier_ = context.Unique();
452 return identifier_;
453 }
454 };
455
456 struct CYBlock :
457 CYStatement
458 {
459 CYStatement *code_;
460
461 CYBlock(CYStatement *code) :
462 code_(code)
463 {
464 }
465
466 CYCompact(Short)
467
468 virtual CYStatement *Replace(CYContext &context);
469
470 virtual void Output(CYOutput &out, CYFlags flags) const;
471
472 virtual CYStatement *Return();
473 };
474
475 struct CYTarget;
476 struct CYVar;
477
478 struct CYForInInitializer {
479 virtual CYStatement *Initialize(CYContext &context, CYExpression *value) = 0;
480
481 virtual CYTarget *Replace(CYContext &context) = 0;
482 virtual void Output(CYOutput &out, CYFlags flags) const = 0;
483 };
484
485 struct CYFunctionParameter;
486
487 struct CYNumber;
488 struct CYString;
489
490 struct CYExpression :
491 CYThing
492 {
493 virtual int Precedence() const = 0;
494
495 virtual bool RightHand() const {
496 return true;
497 }
498
499 virtual bool Eval() const {
500 return false;
501 }
502
503 virtual CYTarget *AddArgument(CYContext &context, CYExpression *value);
504
505 virtual void Output(CYOutput &out) const;
506 virtual void Output(CYOutput &out, CYFlags flags) const = 0;
507 void Output(CYOutput &out, int precedence, CYFlags flags) const;
508
509 virtual CYExpression *Replace(CYContext &context) = 0;
510
511 virtual CYExpression *Primitive(CYContext &context) {
512 return NULL;
513 }
514
515 virtual CYFunctionParameter *Parameter() const;
516
517 virtual CYNumber *Number(CYContext &context) {
518 return NULL;
519 }
520
521 virtual CYString *String(CYContext &context) {
522 return NULL;
523 }
524
525 virtual const char *Word() const {
526 return NULL;
527 }
528 };
529
530 struct CYTarget :
531 CYExpression,
532 CYForInInitializer
533 {
534 virtual bool RightHand() const {
535 return false;
536 }
537
538 virtual CYStatement *Initialize(CYContext &context, CYExpression *value);
539
540 virtual CYTarget *Replace(CYContext &context) = 0;
541 using CYExpression::Output;
542 };
543
544 #define CYAlphabetic(value) \
545 virtual bool Alphabetic() const { \
546 return value; \
547 }
548
549 #define CYPrecedence(value) \
550 static const int Precedence_ = value; \
551 virtual int Precedence() const { \
552 return Precedence_; \
553 }
554
555 struct CYCompound :
556 CYExpression
557 {
558 CYExpression *expression_;
559 CYExpression *next_;
560
561 CYCompound(CYExpression *expression, CYExpression *next) :
562 expression_(expression),
563 next_(next)
564 {
565 _assert(expression_ != NULL);
566 _assert(next != NULL);
567 }
568
569 CYPrecedence(17)
570
571 virtual CYExpression *Replace(CYContext &context);
572 void Output(CYOutput &out, CYFlags flags) const;
573
574 virtual CYFunctionParameter *Parameter() const;
575 };
576
577 struct CYParenthetical :
578 CYTarget
579 {
580 CYExpression *expression_;
581
582 CYParenthetical(CYExpression *expression) :
583 expression_(expression)
584 {
585 }
586
587 CYPrecedence(0)
588
589 virtual CYTarget *Replace(CYContext &context);
590 void Output(CYOutput &out, CYFlags flags) const;
591 };
592
593 struct CYBinding;
594
595 struct CYFunctionParameter :
596 CYNext<CYFunctionParameter>,
597 CYThing
598 {
599 CYBinding *binding_;
600
601 CYFunctionParameter(CYBinding *binding, CYFunctionParameter *next = NULL) :
602 CYNext<CYFunctionParameter>(next),
603 binding_(binding)
604 {
605 }
606
607 void Replace(CYContext &context, CYStatement *&statements);
608 void Output(CYOutput &out) const;
609 };
610
611 struct CYComprehension :
612 CYNext<CYComprehension>,
613 CYThing
614 {
615 CYComprehension(CYComprehension *next = NULL) :
616 CYNext<CYComprehension>(next)
617 {
618 }
619
620 virtual CYFunctionParameter *Parameter(CYContext &context) const = 0;
621 CYFunctionParameter *Parameters(CYContext &context) const;
622 virtual CYStatement *Replace(CYContext &context, CYStatement *statement) const;
623 virtual void Output(CYOutput &out) const = 0;
624 };
625
626 struct CYForInComprehension :
627 CYComprehension
628 {
629 CYBinding *binding_;
630 CYExpression *iterable_;
631
632 CYForInComprehension(CYBinding *binding, CYExpression *iterable, CYComprehension *next = NULL) :
633 CYComprehension(next),
634 binding_(binding),
635 iterable_(iterable)
636 {
637 }
638
639 virtual CYFunctionParameter *Parameter(CYContext &context) const;
640 virtual CYStatement *Replace(CYContext &context, CYStatement *statement) const;
641 virtual void Output(CYOutput &out) const;
642 };
643
644 struct CYForOfComprehension :
645 CYComprehension
646 {
647 CYBinding *binding_;
648 CYExpression *iterable_;
649
650 CYForOfComprehension(CYBinding *binding, CYExpression *iterable, CYComprehension *next = NULL) :
651 CYComprehension(next),
652 binding_(binding),
653 iterable_(iterable)
654 {
655 }
656
657 virtual CYFunctionParameter *Parameter(CYContext &context) const;
658 virtual CYStatement *Replace(CYContext &context, CYStatement *statement) const;
659 virtual void Output(CYOutput &out) const;
660 };
661
662 struct CYIfComprehension :
663 CYComprehension
664 {
665 CYExpression *test_;
666
667 CYIfComprehension(CYExpression *test, CYComprehension *next = NULL) :
668 CYComprehension(next),
669 test_(test)
670 {
671 }
672
673 virtual CYFunctionParameter *Parameter(CYContext &context) const;
674 virtual CYStatement *Replace(CYContext &context, CYStatement *statement) const;
675 virtual void Output(CYOutput &out) const;
676 };
677
678 struct CYArrayComprehension :
679 CYTarget
680 {
681 CYExpression *expression_;
682 CYComprehension *comprehensions_;
683
684 CYArrayComprehension(CYExpression *expression, CYComprehension *comprehensions) :
685 expression_(expression),
686 comprehensions_(comprehensions)
687 {
688 }
689
690 CYPrecedence(0)
691
692 virtual CYTarget *Replace(CYContext &context);
693 virtual void Output(CYOutput &out, CYFlags flags) const;
694 };
695
696 struct CYLiteral :
697 CYTarget
698 {
699 CYLocation location_;
700
701 CYPrecedence(0)
702
703 virtual CYExpression *Primitive(CYContext &context) {
704 return this;
705 }
706 };
707
708 struct CYTrivial :
709 CYLiteral
710 {
711 virtual CYTarget *Replace(CYContext &context);
712 };
713
714 struct CYMagic :
715 CYTarget
716 {
717 CYPrecedence(0)
718 };
719
720 struct CYRange {
721 uint64_t lo_;
722 uint64_t hi_;
723
724 CYRange(uint64_t lo, uint64_t hi) :
725 lo_(lo), hi_(hi)
726 {
727 }
728
729 bool operator [](uint8_t value) const {
730 return !(value >> 7) && (value >> 6 ? hi_ : lo_) >> (value & 0x3f) & 0x1;
731 }
732
733 void operator()(uint8_t value) {
734 if (value >> 7)
735 return;
736 (value >> 6 ? hi_ : lo_) |= uint64_t(0x1) << (value & 0x3f);
737 }
738 };
739
740 extern CYRange DigitRange_;
741 extern CYRange WordStartRange_;
742 extern CYRange WordEndRange_;
743
744 struct CYString :
745 CYTrivial,
746 CYPropertyName
747 {
748 const char *value_;
749 size_t size_;
750
751 CYString() :
752 value_(NULL),
753 size_(0)
754 {
755 }
756
757 CYString(const char *value) :
758 value_(value),
759 size_(strlen(value))
760 {
761 }
762
763 CYString(const char *value, size_t size) :
764 value_(value),
765 size_(size)
766 {
767 }
768
769 CYString(const CYWord *word) :
770 value_(word->Word()),
771 size_(strlen(value_))
772 {
773 }
774
775 const char *Value() const {
776 return value_;
777 }
778
779 virtual const char *Word() const;
780
781 virtual CYNumber *Number(CYContext &context);
782 virtual CYString *String(CYContext &context);
783
784 CYString *Concat(CYContext &out, CYString *rhs) const;
785 virtual void Output(CYOutput &out, CYFlags flags) const;
786
787 virtual CYExpression *PropertyName(CYContext &context);
788 virtual void PropertyName(CYOutput &out) const;
789 };
790
791 struct CYElementValue;
792
793 struct CYSpan :
794 CYNext<CYSpan>
795 {
796 CYExpression *expression_;
797 CYString *string_;
798
799 CYSpan(CYExpression *expression, CYString *string, CYSpan *next) :
800 CYNext<CYSpan>(next),
801 expression_(expression),
802 string_(string)
803 {
804 }
805
806 CYElementValue *Replace(CYContext &context);
807 };
808
809 struct CYTemplate :
810 CYTarget
811 {
812 CYString *string_;
813 CYSpan *spans_;
814
815 CYTemplate(CYString *string, CYSpan *spans) :
816 string_(string),
817 spans_(spans)
818 {
819 }
820
821 CYPrecedence(0)
822
823 virtual CYTarget *Replace(CYContext &context);
824 virtual void Output(CYOutput &out, CYFlags flags) const;
825 };
826
827 struct CYNumber :
828 CYTrivial,
829 CYPropertyName
830 {
831 double value_;
832
833 CYNumber(double value) :
834 value_(value)
835 {
836 }
837
838 double Value() const {
839 return value_;
840 }
841
842 virtual CYNumber *Number(CYContext &context);
843 virtual CYString *String(CYContext &context);
844
845 virtual void Output(CYOutput &out, CYFlags flags) const;
846
847 virtual CYExpression *PropertyName(CYContext &context);
848 virtual void PropertyName(CYOutput &out) const;
849 };
850
851 struct CYComputed :
852 CYPropertyName
853 {
854 CYExpression *expression_;
855
856 CYComputed(CYExpression *expression) :
857 expression_(expression)
858 {
859 }
860
861 virtual bool Computed() const {
862 return true;
863 }
864
865 virtual CYExpression *PropertyName(CYContext &context);
866 virtual void PropertyName(CYOutput &out) const;
867 };
868
869 struct CYRegEx :
870 CYTrivial
871 {
872 const char *value_;
873 size_t size_;
874
875 CYRegEx(const char *value, size_t size) :
876 value_(value),
877 size_(size)
878 {
879 }
880
881 const char *Value() const {
882 return value_;
883 }
884
885 virtual void Output(CYOutput &out, CYFlags flags) const;
886 };
887
888 struct CYNull :
889 CYTrivial
890 {
891 virtual CYNumber *Number(CYContext &context);
892 virtual CYString *String(CYContext &context);
893
894 virtual void Output(CYOutput &out, CYFlags flags) const;
895 };
896
897 struct CYThis :
898 CYMagic
899 {
900 virtual CYTarget *Replace(CYContext &context);
901 virtual void Output(CYOutput &out, CYFlags flags) const;
902 };
903
904 struct CYBoolean :
905 CYTrivial
906 {
907 CYPrecedence(4)
908
909 virtual bool RightHand() const {
910 return true;
911 }
912
913 virtual bool Value() const = 0;
914 virtual void Output(CYOutput &out, CYFlags flags) const;
915 };
916
917 struct CYFalse :
918 CYBoolean
919 {
920 virtual bool Value() const {
921 return false;
922 }
923
924 virtual CYNumber *Number(CYContext &context);
925 virtual CYString *String(CYContext &context);
926 };
927
928 struct CYTrue :
929 CYBoolean
930 {
931 virtual bool Value() const {
932 return true;
933 }
934
935 virtual CYNumber *Number(CYContext &context);
936 virtual CYString *String(CYContext &context);
937 };
938
939 struct CYVariable :
940 CYTarget
941 {
942 CYIdentifier *name_;
943
944 CYVariable(CYIdentifier *name) :
945 name_(name)
946 {
947 }
948
949 CYVariable(const char *name) :
950 name_(new($pool) CYIdentifier(name))
951 {
952 }
953
954 CYPrecedence(0)
955
956 virtual bool Eval() const {
957 return strcmp(name_->Word(), "eval") == 0;
958 }
959
960 virtual CYTarget *Replace(CYContext &context);
961 virtual void Output(CYOutput &out, CYFlags flags) const;
962
963 virtual CYFunctionParameter *Parameter() const;
964 };
965
966 struct CYSymbol :
967 CYTarget
968 {
969 const char *name_;
970
971 CYSymbol(const char *name) :
972 name_(name)
973 {
974 }
975
976 CYPrecedence(0)
977
978 virtual CYTarget *Replace(CYContext &context);
979 virtual void Output(CYOutput &out, CYFlags flags) const;
980 };
981
982 struct CYPrefix :
983 CYExpression
984 {
985 CYExpression *rhs_;
986
987 CYPrefix(CYExpression *rhs) :
988 rhs_(rhs)
989 {
990 }
991
992 virtual bool Alphabetic() const = 0;
993 virtual const char *Operator() const = 0;
994
995 CYPrecedence(4)
996
997 virtual CYExpression *Replace(CYContext &context);
998 virtual void Output(CYOutput &out, CYFlags flags) const;
999 };
1000
1001 struct CYInfix :
1002 CYExpression
1003 {
1004 CYExpression *lhs_;
1005 CYExpression *rhs_;
1006
1007 CYInfix(CYExpression *lhs, CYExpression *rhs) :
1008 lhs_(lhs),
1009 rhs_(rhs)
1010 {
1011 }
1012
1013 void SetLeft(CYExpression *lhs) {
1014 lhs_ = lhs;
1015 }
1016
1017 virtual bool Alphabetic() const = 0;
1018 virtual const char *Operator() const = 0;
1019
1020 virtual CYExpression *Replace(CYContext &context);
1021 virtual void Output(CYOutput &out, CYFlags flags) const;
1022 };
1023
1024 struct CYPostfix :
1025 CYExpression
1026 {
1027 CYExpression *lhs_;
1028
1029 CYPostfix(CYExpression *lhs) :
1030 lhs_(lhs)
1031 {
1032 }
1033
1034 virtual const char *Operator() const = 0;
1035
1036 CYPrecedence(3)
1037
1038 virtual CYExpression *Replace(CYContext &context);
1039 virtual void Output(CYOutput &out, CYFlags flags) const;
1040 };
1041
1042 struct CYAssignment :
1043 CYExpression
1044 {
1045 CYTarget *lhs_;
1046 CYExpression *rhs_;
1047
1048 CYAssignment(CYTarget *lhs, CYExpression *rhs) :
1049 lhs_(lhs),
1050 rhs_(rhs)
1051 {
1052 }
1053
1054 void SetRight(CYExpression *rhs) {
1055 rhs_ = rhs;
1056 }
1057
1058 virtual const char *Operator() const = 0;
1059
1060 CYPrecedence(16)
1061
1062 virtual CYExpression *Replace(CYContext &context);
1063 virtual void Output(CYOutput &out, CYFlags flags) const;
1064 };
1065
1066 struct CYArgument :
1067 CYNext<CYArgument>,
1068 CYThing
1069 {
1070 CYWord *name_;
1071 CYExpression *value_;
1072
1073 CYArgument(CYExpression *value, CYArgument *next = NULL) :
1074 CYNext<CYArgument>(next),
1075 name_(NULL),
1076 value_(value)
1077 {
1078 }
1079
1080 CYArgument(CYWord *name, CYExpression *value, CYArgument *next = NULL) :
1081 CYNext<CYArgument>(next),
1082 name_(name),
1083 value_(value)
1084 {
1085 }
1086
1087 CYArgument *Replace(CYContext &context);
1088 void Output(CYOutput &out) const;
1089 };
1090
1091 struct CYClause :
1092 CYThing,
1093 CYNext<CYClause>
1094 {
1095 CYExpression *value_;
1096 CYStatement *code_;
1097
1098 CYClause(CYExpression *value, CYStatement *code) :
1099 value_(value),
1100 code_(code)
1101 {
1102 }
1103
1104 void Replace(CYContext &context);
1105 virtual void Output(CYOutput &out) const;
1106 };
1107
1108 struct CYElement :
1109 CYNext<CYElement>,
1110 CYThing
1111 {
1112 CYElement(CYElement *next) :
1113 CYNext<CYElement>(next)
1114 {
1115 }
1116
1117 virtual bool Elision() const = 0;
1118
1119 virtual void Replace(CYContext &context) = 0;
1120 };
1121
1122 struct CYElementValue :
1123 CYElement
1124 {
1125 CYExpression *value_;
1126
1127 CYElementValue(CYExpression *value, CYElement *next = NULL) :
1128 CYElement(next),
1129 value_(value)
1130 {
1131 }
1132
1133 virtual bool Elision() const {
1134 return value_ == NULL;
1135 }
1136
1137 virtual void Replace(CYContext &context);
1138 virtual void Output(CYOutput &out) const;
1139 };
1140
1141 struct CYElementSpread :
1142 CYElement
1143 {
1144 CYExpression *value_;
1145
1146 CYElementSpread(CYExpression *value, CYElement *next = NULL) :
1147 CYElement(next),
1148 value_(value)
1149 {
1150 }
1151
1152 virtual bool Elision() const {
1153 return false;
1154 }
1155
1156 virtual void Replace(CYContext &context);
1157 virtual void Output(CYOutput &out) const;
1158 };
1159
1160 struct CYArray :
1161 CYLiteral
1162 {
1163 CYElement *elements_;
1164
1165 CYArray(CYElement *elements = NULL) :
1166 elements_(elements)
1167 {
1168 }
1169
1170 virtual CYTarget *Replace(CYContext &context);
1171 virtual void Output(CYOutput &out, CYFlags flags) const;
1172 };
1173
1174 struct CYBinding {
1175 CYIdentifier *identifier_;
1176 CYExpression *initializer_;
1177
1178 CYBinding(CYIdentifier *identifier, CYExpression *initializer = NULL) :
1179 identifier_(identifier),
1180 initializer_(initializer)
1181 {
1182 }
1183
1184 CYTarget *Target(CYContext &context);
1185
1186 virtual CYAssignment *Replace(CYContext &context, CYIdentifierKind kind);
1187 virtual void Output(CYOutput &out, CYFlags flags) const;
1188 };
1189
1190 struct CYForLexical :
1191 CYForInInitializer
1192 {
1193 bool constant_;
1194 CYBinding *binding_;
1195
1196 CYForLexical(bool constant, CYBinding *binding) :
1197 constant_(constant),
1198 binding_(binding)
1199 {
1200 }
1201
1202 virtual CYStatement *Initialize(CYContext &context, CYExpression *value);
1203
1204 virtual CYTarget *Replace(CYContext &context);
1205 virtual void Output(CYOutput &out, CYFlags flags) const;
1206 };
1207
1208 struct CYForVariable :
1209 CYForInInitializer
1210 {
1211 CYBinding *binding_;
1212
1213 CYForVariable(CYBinding *binding) :
1214 binding_(binding)
1215 {
1216 }
1217
1218 virtual CYStatement *Initialize(CYContext &context, CYExpression *value);
1219
1220 virtual CYTarget *Replace(CYContext &context);
1221 virtual void Output(CYOutput &out, CYFlags flags) const;
1222 };
1223
1224 struct CYBindings :
1225 CYNext<CYBindings>,
1226 CYThing
1227 {
1228 CYBinding *binding_;
1229
1230 CYBindings(CYBinding *binding, CYBindings *next = NULL) :
1231 CYNext<CYBindings>(next),
1232 binding_(binding)
1233 {
1234 }
1235
1236 CYExpression *Replace(CYContext &context, CYIdentifierKind kind);
1237
1238 CYArgument *Argument(CYContext &context);
1239 CYFunctionParameter *Parameter(CYContext &context);
1240
1241 virtual void Output(CYOutput &out) const;
1242 virtual void Output(CYOutput &out, CYFlags flags) const;
1243 };
1244
1245 struct CYVar :
1246 CYForInitializer
1247 {
1248 CYBindings *bindings_;
1249
1250 CYVar(CYBindings *bindings) :
1251 bindings_(bindings)
1252 {
1253 }
1254
1255 CYCompact(None)
1256
1257 virtual CYForInitializer *Replace(CYContext &context);
1258 virtual void Output(CYOutput &out, CYFlags flags) const;
1259 };
1260
1261 struct CYLexical :
1262 CYForInitializer
1263 {
1264 bool constant_;
1265 CYBindings *bindings_;
1266
1267 CYLexical(bool constant, CYBindings *bindings) :
1268 constant_(constant),
1269 bindings_(bindings)
1270 {
1271 }
1272
1273 CYCompact(None)
1274
1275 virtual CYForInitializer *Replace(CYContext &context);
1276 virtual void Output(CYOutput &out, CYFlags flags) const;
1277 };
1278
1279 struct CYBuilder {
1280 CYList<CYBindings> bindings_;
1281 CYList<CYStatement> statements_;
1282
1283 operator bool() const {
1284 return statements_ != NULL;
1285 }
1286 };
1287
1288 struct CYProperty :
1289 CYNext<CYProperty>,
1290 CYThing
1291 {
1292 CYPropertyName *name_;
1293
1294 CYProperty(CYPropertyName *name, CYProperty *next = NULL) :
1295 CYNext<CYProperty>(next),
1296 name_(name)
1297 {
1298 }
1299
1300 virtual bool Update() const;
1301
1302 CYProperty *ReplaceAll(CYContext &context, CYBuilder &builder, CYExpression *self, bool update);
1303 void Replace(CYContext &context, CYBuilder &builder, CYExpression *self, bool protect);
1304
1305 virtual void Replace(CYContext &context, CYBuilder &builder, CYExpression *self, CYExpression *name, bool protect) = 0;
1306
1307 virtual void Replace(CYContext &context) = 0;
1308 virtual void Output(CYOutput &out) const;
1309 };
1310
1311 struct CYPropertyValue :
1312 CYProperty
1313 {
1314 CYExpression *value_;
1315
1316 CYPropertyValue(CYPropertyName *name, CYExpression *value, CYProperty *next = NULL) :
1317 CYProperty(name, next),
1318 value_(value)
1319 {
1320 }
1321
1322 virtual void Replace(CYContext &context, CYBuilder &builder, CYExpression *self, CYExpression *name, bool protect);
1323 virtual void Replace(CYContext &context);
1324 virtual void Output(CYOutput &out) const;
1325 };
1326
1327 struct CYFor :
1328 CYStatement
1329 {
1330 CYForInitializer *initializer_;
1331 CYExpression *test_;
1332 CYExpression *increment_;
1333 CYStatement *code_;
1334
1335 CYFor(CYForInitializer *initializer, CYExpression *test, CYExpression *increment, CYStatement *code) :
1336 initializer_(initializer),
1337 test_(test),
1338 increment_(increment),
1339 code_(code)
1340 {
1341 }
1342
1343 CYCompact(Long)
1344
1345 virtual CYStatement *Replace(CYContext &context);
1346 virtual void Output(CYOutput &out, CYFlags flags) const;
1347 };
1348
1349 struct CYForIn :
1350 CYStatement
1351 {
1352 CYForInInitializer *initializer_;
1353 CYExpression *iterable_;
1354 CYStatement *code_;
1355
1356 CYForIn(CYForInInitializer *initializer, CYExpression *iterable, CYStatement *code) :
1357 initializer_(initializer),
1358 iterable_(iterable),
1359 code_(code)
1360 {
1361 }
1362
1363 CYCompact(Long)
1364
1365 virtual CYStatement *Replace(CYContext &context);
1366 virtual void Output(CYOutput &out, CYFlags flags) const;
1367 };
1368
1369 struct CYForInitialized :
1370 CYStatement
1371 {
1372 CYBinding *binding_;
1373 CYExpression *iterable_;
1374 CYStatement *code_;
1375
1376 CYForInitialized(CYBinding *binding, CYExpression *iterable, CYStatement *code) :
1377 binding_(binding),
1378 iterable_(iterable),
1379 code_(code)
1380 {
1381 }
1382
1383 CYCompact(Long)
1384
1385 virtual CYStatement *Replace(CYContext &context);
1386 virtual void Output(CYOutput &out, CYFlags flags) const;
1387 };
1388
1389 struct CYForOf :
1390 CYStatement
1391 {
1392 CYForInInitializer *initializer_;
1393 CYExpression *iterable_;
1394 CYStatement *code_;
1395
1396 CYForOf(CYForInInitializer *initializer, CYExpression *iterable, CYStatement *code) :
1397 initializer_(initializer),
1398 iterable_(iterable),
1399 code_(code)
1400 {
1401 }
1402
1403 CYCompact(Long)
1404
1405 virtual CYStatement *Replace(CYContext &context);
1406 virtual void Output(CYOutput &out, CYFlags flags) const;
1407 };
1408
1409 struct CYObject :
1410 CYLiteral
1411 {
1412 CYProperty *properties_;
1413
1414 CYObject(CYProperty *properties = NULL) :
1415 properties_(properties)
1416 {
1417 }
1418
1419 virtual CYTarget *Replace(CYContext &context);
1420 void Output(CYOutput &out, CYFlags flags) const;
1421 };
1422
1423 struct CYMember :
1424 CYTarget
1425 {
1426 CYExpression *object_;
1427 CYExpression *property_;
1428
1429 CYMember(CYExpression *object, CYExpression *property) :
1430 object_(object),
1431 property_(property)
1432 {
1433 }
1434
1435 void SetLeft(CYExpression *object) {
1436 object_ = object;
1437 }
1438 };
1439
1440 struct CYDirectMember :
1441 CYMember
1442 {
1443 CYDirectMember(CYExpression *object, CYExpression *property) :
1444 CYMember(object, property)
1445 {
1446 }
1447
1448 CYPrecedence(1)
1449
1450 virtual CYTarget *Replace(CYContext &context);
1451 virtual void Output(CYOutput &out, CYFlags flags) const;
1452 };
1453
1454 struct CYIndirectMember :
1455 CYMember
1456 {
1457 CYIndirectMember(CYExpression *object, CYExpression *property) :
1458 CYMember(object, property)
1459 {
1460 }
1461
1462 CYPrecedence(1)
1463
1464 virtual CYTarget *Replace(CYContext &context);
1465 virtual void Output(CYOutput &out, CYFlags flags) const;
1466 };
1467
1468 struct CYResolveMember :
1469 CYMember
1470 {
1471 CYResolveMember(CYExpression *object, CYExpression *property) :
1472 CYMember(object, property)
1473 {
1474 }
1475
1476 CYPrecedence(1)
1477
1478 virtual CYTarget *Replace(CYContext &context);
1479 virtual void Output(CYOutput &out, CYFlags flags) const;
1480 };
1481
1482 namespace cy {
1483 namespace Syntax {
1484
1485 struct New :
1486 CYTarget
1487 {
1488 CYExpression *constructor_;
1489 CYArgument *arguments_;
1490
1491 New(CYExpression *constructor, CYArgument *arguments = NULL) :
1492 constructor_(constructor),
1493 arguments_(arguments)
1494 {
1495 }
1496
1497 virtual int Precedence() const {
1498 return arguments_ == NULL ? 2 : 1;
1499 }
1500
1501
1502 virtual CYTarget *Replace(CYContext &context);
1503 virtual void Output(CYOutput &out, CYFlags flags) const;
1504
1505 virtual CYTarget *AddArgument(CYContext &context, CYExpression *value);
1506 };
1507
1508 } }
1509
1510 struct CYApply :
1511 CYTarget
1512 {
1513 CYArgument *arguments_;
1514
1515 CYApply(CYArgument *arguments = NULL) :
1516 arguments_(arguments)
1517 {
1518 }
1519
1520 CYPrecedence(1)
1521
1522 virtual CYTarget *AddArgument(CYContext &context, CYExpression *value);
1523 };
1524
1525 struct CYCall :
1526 CYApply
1527 {
1528 CYExpression *function_;
1529
1530 CYCall(CYExpression *function, CYArgument *arguments = NULL) :
1531 CYApply(arguments),
1532 function_(function)
1533 {
1534 }
1535
1536 virtual void Output(CYOutput &out, CYFlags flags) const;
1537 virtual CYTarget *Replace(CYContext &context);
1538 };
1539
1540 struct CYEval :
1541 CYApply
1542 {
1543 CYEval(CYArgument *arguments) :
1544 CYApply(arguments)
1545 {
1546 }
1547
1548 virtual void Output(CYOutput &out, CYFlags flags) const;
1549 virtual CYTarget *Replace(CYContext &context);
1550 };
1551
1552 struct CYRubyProc;
1553
1554 struct CYRubyBlock :
1555 CYTarget
1556 {
1557 CYExpression *call_;
1558 CYRubyProc *proc_;
1559
1560 CYRubyBlock(CYExpression *call, CYRubyProc *proc) :
1561 call_(call),
1562 proc_(proc)
1563 {
1564 }
1565
1566 CYPrecedence(1)
1567
1568 virtual CYTarget *Replace(CYContext &context);
1569 virtual void Output(CYOutput &out, CYFlags flags) const;
1570
1571 virtual CYTarget *AddArgument(CYContext &context, CYExpression *value);
1572 };
1573
1574 struct CYIf :
1575 CYStatement
1576 {
1577 CYExpression *test_;
1578 CYStatement *true_;
1579 CYStatement *false_;
1580
1581 CYIf(CYExpression *test, CYStatement *_true, CYStatement *_false = NULL) :
1582 test_(test),
1583 true_(_true),
1584 false_(_false)
1585 {
1586 }
1587
1588 CYCompact(Long)
1589
1590 virtual CYStatement *Replace(CYContext &context);
1591 virtual void Output(CYOutput &out, CYFlags flags) const;
1592
1593 virtual CYStatement *Return();
1594 };
1595
1596 struct CYDoWhile :
1597 CYStatement
1598 {
1599 CYExpression *test_;
1600 CYStatement *code_;
1601
1602 CYDoWhile(CYExpression *test, CYStatement *code) :
1603 test_(test),
1604 code_(code)
1605 {
1606 }
1607
1608 CYCompact(None)
1609
1610 virtual CYStatement *Replace(CYContext &context);
1611 virtual void Output(CYOutput &out, CYFlags flags) const;
1612 };
1613
1614 struct CYWhile :
1615 CYStatement
1616 {
1617 CYExpression *test_;
1618 CYStatement *code_;
1619
1620 CYWhile(CYExpression *test, CYStatement *code) :
1621 test_(test),
1622 code_(code)
1623 {
1624 }
1625
1626 CYCompact(Long)
1627
1628 virtual CYStatement *Replace(CYContext &context);
1629 virtual void Output(CYOutput &out, CYFlags flags) const;
1630 };
1631
1632 struct CYFunction {
1633 CYFunctionParameter *parameters_;
1634 CYStatement *code_;
1635
1636 CYNonLocal *nonlocal_;
1637 bool implicit_;
1638 CYThisScope this_;
1639 CYIdentifier *super_;
1640
1641 CYFunction(CYFunctionParameter *parameters, CYStatement *code) :
1642 parameters_(parameters),
1643 code_(code),
1644 nonlocal_(NULL),
1645 implicit_(false),
1646 super_(NULL)
1647 {
1648 }
1649
1650 void Replace(CYContext &context);
1651 void Output(CYOutput &out) const;
1652 };
1653
1654 struct CYFunctionExpression :
1655 CYFunction,
1656 CYTarget
1657 {
1658 CYIdentifier *name_;
1659
1660 CYFunctionExpression(CYIdentifier *name, CYFunctionParameter *parameters, CYStatement *code) :
1661 CYFunction(parameters, code),
1662 name_(name)
1663 {
1664 }
1665
1666 CYPrecedence(0)
1667
1668 CYTarget *Replace(CYContext &context) override;
1669 virtual void Output(CYOutput &out, CYFlags flags) const;
1670 };
1671
1672 struct CYFatArrow :
1673 CYFunction,
1674 CYExpression
1675 {
1676 CYFatArrow(CYFunctionParameter *parameters, CYStatement *code) :
1677 CYFunction(parameters, code)
1678 {
1679 }
1680
1681 CYPrecedence(0)
1682
1683 CYExpression *Replace(CYContext &context) override;
1684 virtual void Output(CYOutput &out, CYFlags flags) const;
1685 };
1686
1687 struct CYRubyProc :
1688 CYFunction,
1689 CYTarget
1690 {
1691 CYRubyProc(CYFunctionParameter *parameters, CYStatement *code) :
1692 CYFunction(parameters, code)
1693 {
1694 }
1695
1696 CYPrecedence(0)
1697
1698 CYTarget *Replace(CYContext &context) override;
1699 virtual void Output(CYOutput &out, CYFlags flags) const;
1700 };
1701
1702 struct CYFunctionStatement :
1703 CYFunction,
1704 CYStatement
1705 {
1706 CYIdentifier *name_;
1707
1708 CYFunctionStatement(CYIdentifier *name, CYFunctionParameter *parameters, CYStatement *code) :
1709 CYFunction(parameters, code),
1710 name_(name)
1711 {
1712 }
1713
1714 CYCompact(None)
1715
1716 CYStatement *Replace(CYContext &context) override;
1717 virtual void Output(CYOutput &out, CYFlags flags) const;
1718 };
1719
1720 struct CYPropertyMethod;
1721
1722 struct CYMethod :
1723 CYFunction,
1724 CYProperty
1725 {
1726 CYMethod(CYPropertyName *name, CYFunctionParameter *parameters, CYStatement *code, CYProperty *next = NULL) :
1727 CYFunction(parameters, code),
1728 CYProperty(name, next)
1729 {
1730 }
1731
1732 virtual CYFunctionExpression *Constructor();
1733
1734 using CYProperty::Replace;
1735 virtual void Replace(CYContext &context);
1736 };
1737
1738 struct CYPropertyGetter :
1739 CYMethod
1740 {
1741 CYPropertyGetter(CYPropertyName *name, CYStatement *code, CYProperty *next = NULL) :
1742 CYMethod(name, NULL, code, next)
1743 {
1744 }
1745
1746 virtual void Replace(CYContext &context, CYBuilder &builder, CYExpression *self, CYExpression *name, bool protect);
1747 virtual void Output(CYOutput &out) const;
1748 };
1749
1750 struct CYPropertySetter :
1751 CYMethod
1752 {
1753 CYPropertySetter(CYPropertyName *name, CYFunctionParameter *parameters, CYStatement *code, CYProperty *next = NULL) :
1754 CYMethod(name, parameters, code, next)
1755 {
1756 }
1757
1758 virtual void Replace(CYContext &context, CYBuilder &builder, CYExpression *self, CYExpression *name, bool protect);
1759 virtual void Output(CYOutput &out) const;
1760 };
1761
1762 struct CYPropertyMethod :
1763 CYMethod
1764 {
1765 CYPropertyMethod(CYPropertyName *name, CYFunctionParameter *parameters, CYStatement *code, CYProperty *next = NULL) :
1766 CYMethod(name, parameters, code, next)
1767 {
1768 }
1769
1770 bool Update() const override;
1771
1772 virtual CYFunctionExpression *Constructor();
1773
1774 virtual void Replace(CYContext &context, CYBuilder &builder, CYExpression *self, CYExpression *name, bool protect);
1775 virtual void Output(CYOutput &out) const;
1776 };
1777
1778 struct CYClassTail :
1779 CYThing
1780 {
1781 CYExpression *extends_;
1782
1783 CYFunctionExpression *constructor_;
1784 CYList<CYProperty> instance_;
1785 CYList<CYProperty> static_;
1786
1787 CYClassTail(CYExpression *extends) :
1788 extends_(extends),
1789 constructor_(NULL)
1790 {
1791 }
1792
1793 void Output(CYOutput &out) const;
1794 };
1795
1796 struct CYClassExpression :
1797 CYTarget
1798 {
1799 CYIdentifier *name_;
1800 CYClassTail *tail_;
1801
1802 CYClassExpression(CYIdentifier *name, CYClassTail *tail) :
1803 name_(name),
1804 tail_(tail)
1805 {
1806 }
1807
1808 CYPrecedence(0)
1809
1810 CYTarget *Replace(CYContext &context) override;
1811 virtual void Output(CYOutput &out, CYFlags flags) const;
1812 };
1813
1814 struct CYClassStatement :
1815 CYStatement
1816 {
1817 CYIdentifier *name_;
1818 CYClassTail *tail_;
1819
1820 CYClassStatement(CYIdentifier *name, CYClassTail *tail) :
1821 name_(name),
1822 tail_(tail)
1823 {
1824 }
1825
1826 CYCompact(Long)
1827
1828 CYStatement *Replace(CYContext &context) override;
1829 virtual void Output(CYOutput &out, CYFlags flags) const;
1830 };
1831
1832 struct CYSuperCall :
1833 CYTarget
1834 {
1835 CYArgument *arguments_;
1836
1837 CYSuperCall(CYArgument *arguments) :
1838 arguments_(arguments)
1839 {
1840 }
1841
1842 CYPrecedence(2)
1843
1844 CYTarget *Replace(CYContext &context) override;
1845 virtual void Output(CYOutput &out, CYFlags flags) const;
1846 };
1847
1848 struct CYSuperAccess :
1849 CYTarget
1850 {
1851 CYExpression *property_;
1852
1853 CYSuperAccess(CYExpression *property) :
1854 property_(property)
1855 {
1856 }
1857
1858 CYPrecedence(1)
1859
1860 CYTarget *Replace(CYContext &context) override;
1861 virtual void Output(CYOutput &out, CYFlags flags) const;
1862 };
1863
1864 struct CYExpress :
1865 CYForInitializer
1866 {
1867 CYExpression *expression_;
1868
1869 CYExpress(CYExpression *expression) :
1870 expression_(expression)
1871 {
1872 if (expression_ == NULL)
1873 throw;
1874 }
1875
1876 CYCompact(None)
1877
1878 CYForInitializer *Replace(CYContext &context) override;
1879 virtual void Output(CYOutput &out, CYFlags flags) const;
1880
1881 virtual CYStatement *Return();
1882 };
1883
1884 struct CYContinue :
1885 CYStatement
1886 {
1887 CYIdentifier *label_;
1888
1889 CYContinue(CYIdentifier *label) :
1890 label_(label)
1891 {
1892 }
1893
1894 CYCompact(Short)
1895
1896 CYStatement *Replace(CYContext &context) override;
1897 virtual void Output(CYOutput &out, CYFlags flags) const;
1898 };
1899
1900 struct CYBreak :
1901 CYStatement
1902 {
1903 CYIdentifier *label_;
1904
1905 CYBreak(CYIdentifier *label) :
1906 label_(label)
1907 {
1908 }
1909
1910 CYCompact(Short)
1911
1912 CYStatement *Replace(CYContext &context) override;
1913 virtual void Output(CYOutput &out, CYFlags flags) const;
1914 };
1915
1916 struct CYReturn :
1917 CYStatement
1918 {
1919 CYExpression *value_;
1920
1921 CYReturn(CYExpression *value) :
1922 value_(value)
1923 {
1924 }
1925
1926 CYCompact(None)
1927
1928 CYStatement *Replace(CYContext &context) override;
1929 virtual void Output(CYOutput &out, CYFlags flags) const;
1930 };
1931
1932 struct CYYieldGenerator :
1933 CYExpression
1934 {
1935 CYExpression *value_;
1936
1937 CYYieldGenerator(CYExpression *value) :
1938 value_(value)
1939 {
1940 }
1941
1942 CYPrecedence(0)
1943
1944 CYExpression *Replace(CYContext &context) override;
1945 virtual void Output(CYOutput &out, CYFlags flags) const;
1946 };
1947
1948 struct CYYieldValue :
1949 CYExpression
1950 {
1951 CYExpression *value_;
1952
1953 CYYieldValue(CYExpression *value) :
1954 value_(value)
1955 {
1956 }
1957
1958 CYPrecedence(0)
1959
1960 virtual CYExpression *Replace(CYContext &context);
1961 virtual void Output(CYOutput &out, CYFlags flags) const;
1962 };
1963
1964 struct CYEmpty :
1965 CYForInitializer
1966 {
1967 CYCompact(Short)
1968
1969 virtual CYForInitializer *Replace(CYContext &context);
1970 virtual void Output(CYOutput &out, CYFlags flags) const;
1971 };
1972
1973 struct CYFinally :
1974 CYThing
1975 {
1976 CYStatement *code_;
1977
1978 CYFinally(CYStatement *code) :
1979 code_(code)
1980 {
1981 }
1982
1983 void Replace(CYContext &context);
1984 virtual void Output(CYOutput &out) const;
1985 };
1986
1987 struct CYTypeSpecifier :
1988 CYThing
1989 {
1990 virtual CYTarget *Replace(CYContext &context) = 0;
1991 };
1992
1993 struct CYTypeError :
1994 CYTypeSpecifier
1995 {
1996 CYTypeError() {
1997 }
1998
1999 virtual CYTarget *Replace(CYContext &context);
2000 virtual void Output(CYOutput &out) const;
2001 };
2002
2003 enum CYTypeSigning {
2004 CYTypeNeutral,
2005 CYTypeSigned,
2006 CYTypeUnsigned,
2007 };
2008
2009 struct CYTypeCharacter :
2010 CYTypeSpecifier
2011 {
2012 CYTypeSigning signing_;
2013
2014 CYTypeCharacter(CYTypeSigning signing) :
2015 signing_(signing)
2016 {
2017 }
2018
2019 virtual CYTarget *Replace(CYContext &context);
2020 virtual void Output(CYOutput &out) const;
2021 };
2022
2023 struct CYTypeIntegral :
2024 CYTypeSpecifier
2025 {
2026 CYTypeSigning signing_;
2027 int length_;
2028
2029 CYTypeIntegral(CYTypeSigning signing, int length = 1) :
2030 signing_(signing),
2031 length_(length)
2032 {
2033 }
2034
2035 CYTypeIntegral *Long() {
2036 if (length_ != 1 && length_ != 2)
2037 return NULL;
2038 ++length_;
2039 return this;
2040 }
2041
2042 CYTypeIntegral *Short() {
2043 if (length_ != 1)
2044 return NULL;
2045 --length_;
2046 return this;
2047 }
2048
2049 CYTypeIntegral *Signed() {
2050 if (signing_ != CYTypeNeutral)
2051 return NULL;
2052 signing_ = CYTypeSigned;
2053 return this;
2054 }
2055
2056 CYTypeIntegral *Unsigned() {
2057 if (signing_ != CYTypeNeutral)
2058 return NULL;
2059 signing_ = CYTypeUnsigned;
2060 return this;
2061 }
2062
2063 virtual CYTarget *Replace(CYContext &context);
2064 virtual void Output(CYOutput &out) const;
2065 };
2066
2067 struct CYTypeVoid :
2068 CYTypeSpecifier
2069 {
2070 CYTypeVoid() {
2071 }
2072
2073 virtual CYTarget *Replace(CYContext &context);
2074 virtual void Output(CYOutput &out) const;
2075 };
2076
2077 struct CYTypeReference :
2078 CYTypeSpecifier
2079 {
2080 CYIdentifier *name_;
2081
2082 CYTypeReference(CYIdentifier *name) :
2083 name_(name)
2084 {
2085 }
2086
2087 virtual CYTarget *Replace(CYContext &context);
2088 virtual void Output(CYOutput &out) const;
2089 };
2090
2091 struct CYTypeVariable :
2092 CYTypeSpecifier
2093 {
2094 CYIdentifier *name_;
2095
2096 CYTypeVariable(CYIdentifier *name) :
2097 name_(name)
2098 {
2099 }
2100
2101 CYTypeVariable(const char *name) :
2102 name_(new($pool) CYIdentifier(name))
2103 {
2104 }
2105
2106 virtual CYTarget *Replace(CYContext &context);
2107 virtual void Output(CYOutput &out) const;
2108 };
2109
2110 struct CYTypeFunctionWith;
2111
2112 struct CYTypeModifier :
2113 CYNext<CYTypeModifier>
2114 {
2115 CYTypeModifier(CYTypeModifier *next) :
2116 CYNext<CYTypeModifier>(next)
2117 {
2118 }
2119
2120 virtual int Precedence() const = 0;
2121
2122 virtual CYTarget *Replace_(CYContext &context, CYTarget *type) = 0;
2123 CYTarget *Replace(CYContext &context, CYTarget *type);
2124
2125 virtual void Output(CYOutput &out, CYIdentifier *identifier) const = 0;
2126 void Output(CYOutput &out, int precedence, CYIdentifier *identifier) const;
2127
2128 virtual CYTypeFunctionWith *Function() { return NULL; }
2129 };
2130
2131 struct CYTypeArrayOf :
2132 CYTypeModifier
2133 {
2134 CYExpression *size_;
2135
2136 CYTypeArrayOf(CYExpression *size, CYTypeModifier *next = NULL) :
2137 CYTypeModifier(next),
2138 size_(size)
2139 {
2140 }
2141
2142 CYPrecedence(1)
2143
2144 virtual CYTarget *Replace_(CYContext &context, CYTarget *type);
2145 virtual void Output(CYOutput &out, CYIdentifier *identifier) const;
2146 };
2147
2148 struct CYTypeConstant :
2149 CYTypeModifier
2150 {
2151 CYTypeConstant(CYTypeModifier *next = NULL) :
2152 CYTypeModifier(next)
2153 {
2154 }
2155
2156 CYPrecedence(0)
2157
2158 virtual CYTarget *Replace_(CYContext &context, CYTarget *type);
2159 virtual void Output(CYOutput &out, CYIdentifier *identifier) const;
2160 };
2161
2162 struct CYTypePointerTo :
2163 CYTypeModifier
2164 {
2165 CYTypePointerTo(CYTypeModifier *next = NULL) :
2166 CYTypeModifier(next)
2167 {
2168 }
2169
2170 CYPrecedence(0)
2171
2172 virtual CYTarget *Replace_(CYContext &context, CYTarget *type);
2173 virtual void Output(CYOutput &out, CYIdentifier *identifier) const;
2174 };
2175
2176 struct CYTypeVolatile :
2177 CYTypeModifier
2178 {
2179 CYTypeVolatile(CYTypeModifier *next = NULL) :
2180 CYTypeModifier(next)
2181 {
2182 }
2183
2184 CYPrecedence(0)
2185
2186 virtual CYTarget *Replace_(CYContext &context, CYTarget *type);
2187 virtual void Output(CYOutput &out, CYIdentifier *identifier) const;
2188 };
2189
2190 struct CYTypedIdentifier :
2191 CYNext<CYTypedIdentifier>,
2192 CYThing
2193 {
2194 CYLocation location_;
2195 CYIdentifier *identifier_;
2196 CYTypeSpecifier *specifier_;
2197 CYTypeModifier *modifier_;
2198
2199 CYTypedIdentifier(const CYLocation &location, CYIdentifier *identifier = NULL) :
2200 location_(location),
2201 identifier_(identifier),
2202 specifier_(NULL),
2203 modifier_(NULL)
2204 {
2205 }
2206
2207 CYTypedIdentifier(CYTypeSpecifier *specifier, CYTypeModifier *modifier = NULL) :
2208 identifier_(NULL),
2209 specifier_(specifier),
2210 modifier_(modifier)
2211 {
2212 }
2213
2214 inline CYTypedIdentifier *Modify(CYTypeModifier *modifier) {
2215 CYSetLast(modifier_) = modifier;
2216 return this;
2217 }
2218
2219 virtual CYTarget *Replace(CYContext &context);
2220 virtual void Output(CYOutput &out) const;
2221
2222 CYTypeFunctionWith *Function();
2223 };
2224
2225 struct CYEncodedType :
2226 CYTarget
2227 {
2228 CYTypedIdentifier *typed_;
2229
2230 CYEncodedType(CYTypedIdentifier *typed) :
2231 typed_(typed)
2232 {
2233 }
2234
2235 CYPrecedence(1)
2236
2237 virtual CYTarget *Replace(CYContext &context);
2238 virtual void Output(CYOutput &out, CYFlags flags) const;
2239 };
2240
2241 struct CYTypedParameter :
2242 CYNext<CYTypedParameter>,
2243 CYThing
2244 {
2245 CYTypedIdentifier *typed_;
2246
2247 CYTypedParameter(CYTypedIdentifier *typed, CYTypedParameter *next) :
2248 CYNext<CYTypedParameter>(next),
2249 typed_(typed)
2250 {
2251 }
2252
2253 CYArgument *Argument(CYContext &context);
2254 CYFunctionParameter *Parameters(CYContext &context);
2255 CYExpression *TypeSignature(CYContext &context, CYExpression *prefix);
2256
2257 virtual void Output(CYOutput &out) const;
2258 };
2259
2260 struct CYTypedFormal {
2261 bool variadic_;
2262 CYTypedParameter *parameters_;
2263
2264 CYTypedFormal(bool variadic) :
2265 variadic_(variadic),
2266 parameters_(NULL)
2267 {
2268 }
2269 };
2270
2271 struct CYLambda :
2272 CYTarget
2273 {
2274 CYTypedIdentifier *typed_;
2275 CYTypedParameter *parameters_;
2276 CYStatement *code_;
2277
2278 CYLambda(CYTypedIdentifier *typed, CYTypedParameter *parameters, CYStatement *code) :
2279 typed_(typed),
2280 parameters_(parameters),
2281 code_(code)
2282 {
2283 }
2284
2285 CYPrecedence(1)
2286
2287 virtual CYTarget *Replace(CYContext &context);
2288 virtual void Output(CYOutput &out, CYFlags flags) const;
2289 };
2290
2291 struct CYModule :
2292 CYNext<CYModule>,
2293 CYThing
2294 {
2295 CYWord *part_;
2296
2297 CYModule(CYWord *part, CYModule *next = NULL) :
2298 CYNext<CYModule>(next),
2299 part_(part)
2300 {
2301 }
2302
2303 CYString *Replace(CYContext &context, const char *separator) const;
2304 void Output(CYOutput &out) const;
2305 };
2306
2307 struct CYImport :
2308 CYStatement
2309 {
2310 CYModule *module_;
2311
2312 CYImport(CYModule *module) :
2313 module_(module)
2314 {
2315 }
2316
2317 CYCompact(None)
2318
2319 virtual CYStatement *Replace(CYContext &context);
2320 virtual void Output(CYOutput &out, CYFlags flags) const;
2321 };
2322
2323 struct CYImportSpecifier :
2324 CYNext<CYImportSpecifier>
2325 {
2326 CYWord *name_;
2327 CYIdentifier *binding_;
2328
2329 CYImportSpecifier(CYWord *name, CYIdentifier *binding) :
2330 name_(name),
2331 binding_(binding)
2332 {
2333 }
2334
2335 CYStatement *Replace(CYContext &context, CYIdentifier *module);
2336 };
2337
2338 struct CYImportDeclaration :
2339 CYStatement
2340 {
2341 CYImportSpecifier *specifiers_;
2342 CYString *module_;
2343
2344 CYImportDeclaration(CYImportSpecifier *specifiers, CYString *module) :
2345 specifiers_(specifiers),
2346 module_(module)
2347 {
2348 }
2349
2350 CYCompact(None)
2351
2352 virtual CYStatement *Replace(CYContext &context);
2353 virtual void Output(CYOutput &out, CYFlags flags) const;
2354 };
2355
2356 struct CYExternal :
2357 CYStatement
2358 {
2359 CYString *abi_;
2360 CYTypedIdentifier *typed_;
2361
2362 CYExternal(CYString *abi, CYTypedIdentifier *typed) :
2363 abi_(abi),
2364 typed_(typed)
2365 {
2366 }
2367
2368 CYCompact(None)
2369
2370 virtual CYStatement *Replace(CYContext &context);
2371 virtual void Output(CYOutput &out, CYFlags flags) const;
2372 };
2373
2374 struct CYTypeExpression :
2375 CYTarget
2376 {
2377 CYTypedIdentifier *typed_;
2378
2379 CYTypeExpression(CYTypedIdentifier *typed) :
2380 typed_(typed)
2381 {
2382 }
2383
2384 CYPrecedence(0)
2385
2386 virtual CYTarget *Replace(CYContext &context);
2387 virtual void Output(CYOutput &out, CYFlags flags) const;
2388 };
2389
2390 struct CYTypeDefinition :
2391 CYStatement
2392 {
2393 CYTypedIdentifier *typed_;
2394
2395 CYTypeDefinition(CYTypedIdentifier *typed) :
2396 typed_(typed)
2397 {
2398 }
2399
2400 CYCompact(None)
2401
2402 virtual CYStatement *Replace(CYContext &context);
2403 virtual void Output(CYOutput &out, CYFlags flags) const;
2404 };
2405
2406 struct CYTypeBlockWith :
2407 CYTypeModifier
2408 {
2409 CYTypedParameter *parameters_;
2410
2411 CYTypeBlockWith(CYTypedParameter *parameters, CYTypeModifier *next = NULL) :
2412 CYTypeModifier(next),
2413 parameters_(parameters)
2414 {
2415 }
2416
2417 CYPrecedence(0)
2418
2419 virtual CYTarget *Replace_(CYContext &context, CYTarget *type);
2420 virtual void Output(CYOutput &out, CYIdentifier *identifier) const;
2421 };
2422
2423 struct CYTypeFunctionWith :
2424 CYTypeModifier
2425 {
2426 bool variadic_;
2427 CYTypedParameter *parameters_;
2428
2429 CYTypeFunctionWith(bool variadic, CYTypedParameter *parameters, CYTypeModifier *next = NULL) :
2430 CYTypeModifier(next),
2431 variadic_(variadic),
2432 parameters_(parameters)
2433 {
2434 }
2435
2436 CYPrecedence(1)
2437
2438 virtual CYTarget *Replace_(CYContext &context, CYTarget *type);
2439 virtual void Output(CYOutput &out, CYIdentifier *identifier) const;
2440
2441 virtual CYTypeFunctionWith *Function() { return this; }
2442 };
2443
2444 struct CYTypeStructField :
2445 CYNext<CYTypeStructField>
2446 {
2447 CYTypedIdentifier *typed_;
2448
2449 CYTypeStructField(CYTypedIdentifier *typed, CYTypeStructField *next = NULL) :
2450 CYNext<CYTypeStructField>(next),
2451 typed_(typed)
2452 {
2453 }
2454 };
2455
2456 struct CYStructTail :
2457 CYThing
2458 {
2459 CYTypeStructField *fields_;
2460
2461 CYStructTail(CYTypeStructField *fields) :
2462 fields_(fields)
2463 {
2464 }
2465
2466 CYTarget *Replace(CYContext &context);
2467 virtual void Output(CYOutput &out) const;
2468 };
2469
2470 struct CYTypeStruct :
2471 CYTypeSpecifier
2472 {
2473 CYIdentifier *name_;
2474 CYStructTail *tail_;
2475
2476 CYTypeStruct(CYIdentifier *name, CYStructTail *tail) :
2477 name_(name),
2478 tail_(tail)
2479 {
2480 }
2481
2482 virtual CYTarget *Replace(CYContext &context);
2483 virtual void Output(CYOutput &out) const;
2484 };
2485
2486 struct CYStructDefinition :
2487 CYStatement
2488 {
2489 CYIdentifier *name_;
2490 CYStructTail *tail_;
2491
2492 CYStructDefinition(CYIdentifier *name, CYStructTail *tail) :
2493 name_(name),
2494 tail_(tail)
2495 {
2496 }
2497
2498 CYCompact(None)
2499
2500 virtual CYStatement *Replace(CYContext &context);
2501 virtual void Output(CYOutput &out, CYFlags flags) const;
2502 };
2503
2504 namespace cy {
2505 namespace Syntax {
2506
2507 struct Catch :
2508 CYThing
2509 {
2510 CYIdentifier *name_;
2511 CYStatement *code_;
2512
2513 Catch(CYIdentifier *name, CYStatement *code) :
2514 name_(name),
2515 code_(code)
2516 {
2517 }
2518
2519 void Replace(CYContext &context);
2520 virtual void Output(CYOutput &out) const;
2521 };
2522
2523 struct Try :
2524 CYStatement
2525 {
2526 CYStatement *code_;
2527 Catch *catch_;
2528 CYFinally *finally_;
2529
2530 Try(CYStatement *code, Catch *_catch, CYFinally *finally) :
2531 code_(code),
2532 catch_(_catch),
2533 finally_(finally)
2534 {
2535 }
2536
2537 CYCompact(Short)
2538
2539 virtual CYStatement *Replace(CYContext &context);
2540 virtual void Output(CYOutput &out, CYFlags flags) const;
2541 };
2542
2543 struct Throw :
2544 CYStatement
2545 {
2546 CYExpression *value_;
2547
2548 Throw(CYExpression *value = NULL) :
2549 value_(value)
2550 {
2551 }
2552
2553 CYCompact(None)
2554
2555 virtual CYStatement *Replace(CYContext &context);
2556 virtual void Output(CYOutput &out, CYFlags flags) const;
2557 };
2558
2559 } }
2560
2561 struct CYWith :
2562 CYStatement
2563 {
2564 CYExpression *scope_;
2565 CYStatement *code_;
2566
2567 CYWith(CYExpression *scope, CYStatement *code) :
2568 scope_(scope),
2569 code_(code)
2570 {
2571 }
2572
2573 CYCompact(Long)
2574
2575 virtual CYStatement *Replace(CYContext &context);
2576 virtual void Output(CYOutput &out, CYFlags flags) const;
2577 };
2578
2579 struct CYSwitch :
2580 CYStatement
2581 {
2582 CYExpression *value_;
2583 CYClause *clauses_;
2584
2585 CYSwitch(CYExpression *value, CYClause *clauses) :
2586 value_(value),
2587 clauses_(clauses)
2588 {
2589 }
2590
2591 CYCompact(Long)
2592
2593 virtual CYStatement *Replace(CYContext &context);
2594 virtual void Output(CYOutput &out, CYFlags flags) const;
2595 };
2596
2597 struct CYDebugger :
2598 CYStatement
2599 {
2600 CYDebugger()
2601 {
2602 }
2603
2604 CYCompact(None)
2605
2606 virtual CYStatement *Replace(CYContext &context);
2607 virtual void Output(CYOutput &out, CYFlags flags) const;
2608 };
2609
2610 struct CYCondition :
2611 CYExpression
2612 {
2613 CYExpression *test_;
2614 CYExpression *true_;
2615 CYExpression *false_;
2616
2617 CYCondition(CYExpression *test, CYExpression *_true, CYExpression *_false) :
2618 test_(test),
2619 true_(_true),
2620 false_(_false)
2621 {
2622 }
2623
2624 CYPrecedence(15)
2625
2626 virtual CYExpression *Replace(CYContext &context);
2627 virtual void Output(CYOutput &out, CYFlags flags) const;
2628 };
2629
2630 struct CYAddressOf :
2631 CYPrefix
2632 {
2633 CYAddressOf(CYExpression *rhs) :
2634 CYPrefix(rhs)
2635 {
2636 }
2637
2638 virtual const char *Operator() const {
2639 return "&";
2640 }
2641
2642 CYAlphabetic(false)
2643
2644 virtual CYExpression *Replace(CYContext &context);
2645 };
2646
2647 struct CYIndirect :
2648 CYTarget
2649 {
2650 CYExpression *rhs_;
2651
2652 CYIndirect(CYExpression *rhs) :
2653 rhs_(rhs)
2654 {
2655 }
2656
2657 // XXX: this should be checked
2658 CYPrecedence(2)
2659
2660 virtual CYTarget *Replace(CYContext &context);
2661 virtual void Output(CYOutput &out, CYFlags flags) const;
2662 };
2663
2664 #define CYReplace \
2665 virtual CYExpression *Replace(CYContext &context);
2666
2667 #define CYPostfix_(op, name, args...) \
2668 struct CY ## name : \
2669 CYPostfix \
2670 { args \
2671 CY ## name(CYExpression *lhs) : \
2672 CYPostfix(lhs) \
2673 { \
2674 } \
2675 \
2676 virtual const char *Operator() const { \
2677 return op; \
2678 } \
2679 };
2680
2681 #define CYPrefix_(alphabetic, op, name, args...) \
2682 struct CY ## name : \
2683 CYPrefix \
2684 { args \
2685 CY ## name(CYExpression *rhs) : \
2686 CYPrefix(rhs) \
2687 { \
2688 } \
2689 \
2690 CYAlphabetic(alphabetic) \
2691 \
2692 virtual const char *Operator() const { \
2693 return op; \
2694 } \
2695 };
2696
2697 #define CYInfix_(alphabetic, precedence, op, name, args...) \
2698 struct CY ## name : \
2699 CYInfix \
2700 { args \
2701 CY ## name(CYExpression *lhs, CYExpression *rhs) : \
2702 CYInfix(lhs, rhs) \
2703 { \
2704 } \
2705 \
2706 CYAlphabetic(alphabetic) \
2707 CYPrecedence(precedence) \
2708 \
2709 virtual const char *Operator() const { \
2710 return op; \
2711 } \
2712 };
2713
2714 #define CYAssignment_(op, name, args...) \
2715 struct CY ## name ## Assign : \
2716 CYAssignment \
2717 { args \
2718 CY ## name ## Assign(CYTarget *lhs, CYExpression *rhs) : \
2719 CYAssignment(lhs, rhs) \
2720 { \
2721 } \
2722 \
2723 virtual const char *Operator() const { \
2724 return op; \
2725 } \
2726 };
2727
2728 CYPostfix_("++", PostIncrement)
2729 CYPostfix_("--", PostDecrement)
2730
2731 CYPrefix_(true, "delete", Delete)
2732 CYPrefix_(true, "void", Void)
2733 CYPrefix_(true, "typeof", TypeOf)
2734 CYPrefix_(false, "++", PreIncrement)
2735 CYPrefix_(false, "--", PreDecrement)
2736 CYPrefix_(false, "+", Affirm)
2737 CYPrefix_(false, "-", Negate)
2738 CYPrefix_(false, "~", BitwiseNot)
2739 CYPrefix_(false, "!", LogicalNot)
2740
2741 CYInfix_(false, 5, "*", Multiply, CYReplace)
2742 CYInfix_(false, 5, "/", Divide)
2743 CYInfix_(false, 5, "%", Modulus)
2744 CYInfix_(false, 6, "+", Add, CYReplace)
2745 CYInfix_(false, 6, "-", Subtract)
2746 CYInfix_(false, 7, "<<", ShiftLeft)
2747 CYInfix_(false, 7, ">>", ShiftRightSigned)
2748 CYInfix_(false, 7, ">>>", ShiftRightUnsigned)
2749 CYInfix_(false, 8, "<", Less)
2750 CYInfix_(false, 8, ">", Greater)
2751 CYInfix_(false, 8, "<=", LessOrEqual)
2752 CYInfix_(false, 8, ">=", GreaterOrEqual)
2753 CYInfix_(true, 8, "instanceof", InstanceOf)
2754 CYInfix_(true, 8, "in", In)
2755 CYInfix_(false, 9, "==", Equal)
2756 CYInfix_(false, 9, "!=", NotEqual)
2757 CYInfix_(false, 9, "===", Identical)
2758 CYInfix_(false, 9, "!==", NotIdentical)
2759 CYInfix_(false, 10, "&", BitwiseAnd)
2760 CYInfix_(false, 11, "^", BitwiseXOr)
2761 CYInfix_(false, 12, "|", BitwiseOr)
2762 CYInfix_(false, 13, "&&", LogicalAnd)
2763 CYInfix_(false, 14, "||", LogicalOr)
2764
2765 CYAssignment_("=", )
2766 CYAssignment_("*=", Multiply)
2767 CYAssignment_("/=", Divide)
2768 CYAssignment_("%=", Modulus)
2769 CYAssignment_("+=", Add)
2770 CYAssignment_("-=", Subtract)
2771 CYAssignment_("<<=", ShiftLeft)
2772 CYAssignment_(">>=", ShiftRightSigned)
2773 CYAssignment_(">>>=", ShiftRightUnsigned)
2774 CYAssignment_("&=", BitwiseAnd)
2775 CYAssignment_("^=", BitwiseXOr)
2776 CYAssignment_("|=", BitwiseOr)
2777
2778 #endif/*CYCRIPT_PARSER_HPP*/