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