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