]> git.saurik.com Git - cycript.git/blob - Parser.hpp
Port Objective-C/Replace to C++.
[cycript.git] / Parser.hpp
1 /* Cycript - Inlining/Optimizing JavaScript Compiler
2 * Copyright (C) 2009 Jay Freeman (saurik)
3 */
4
5 /* Modified BSD License {{{ */
6 /*
7 * Redistribution and use in source and binary
8 * forms, with or without modification, are permitted
9 * provided that the following conditions are met:
10 *
11 * 1. Redistributions of source code must retain the
12 * above copyright notice, this list of conditions
13 * and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the
15 * above copyright notice, this list of conditions
16 * and the following disclaimer in the documentation
17 * and/or other materials provided with the
18 * distribution.
19 * 3. The name of the author may not be used to endorse
20 * or promote products derived from this software
21 * without specific prior written permission.
22 *
23 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS''
24 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
25 * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
26 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE
28 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
29 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
30 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
31 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
34 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
35 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
36 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 */
38 /* }}} */
39
40 #ifndef CYPARSER_HPP
41 #define CYPARSER_HPP
42
43 // XXX: wtf is this here?!
44 #define CYPA 16
45
46 #include <iostream>
47
48 #include <string>
49 #include <vector>
50 #include <map>
51 #include <set>
52
53 #include <cstdio>
54 #include <cstdlib>
55
56 #include "location.hh"
57 #include "Pooling.hpp"
58 #include "Options.hpp"
59
60 class CYContext;
61
62 template <typename Type_>
63 struct CYNext {
64 Type_ *next_;
65
66 CYNext() :
67 next_(NULL)
68 {
69 }
70
71 CYNext(Type_ *next) :
72 next_(next)
73 {
74 }
75
76 void SetNext(Type_ *next) {
77 next_ = next;
78 }
79 };
80
81 struct CYThing {
82 virtual ~CYThing() {
83 }
84
85 virtual void Output(struct CYOutput &out) const = 0;
86 };
87
88 struct CYOutput {
89 std::ostream &out_;
90 CYOptions &options_;
91 bool pretty_;
92 unsigned indent_;
93 bool right_;
94
95 enum {
96 NoMode,
97 NoLetter,
98 NoPlus,
99 NoHyphen,
100 Terminated
101 } mode_;
102
103 CYOutput(std::ostream &out, CYOptions &options) :
104 out_(out),
105 options_(options),
106 pretty_(false),
107 indent_(0),
108 right_(false),
109 mode_(NoMode)
110 {
111 }
112
113 void Check(char value);
114 void Terminate();
115
116 CYOutput &operator <<(char rhs);
117 CYOutput &operator <<(const char *rhs);
118
119 _finline CYOutput &operator <<(const CYThing *rhs) {
120 if (rhs != NULL)
121 rhs->Output(*this);
122 return *this;
123 }
124
125 _finline CYOutput &operator <<(const CYThing &rhs) {
126 rhs.Output(*this);
127 return *this;
128 }
129 };
130
131 struct CYPropertyName {
132 virtual void PropertyName(CYOutput &out) const = 0;
133
134 virtual ~CYPropertyName() {
135 }
136 };
137
138 struct CYExpression;
139
140 enum CYNeeded {
141 CYNever = -1,
142 CYSometimes = 0,
143 CYAlways = 1,
144 };
145
146 enum CYFlags {
147 CYNoFlags = 0,
148 CYNoBrace = (1 << 0),
149 CYNoFunction = (1 << 1),
150 CYNoIn = (1 << 2),
151 CYNoCall = (1 << 3),
152 CYNoRightHand = (1 << 4),
153 CYNoDangle = (1 << 5),
154 CYNoInteger = (1 << 6),
155 CYNoBF = (CYNoBrace | CYNoFunction),
156 };
157
158 struct CYStatement :
159 CYNext<CYStatement>
160 {
161 virtual ~CYStatement() {
162 }
163
164 void Single(CYOutput &out, CYFlags flags) const;
165 void Multiple(CYOutput &out, CYFlags flags = CYNoFlags) const;
166
167 CYStatement *ReplaceAll(CYContext &context);
168 virtual CYStatement *Collapse(CYContext &context);
169
170 virtual CYStatement *Replace(CYContext &context) = 0;
171
172 private:
173 virtual void Output(CYOutput &out, CYFlags flags) const = 0;
174 };
175
176 struct CYStatements {
177 CYStatement *first_;
178 CYStatement *last_;
179
180 CYStatements() :
181 first_(NULL),
182 last_(NULL)
183 {
184 }
185
186 operator CYStatement *() const {
187 return first_;
188 }
189
190 CYStatements &operator ->*(CYStatement *next) {
191 if (next != NULL)
192 if (first_ == NULL) {
193 first_ = next;
194 last_ = next;
195 } else for (;; last_ = last_->next_)
196 if (last_->next_ == NULL) {
197 last_->next_ = next;
198 last_ = next;
199 break;
200 }
201 return *this;
202 }
203 };
204
205 struct CYClassName {
206 virtual ~CYClassName() {
207 }
208
209 virtual CYExpression *ClassName(CYContext &context, bool object) = 0;
210 virtual void ClassName(CYOutput &out, bool object) const = 0;
211 };
212
213 struct CYWord :
214 CYThing,
215 CYPropertyName,
216 CYClassName
217 {
218 const char *word_;
219
220 CYWord(const char *word) :
221 word_(word)
222 {
223 }
224
225 void Set(const char *value) {
226 word_ = value;
227 }
228
229 virtual const char *Word() const;
230 virtual void Output(CYOutput &out) const;
231
232 virtual CYExpression *ClassName(CYContext &context, bool object);
233 virtual void ClassName(CYOutput &out, bool object) const;
234 virtual void PropertyName(CYOutput &out) const;
235 };
236
237 _finline std::ostream &operator <<(std::ostream &lhs, const CYWord &rhs) {
238 lhs << &rhs << '=';
239 return lhs << rhs.Word();
240 }
241
242 struct CYIdentifier :
243 CYNext<CYIdentifier>,
244 CYWord
245 {
246 CYIdentifier *replace_;
247 size_t offset_;
248 size_t usage_;
249
250 CYIdentifier(const char *word) :
251 CYWord(word),
252 replace_(NULL),
253 offset_(0),
254 usage_(0)
255 {
256 }
257
258 virtual const char *Word() const;
259 CYIdentifier *Replace(CYContext &context);
260 };
261
262 struct CYComment :
263 CYStatement
264 {
265 const char *value_;
266
267 CYComment(const char *value) :
268 value_(value)
269 {
270 }
271
272 virtual CYStatement *Replace(CYContext &context);
273 virtual void Output(CYOutput &out, CYFlags flags) const;
274 };
275
276 struct CYLabel :
277 CYStatement
278 {
279 CYIdentifier *name_;
280 CYStatement *statement_;
281
282 CYLabel(CYIdentifier *name, CYStatement *statement) :
283 name_(name),
284 statement_(statement)
285 {
286 }
287
288 virtual CYStatement *Replace(CYContext &context);
289 virtual void Output(CYOutput &out, CYFlags flags) const;
290 };
291
292 struct CYCStringLess :
293 std::binary_function<const char *, const char *, bool>
294 {
295 _finline bool operator ()(const char *lhs, const char *rhs) const {
296 return strcmp(lhs, rhs) < 0;
297 }
298 };
299
300 struct CYIdentifierValueLess :
301 std::binary_function<CYIdentifier *, CYIdentifier *, bool>
302 {
303 _finline bool operator ()(CYIdentifier *lhs, CYIdentifier *rhs) const {
304 return CYCStringLess()(lhs->Word(), rhs->Word());
305 }
306 };
307
308 enum CYIdentifierFlags {
309 CYIdentifierArgument,
310 CYIdentifierVariable,
311 CYIdentifierOther,
312 CYIdentifierMagic,
313 CYIdentifierCatch,
314 };
315
316 typedef std::set<const char *, CYCStringLess> CYCStringSet;
317 typedef std::set<CYIdentifier *, CYIdentifierValueLess> CYIdentifierValueSet;
318 typedef std::map<CYIdentifier *, CYIdentifierFlags> CYIdentifierAddressFlagsMap;
319
320 struct CYIdentifierUsage {
321 CYIdentifier *identifier_;
322 size_t usage_;
323 };
324
325 typedef std::vector<CYIdentifierUsage> CYIdentifierUsageVector;
326
327 // XXX: strategy pattern, maybe subclass
328 enum CYScopeType {
329 CYScopeCatch,
330 CYScopeFunction,
331 CYScopeProgram,
332 };
333
334 struct CYScope {
335 CYScopeType type_;
336
337 CYContext &context_;
338 CYStatement *&statements_;
339
340 CYScope *parent_;
341
342 CYIdentifierAddressFlagsMap internal_;
343 CYIdentifierValueSet identifiers_;
344
345 CYScope(CYScopeType type, CYContext &context, CYStatement *&statements);
346
347 void Close();
348
349 void Declare(CYContext &context, CYIdentifier *identifier, CYIdentifierFlags flags);
350 virtual CYIdentifier *Lookup(CYContext &context, CYIdentifier *identifier);
351 void Merge(CYContext &context, CYIdentifier *identifier);
352 void Scope(CYContext &context, CYStatement *&statements);
353 };
354
355 struct CYProgram :
356 CYThing
357 {
358 CYStatement *statements_;
359
360 CYProgram(CYStatement *statements) :
361 statements_(statements)
362 {
363 }
364
365 virtual void Replace(CYContext &context);
366 virtual void Output(CYOutput &out) const;
367 };
368
369 struct CYNonLocal;
370
371 struct CYContext {
372 CYOptions &options_;
373
374 CYScope *scope_;
375 CYIdentifierUsageVector rename_;
376
377 CYNonLocal *nonlocal_;
378 CYNonLocal *nextlocal_;
379 unsigned unique_;
380
381 CYContext(CYOptions &options) :
382 options_(options),
383 scope_(NULL),
384 nonlocal_(NULL),
385 nextlocal_(NULL),
386 unique_(0)
387 {
388 }
389
390 virtual ~CYContext() {
391 }
392
393 template <typename Type_>
394 void Replace(Type_ *&value) {
395 for (;;) if (value == NULL)
396 break;
397 else {
398 Type_ *replace(value->Replace(*this));
399 if (replace != value)
400 value = replace;
401 else break;
402 }
403 }
404
405 void NonLocal(CYStatement *&statements);
406 CYIdentifier *Unique();
407 };
408
409 struct CYNonLocal {
410 CYIdentifier *identifier_;
411
412 CYNonLocal() :
413 identifier_(NULL)
414 {
415 }
416
417 CYIdentifier *Target(CYContext &context) {
418 if (identifier_ == NULL)
419 identifier_ = context.Unique();
420 return identifier_;
421 }
422 };
423
424 struct CYBlock :
425 CYStatement,
426 CYThing
427 {
428 CYStatement *statements_;
429
430 CYBlock(CYStatement *statements) :
431 statements_(statements)
432 {
433 }
434
435 operator CYStatement *() const {
436 return statements_;
437 }
438
439 void AddPrev(CYStatement *statement) {
440 CYStatement *last(statement);
441 while (last->next_ != NULL)
442 last = last->next_;
443 last->SetNext(statements_);
444 statements_ = statement;
445 }
446
447 virtual CYStatement *Replace(CYContext &context);
448
449 virtual void Output(CYOutput &out) const;
450 virtual void Output(CYOutput &out, CYFlags flags) const;
451 };
452
453 enum CYState {
454 CYClear,
455 CYRestricted,
456 CYNewLine
457 };
458
459 class CYDriver {
460 public:
461 CYState state_;
462 void *scanner_;
463
464 const char *data_;
465 size_t size_;
466 FILE *file_;
467
468 bool strict_;
469
470 enum Condition {
471 RegExpCondition,
472 XMLContentCondition,
473 XMLTagCondition,
474 };
475
476 std::string filename_;
477
478 struct Error {
479 bool warning_;
480 cy::location location_;
481 std::string message_;
482 };
483
484 typedef std::vector<Error> Errors;
485
486 CYProgram *program_;
487 Errors errors_;
488
489 bool auto_;
490
491 struct Context {
492 CYExpression *context_;
493
494 Context(CYExpression *context) :
495 context_(context)
496 {
497 }
498
499 typedef std::vector<CYWord *> Words;
500 Words words_;
501 };
502
503 typedef std::vector<Context> Contexts;
504 Contexts contexts_;
505
506 CYExpression *context_;
507
508 enum Mode {
509 AutoNone,
510 AutoPrimary,
511 AutoDirect,
512 AutoIndirect,
513 AutoMessage
514 } mode_;
515
516 private:
517 void ScannerInit();
518 void ScannerDestroy();
519
520 public:
521 CYDriver(const std::string &filename = "");
522 ~CYDriver();
523
524 Condition GetCondition();
525 void SetCondition(Condition condition);
526
527 void PushCondition(Condition condition);
528 void PopCondition();
529
530 void Warning(const cy::location &location, const char *message);
531 };
532
533 struct CYForInitialiser {
534 virtual ~CYForInitialiser() {
535 }
536
537 virtual void For(CYOutput &out) const = 0;
538 virtual CYExpression *Replace(CYContext &context) = 0;
539 };
540
541 struct CYForInInitialiser {
542 virtual ~CYForInInitialiser() {
543 }
544
545 virtual void ForIn(CYOutput &out, CYFlags flags) const = 0;
546 virtual const char *ForEachIn() const = 0;
547 virtual CYExpression *ForEachIn(CYContext &out) = 0;
548 virtual CYExpression *Replace(CYContext &context) = 0;
549 };
550
551 struct CYNumber;
552 struct CYString;
553
554 struct CYExpression :
555 CYNext<CYExpression>,
556 CYForInitialiser,
557 CYForInInitialiser,
558 CYClassName,
559 CYThing
560 {
561 virtual unsigned Precedence() const = 0;
562
563 virtual bool RightHand() const {
564 return true;
565 }
566
567 virtual void For(CYOutput &out) const;
568 virtual void ForIn(CYOutput &out, CYFlags flags) const;
569
570 virtual const char *ForEachIn() const;
571 virtual CYExpression *ForEachIn(CYContext &out);
572
573 virtual CYExpression *AddArgument(CYContext &context, CYExpression *value);
574
575 virtual void Output(CYOutput &out) const;
576 virtual void Output(CYOutput &out, CYFlags flags) const = 0;
577 void Output(CYOutput &out, unsigned precedence, CYFlags flags) const;
578
579 virtual CYExpression *ClassName(CYContext &context, bool object);
580 virtual void ClassName(CYOutput &out, bool object) const;
581
582 CYExpression *ReplaceAll(CYContext &context);
583
584 virtual CYExpression *Replace(CYContext &context) = 0;
585
586 virtual CYExpression *Primitive(CYContext &context) {
587 return this;
588 }
589
590 virtual CYNumber *Number(CYContext &context) {
591 return NULL;
592 }
593
594 virtual CYString *String(CYContext &context) {
595 return NULL;
596 }
597
598 virtual const char *Word() const {
599 return NULL;
600 }
601 };
602
603 #define CYAlphabetic(value) \
604 virtual bool Alphabetic() const { \
605 return value; \
606 }
607
608 #define CYPrecedence(value) \
609 virtual unsigned Precedence() const { \
610 return value; \
611 }
612
613 #define CYRightHand(value) \
614 virtual bool RightHand() const { \
615 return value; \
616 }
617
618 struct CYCompound :
619 CYExpression
620 {
621 CYExpression *expressions_;
622
623 CYCompound(CYExpression *expressions = NULL) :
624 expressions_(expressions)
625 {
626 }
627
628 void AddPrev(CYExpression *expression) {
629 CYExpression *last(expression);
630 while (last->next_ != NULL)
631 last = last->next_;
632 last->SetNext(expressions_);
633 expressions_ = expression;
634 }
635
636 CYPrecedence(17)
637
638 virtual CYExpression *Replace(CYContext &context);
639 void Output(CYOutput &out, CYFlags flags) const;
640 };
641
642 struct CYFunctionParameter :
643 CYNext<CYFunctionParameter>,
644 CYThing
645 {
646 CYIdentifier *name_;
647
648 CYFunctionParameter(CYIdentifier *name, CYFunctionParameter *next = NULL) :
649 CYNext<CYFunctionParameter>(next),
650 name_(name)
651 {
652 }
653
654 virtual CYFunctionParameter *Replace(CYContext &context, CYBlock &code);
655 virtual void Output(CYOutput &out) const;
656 };
657
658 struct CYOptionalFunctionParameter :
659 CYFunctionParameter
660 {
661 CYExpression *initializer_;
662
663 CYOptionalFunctionParameter(CYIdentifier *name, CYExpression *initializer, CYFunctionParameter *next = NULL) :
664 CYFunctionParameter(name, next),
665 initializer_(initializer)
666 {
667 }
668
669 virtual CYFunctionParameter *Replace(CYContext &context, CYBlock &code);
670 virtual void Output(CYOutput &out) const;
671 };
672
673 struct CYComprehension :
674 CYNext<CYComprehension>,
675 CYThing
676 {
677 virtual const char *Name() const = 0;
678
679 virtual CYFunctionParameter *Parameter(CYContext &context) const = 0;
680 CYFunctionParameter *Parameters(CYContext &context) const;
681 virtual CYStatement *Replace(CYContext &context, CYStatement *statement) const;
682 virtual void Output(CYOutput &out) const = 0;
683 };
684
685 struct CYForInComprehension :
686 CYComprehension
687 {
688 CYIdentifier *name_;
689 CYExpression *set_;
690
691 CYForInComprehension(CYIdentifier *name, CYExpression *set) :
692 name_(name),
693 set_(set)
694 {
695 }
696
697 virtual const char *Name() const {
698 return name_->Word();
699 }
700
701 virtual CYFunctionParameter *Parameter(CYContext &context) const;
702 virtual CYStatement *Replace(CYContext &context, CYStatement *statement) const;
703 virtual void Output(CYOutput &out) const;
704 };
705
706 struct CYForEachInComprehension :
707 CYComprehension
708 {
709 CYIdentifier *name_;
710 CYExpression *set_;
711
712 CYForEachInComprehension(CYIdentifier *name, CYExpression *set) :
713 name_(name),
714 set_(set)
715 {
716 }
717
718 virtual const char *Name() const {
719 return name_->Word();
720 }
721
722 virtual CYFunctionParameter *Parameter(CYContext &context) const;
723 virtual CYStatement *Replace(CYContext &context, CYStatement *statement) const;
724 virtual void Output(CYOutput &out) const;
725 };
726
727 struct CYIfComprehension :
728 CYComprehension
729 {
730 CYExpression *test_;
731
732 CYIfComprehension(CYExpression *test) :
733 test_(test)
734 {
735 }
736
737 virtual const char *Name() const {
738 return NULL;
739 }
740
741 virtual CYFunctionParameter *Parameter(CYContext &context) const;
742 virtual CYStatement *Replace(CYContext &context, CYStatement *statement) const;
743 virtual void Output(CYOutput &out) const;
744 };
745
746 struct CYArrayComprehension :
747 CYExpression
748 {
749 CYExpression *expression_;
750 CYComprehension *comprehensions_;
751
752 CYArrayComprehension(CYExpression *expression, CYComprehension *comprehensions) :
753 expression_(expression),
754 comprehensions_(comprehensions)
755 {
756 }
757
758 CYPrecedence(0)
759
760 virtual CYExpression *Replace(CYContext &context);
761 virtual void Output(CYOutput &out, CYFlags flags) const;
762 };
763
764 struct CYLiteral :
765 CYExpression
766 {
767 CYPrecedence(0)
768 CYRightHand(false)
769 };
770
771 struct CYTrivial :
772 CYLiteral
773 {
774 virtual CYExpression *Replace(CYContext &context);
775 };
776
777 struct CYMagic :
778 CYExpression
779 {
780 CYPrecedence(0)
781 CYRightHand(false)
782 };
783
784 struct CYRange {
785 uint64_t lo_;
786 uint64_t hi_;
787
788 CYRange(uint64_t lo, uint64_t hi) :
789 lo_(lo), hi_(hi)
790 {
791 }
792
793 bool operator [](uint8_t value) const {
794 return !(value >> 7) && (value >> 6 ? hi_ : lo_) >> (value & 0x3f) & 0x1;
795 }
796
797 void operator()(uint8_t value) {
798 if (value >> 7)
799 return;
800 (value >> 6 ? hi_ : lo_) |= uint64_t(0x1) << (value & 0x3f);
801 }
802 };
803
804 extern CYRange DigitRange_;
805 extern CYRange WordStartRange_;
806 extern CYRange WordEndRange_;
807
808 struct CYString :
809 CYTrivial,
810 CYPropertyName
811 {
812 const char *value_;
813 size_t size_;
814
815 CYString() :
816 value_(NULL),
817 size_(0)
818 {
819 }
820
821 CYString(const char *value) :
822 value_(value),
823 size_(strlen(value))
824 {
825 }
826
827 CYString(const char *value, size_t size) :
828 value_(value),
829 size_(size)
830 {
831 }
832
833 CYString(const CYWord *word) :
834 value_(word->Word()),
835 size_(strlen(value_))
836 {
837 }
838
839 const char *Value() const {
840 return value_;
841 }
842
843 virtual const char *Word() const;
844
845 virtual CYNumber *Number(CYContext &context);
846 virtual CYString *String(CYContext &context);
847
848 CYString *Concat(CYContext &out, CYString *rhs) const;
849 virtual void Output(CYOutput &out, CYFlags flags) const;
850 virtual void PropertyName(CYOutput &out) const;
851 };
852
853 struct CYNumber :
854 CYTrivial,
855 CYPropertyName
856 {
857 double value_;
858
859 CYNumber(double value) :
860 value_(value)
861 {
862 }
863
864 double Value() const {
865 return value_;
866 }
867
868 virtual CYNumber *Number(CYContext &context);
869 virtual CYString *String(CYContext &context);
870
871 virtual void Output(CYOutput &out, CYFlags flags) const;
872 virtual void PropertyName(CYOutput &out) const;
873 };
874
875 struct CYRegEx :
876 CYTrivial
877 {
878 const char *value_;
879
880 CYRegEx(const char *value) :
881 value_(value)
882 {
883 }
884
885 const char *Value() const {
886 return value_;
887 }
888
889 virtual void Output(CYOutput &out, CYFlags flags) const;
890 };
891
892 struct CYNull :
893 CYWord,
894 CYTrivial
895 {
896 CYNull() :
897 CYWord("null")
898 {
899 }
900
901 virtual CYNumber *Number(CYContext &context);
902 virtual CYString *String(CYContext &context);
903
904 virtual void Output(CYOutput &out, CYFlags flags) const;
905 };
906
907 struct CYThis :
908 CYWord,
909 CYMagic
910 {
911 CYThis() :
912 CYWord("this")
913 {
914 }
915
916 virtual CYExpression *Replace(CYContext &context);
917 virtual void Output(CYOutput &out, CYFlags flags) const;
918 };
919
920 struct CYBoolean :
921 CYTrivial
922 {
923 virtual bool Value() const = 0;
924 virtual void Output(CYOutput &out, CYFlags flags) const;
925 };
926
927 struct CYFalse :
928 CYWord,
929 CYBoolean
930 {
931 CYFalse() :
932 CYWord("false")
933 {
934 }
935
936 virtual bool Value() const {
937 return false;
938 }
939
940 virtual CYNumber *Number(CYContext &context);
941 virtual CYString *String(CYContext &context);
942 };
943
944 struct CYTrue :
945 CYWord,
946 CYBoolean
947 {
948 CYTrue() :
949 CYWord("true")
950 {
951 }
952
953 virtual bool Value() const {
954 return true;
955 }
956
957 virtual CYNumber *Number(CYContext &context);
958 virtual CYString *String(CYContext &context);
959 };
960
961 struct CYVariable :
962 CYExpression
963 {
964 CYIdentifier *name_;
965
966 CYVariable(CYIdentifier *name) :
967 name_(name)
968 {
969 }
970
971 CYVariable(const char *name) :
972 name_(new($pool) CYIdentifier(name))
973 {
974 }
975
976 CYPrecedence(0)
977 CYRightHand(false)
978
979 virtual CYExpression *Replace(CYContext &context);
980 virtual void Output(CYOutput &out, CYFlags flags) const;
981 };
982
983 struct CYPrefix :
984 CYExpression
985 {
986 CYExpression *rhs_;
987
988 CYPrefix(CYExpression *rhs) :
989 rhs_(rhs)
990 {
991 }
992
993 virtual bool Alphabetic() const = 0;
994 virtual const char *Operator() const = 0;
995
996 CYPrecedence(4)
997
998 virtual CYExpression *Replace(CYContext &context);
999 virtual void Output(CYOutput &out, CYFlags flags) const;
1000 };
1001
1002 struct CYInfix :
1003 CYExpression
1004 {
1005 CYExpression *lhs_;
1006 CYExpression *rhs_;
1007
1008 CYInfix(CYExpression *lhs, CYExpression *rhs) :
1009 lhs_(lhs),
1010 rhs_(rhs)
1011 {
1012 }
1013
1014 void SetLeft(CYExpression *lhs) {
1015 lhs_ = lhs;
1016 }
1017
1018 virtual bool Alphabetic() const = 0;
1019 virtual const char *Operator() const = 0;
1020
1021 virtual CYExpression *Replace(CYContext &context);
1022 virtual void Output(CYOutput &out, CYFlags flags) const;
1023 };
1024
1025 struct CYPostfix :
1026 CYExpression
1027 {
1028 CYExpression *lhs_;
1029
1030 CYPostfix(CYExpression *lhs) :
1031 lhs_(lhs)
1032 {
1033 }
1034
1035 virtual const char *Operator() const = 0;
1036
1037 CYPrecedence(3)
1038
1039 virtual CYExpression *Replace(CYContext &context);
1040 virtual void Output(CYOutput &out, CYFlags flags) const;
1041 };
1042
1043 struct CYAssignment :
1044 CYExpression
1045 {
1046 CYExpression *lhs_;
1047 CYExpression *rhs_;
1048
1049 CYAssignment(CYExpression *lhs, CYExpression *rhs) :
1050 lhs_(lhs),
1051 rhs_(rhs)
1052 {
1053 }
1054
1055 void SetLeft(CYExpression *lhs) {
1056 lhs_ = lhs;
1057 }
1058
1059 virtual const char *Operator() const = 0;
1060
1061 CYPrecedence(16)
1062
1063 virtual CYExpression *Replace(CYContext &context);
1064 virtual void Output(CYOutput &out, CYFlags flags) const;
1065 };
1066
1067 struct CYArgument :
1068 CYNext<CYArgument>,
1069 CYThing
1070 {
1071 CYWord *name_;
1072 CYExpression *value_;
1073
1074 CYArgument(CYExpression *value, CYArgument *next = NULL) :
1075 CYNext<CYArgument>(next),
1076 name_(NULL),
1077 value_(value)
1078 {
1079 }
1080
1081 CYArgument(CYWord *name, CYExpression *value, CYArgument *next = NULL) :
1082 CYNext<CYArgument>(next),
1083 name_(name),
1084 value_(value)
1085 {
1086 }
1087
1088 void Replace(CYContext &context);
1089 void Output(CYOutput &out) const;
1090 };
1091
1092 struct CYBlank :
1093 public CYWord
1094 {
1095 CYBlank() :
1096 CYWord("")
1097 {
1098 }
1099 };
1100
1101 struct CYClause :
1102 CYThing,
1103 CYNext<CYClause>
1104 {
1105 CYExpression *case_;
1106 CYStatement *statements_;
1107
1108 CYClause(CYExpression *_case, CYStatement *statements) :
1109 case_(_case),
1110 statements_(statements)
1111 {
1112 }
1113
1114 void Replace(CYContext &context);
1115 virtual void Output(CYOutput &out) const;
1116 };
1117
1118 struct CYElement :
1119 CYNext<CYElement>,
1120 CYThing
1121 {
1122 CYExpression *value_;
1123
1124 CYElement(CYExpression *value, CYElement *next) :
1125 CYNext<CYElement>(next),
1126 value_(value)
1127 {
1128 }
1129
1130 void Replace(CYContext &context);
1131 void Output(CYOutput &out) const;
1132 };
1133
1134 struct CYArray :
1135 CYLiteral
1136 {
1137 CYElement *elements_;
1138
1139 CYArray(CYElement *elements = NULL) :
1140 elements_(elements)
1141 {
1142 }
1143
1144 virtual CYExpression *Replace(CYContext &context);
1145 virtual void Output(CYOutput &out, CYFlags flags) const;
1146 };
1147
1148 struct CYProperty :
1149 CYNext<CYProperty>,
1150 CYThing
1151 {
1152 CYPropertyName *name_;
1153 CYExpression *value_;
1154
1155 CYProperty(CYPropertyName *name, CYExpression *value, CYProperty *next = NULL) :
1156 CYNext<CYProperty>(next),
1157 name_(name),
1158 value_(value)
1159 {
1160 }
1161
1162 void Replace(CYContext &context);
1163 virtual void Output(CYOutput &out) const;
1164 };
1165
1166 struct CYDeclaration :
1167 CYForInInitialiser
1168 {
1169 CYIdentifier *identifier_;
1170 CYExpression *initialiser_;
1171
1172 CYDeclaration(CYIdentifier *identifier, CYExpression *initialiser = NULL) :
1173 identifier_(identifier),
1174 initialiser_(initialiser)
1175 {
1176 }
1177
1178 virtual void ForIn(CYOutput &out, CYFlags flags) const;
1179
1180 virtual const char *ForEachIn() const;
1181 virtual CYExpression *ForEachIn(CYContext &out);
1182
1183 virtual CYExpression *Replace(CYContext &context);
1184 virtual CYAssignment *Assignment(CYContext &context);
1185
1186 virtual void Output(CYOutput &out, CYFlags flags) const;
1187 };
1188
1189 struct CYDeclarations :
1190 CYNext<CYDeclarations>,
1191 CYThing,
1192 CYForInitialiser
1193 {
1194 CYDeclaration *declaration_;
1195
1196 CYDeclarations(CYDeclaration *declaration, CYDeclarations *next = NULL) :
1197 CYNext<CYDeclarations>(next),
1198 declaration_(declaration)
1199 {
1200 }
1201
1202 virtual void For(CYOutput &out) const;
1203
1204 virtual CYCompound *Replace(CYContext &context);
1205 CYProperty *Property(CYContext &context);
1206
1207 virtual void Output(CYOutput &out) const;
1208 virtual void Output(CYOutput &out, CYFlags flags) const;
1209 };
1210
1211 struct CYVar :
1212 CYStatement
1213 {
1214 CYDeclarations *declarations_;
1215
1216 CYVar(CYDeclarations *declarations) :
1217 declarations_(declarations)
1218 {
1219 }
1220
1221 virtual CYStatement *Replace(CYContext &context);
1222 virtual void Output(CYOutput &out, CYFlags flags) const;
1223 };
1224
1225 struct CYLet :
1226 CYStatement
1227 {
1228 CYDeclarations *declarations_;
1229 CYBlock code_;
1230
1231 CYLet(CYDeclarations *declarations, CYStatement *statements) :
1232 declarations_(declarations),
1233 code_(statements)
1234 {
1235 }
1236
1237 virtual CYStatement *Replace(CYContext &context);
1238 virtual void Output(CYOutput &out, CYFlags flags) const;
1239 };
1240
1241 struct CYFor :
1242 CYStatement
1243 {
1244 CYForInitialiser *initialiser_;
1245 CYExpression *test_;
1246 CYExpression *increment_;
1247 CYStatement *code_;
1248
1249 CYFor(CYForInitialiser *initialiser, CYExpression *test, CYExpression *increment, CYStatement *code) :
1250 initialiser_(initialiser),
1251 test_(test),
1252 increment_(increment),
1253 code_(code)
1254 {
1255 }
1256
1257 virtual CYStatement *Replace(CYContext &context);
1258 virtual void Output(CYOutput &out, CYFlags flags) const;
1259 };
1260
1261 struct CYForIn :
1262 CYStatement
1263 {
1264 CYForInInitialiser *initialiser_;
1265 CYExpression *set_;
1266 CYStatement *code_;
1267
1268 CYForIn(CYForInInitialiser *initialiser, CYExpression *set, CYStatement *code) :
1269 initialiser_(initialiser),
1270 set_(set),
1271 code_(code)
1272 {
1273 }
1274
1275 virtual CYStatement *Replace(CYContext &context);
1276 virtual void Output(CYOutput &out, CYFlags flags) const;
1277 };
1278
1279 struct CYForEachIn :
1280 CYStatement
1281 {
1282 CYForInInitialiser *initialiser_;
1283 CYExpression *set_;
1284 CYStatement *code_;
1285
1286 CYForEachIn(CYForInInitialiser *initialiser, CYExpression *set, CYStatement *code) :
1287 initialiser_(initialiser),
1288 set_(set),
1289 code_(code)
1290 {
1291 }
1292
1293 virtual CYStatement *Replace(CYContext &context);
1294 virtual void Output(CYOutput &out, CYFlags flags) const;
1295 };
1296
1297 struct CYObject :
1298 CYLiteral
1299 {
1300 CYProperty *properties_;
1301
1302 CYObject(CYProperty *properties = NULL) :
1303 properties_(properties)
1304 {
1305 }
1306
1307 virtual CYExpression *Replace(CYContext &context);
1308 void Output(CYOutput &out, CYFlags flags) const;
1309 };
1310
1311 struct CYMember :
1312 CYExpression
1313 {
1314 CYExpression *object_;
1315 CYExpression *property_;
1316
1317 CYMember(CYExpression *object, CYExpression *property) :
1318 object_(object),
1319 property_(property)
1320 {
1321 }
1322
1323 void SetLeft(CYExpression *object) {
1324 object_ = object;
1325 }
1326
1327 void Replace_(CYContext &context);
1328 };
1329
1330 struct CYDirectMember :
1331 CYMember
1332 {
1333 CYDirectMember(CYExpression *object, CYExpression *property) :
1334 CYMember(object, property)
1335 {
1336 }
1337
1338 CYPrecedence(1)
1339 CYRightHand(false)
1340
1341 virtual CYExpression *Replace(CYContext &context);
1342 virtual void Output(CYOutput &out, CYFlags flags) const;
1343 };
1344
1345 struct CYIndirectMember :
1346 CYMember
1347 {
1348 CYIndirectMember(CYExpression *object, CYExpression *property) :
1349 CYMember(object, property)
1350 {
1351 }
1352
1353 CYPrecedence(1)
1354 CYRightHand(false)
1355
1356 virtual CYExpression *Replace(CYContext &context);
1357 virtual void Output(CYOutput &out, CYFlags flags) const;
1358 };
1359
1360 namespace cy {
1361 namespace Syntax {
1362
1363 struct New :
1364 CYExpression
1365 {
1366 CYExpression *constructor_;
1367 CYArgument *arguments_;
1368
1369 New(CYExpression *constructor, CYArgument *arguments) :
1370 constructor_(constructor),
1371 arguments_(arguments)
1372 {
1373 }
1374
1375 virtual unsigned Precedence() const {
1376 return arguments_ == NULL ? 2 : 1;
1377 }
1378
1379 CYRightHand(false)
1380
1381 virtual CYExpression *Replace(CYContext &context);
1382 virtual void Output(CYOutput &out, CYFlags flags) const;
1383
1384 virtual CYExpression *AddArgument(CYContext &context, CYExpression *value);
1385 };
1386
1387 } }
1388
1389 struct CYCall :
1390 CYExpression
1391 {
1392 CYExpression *function_;
1393 CYArgument *arguments_;
1394
1395 CYCall(CYExpression *function, CYArgument *arguments = NULL) :
1396 function_(function),
1397 arguments_(arguments)
1398 {
1399 }
1400
1401 CYPrecedence(1)
1402 CYRightHand(false)
1403
1404 virtual CYExpression *Replace(CYContext &context);
1405 virtual void Output(CYOutput &out, CYFlags flags) const;
1406
1407 virtual CYExpression *AddArgument(CYContext &context, CYExpression *value);
1408 };
1409
1410 struct CYRubyProc;
1411
1412 struct CYRubyBlock :
1413 CYExpression
1414 {
1415 CYExpression *call_;
1416 CYRubyProc *proc_;
1417
1418 CYRubyBlock(CYExpression *call, CYRubyProc *proc) :
1419 call_(call),
1420 proc_(proc)
1421 {
1422 }
1423
1424 CYPrecedence(1)
1425 CYRightHand(false)
1426
1427 virtual CYExpression *Replace(CYContext &context);
1428 virtual void Output(CYOutput &out, CYFlags flags) const;
1429 };
1430
1431 struct CYIf :
1432 CYStatement
1433 {
1434 CYExpression *test_;
1435 CYStatement *true_;
1436 CYStatement *false_;
1437
1438 CYIf(CYExpression *test, CYStatement *_true, CYStatement *_false = NULL) :
1439 test_(test),
1440 true_(_true),
1441 false_(_false)
1442 {
1443 }
1444
1445 virtual CYStatement *Replace(CYContext &context);
1446 virtual void Output(CYOutput &out, CYFlags flags) const;
1447 };
1448
1449 struct CYDoWhile :
1450 CYStatement
1451 {
1452 CYExpression *test_;
1453 CYStatement *code_;
1454
1455 CYDoWhile(CYExpression *test, CYStatement *code) :
1456 test_(test),
1457 code_(code)
1458 {
1459 }
1460
1461 virtual CYStatement *Replace(CYContext &context);
1462 virtual void Output(CYOutput &out, CYFlags flags) const;
1463 };
1464
1465 struct CYWhile :
1466 CYStatement
1467 {
1468 CYExpression *test_;
1469 CYStatement *code_;
1470
1471 CYWhile(CYExpression *test, CYStatement *code) :
1472 test_(test),
1473 code_(code)
1474 {
1475 }
1476
1477 virtual CYStatement *Replace(CYContext &context);
1478 virtual void Output(CYOutput &out, CYFlags flags) const;
1479 };
1480
1481 // XXX: this should be split up into CYAnonymousFunction and CYNamedFunction (subclass)
1482 struct CYFunction {
1483 CYIdentifier *name_;
1484 CYFunctionParameter *parameters_;
1485 CYBlock code_;
1486 CYNonLocal *nonlocal_;
1487
1488 CYFunction(CYIdentifier *name, CYFunctionParameter *parameters, CYStatement *statements) :
1489 name_(name),
1490 parameters_(parameters),
1491 code_(statements),
1492 nonlocal_(NULL)
1493 {
1494 }
1495
1496 virtual ~CYFunction() {
1497 }
1498
1499 void Inject(CYContext &context);
1500 virtual void Replace_(CYContext &context, bool outer);
1501 virtual void Output(CYOutput &out, CYFlags flags) const;
1502 };
1503
1504 // XXX: this should be split up into CYAnonymousFunctionExpression and CYNamedFunctionExpression
1505 struct CYFunctionExpression :
1506 CYFunction,
1507 CYExpression
1508 {
1509 CYFunctionExpression(CYIdentifier *name, CYFunctionParameter *parameters, CYStatement *statements) :
1510 CYFunction(name, parameters, statements)
1511 {
1512 }
1513
1514 CYPrecedence(0)
1515 CYRightHand(false)
1516
1517 virtual CYExpression *Replace(CYContext &context);
1518 virtual void Output(CYOutput &out, CYFlags flags) const;
1519 };
1520
1521 // XXX: this should derive from CYAnonymousFunctionExpression
1522 struct CYRubyProc :
1523 CYFunctionExpression
1524 {
1525 CYRubyProc(CYFunctionParameter *parameters, CYStatement *statements) :
1526 CYFunctionExpression(NULL, parameters, statements)
1527 {
1528 }
1529
1530 virtual CYExpression *Replace(CYContext &context);
1531 virtual void Output(CYOutput &out, CYFlags flags) const;
1532 };
1533
1534 // XXX: this should derive from CYNamedFunction
1535 struct CYFunctionStatement :
1536 CYFunction,
1537 CYStatement
1538 {
1539 CYFunctionStatement(CYIdentifier *name, CYFunctionParameter *parameters, CYStatement *statements) :
1540 CYFunction(name, parameters, statements)
1541 {
1542 }
1543
1544 virtual CYStatement *Replace(CYContext &context);
1545 virtual void Output(CYOutput &out, CYFlags flags) const;
1546 };
1547
1548 struct CYExpress :
1549 CYStatement
1550 {
1551 CYExpression *expression_;
1552
1553 CYExpress(CYExpression *expression) :
1554 expression_(expression)
1555 {
1556 if (expression == NULL)
1557 throw;
1558 }
1559
1560 virtual CYStatement *Collapse(CYContext &context);
1561 virtual CYStatement *Replace(CYContext &context);
1562 virtual void Output(CYOutput &out, CYFlags flags) const;
1563 };
1564
1565 struct CYContinue :
1566 CYStatement
1567 {
1568 CYIdentifier *label_;
1569
1570 CYContinue(CYIdentifier *label) :
1571 label_(label)
1572 {
1573 }
1574
1575 virtual CYStatement *Replace(CYContext &context);
1576 virtual void Output(CYOutput &out, CYFlags flags) const;
1577 };
1578
1579 struct CYBreak :
1580 CYStatement
1581 {
1582 CYIdentifier *label_;
1583
1584 CYBreak(CYIdentifier *label) :
1585 label_(label)
1586 {
1587 }
1588
1589 virtual CYStatement *Replace(CYContext &context);
1590 virtual void Output(CYOutput &out, CYFlags flags) const;
1591 };
1592
1593 struct CYReturn :
1594 CYStatement
1595 {
1596 CYExpression *value_;
1597
1598 CYReturn(CYExpression *value) :
1599 value_(value)
1600 {
1601 }
1602
1603 virtual CYStatement *Replace(CYContext &context);
1604 virtual void Output(CYOutput &out, CYFlags flags) const;
1605 };
1606
1607 struct CYEmpty :
1608 CYStatement
1609 {
1610 virtual CYStatement *Collapse(CYContext &context);
1611 virtual CYStatement *Replace(CYContext &context);
1612 virtual void Output(CYOutput &out, CYFlags flags) const;
1613 };
1614
1615 struct CYFinally :
1616 CYThing
1617 {
1618 CYBlock code_;
1619
1620 CYFinally(CYStatement *statements) :
1621 code_(statements)
1622 {
1623 }
1624
1625 void Replace(CYContext &context);
1626 virtual void Output(CYOutput &out) const;
1627 };
1628
1629 namespace cy {
1630 namespace Syntax {
1631
1632 struct Catch :
1633 CYThing
1634 {
1635 CYIdentifier *name_;
1636 CYBlock code_;
1637
1638 Catch(CYIdentifier *name, CYStatement *statements) :
1639 name_(name),
1640 code_(statements)
1641 {
1642 }
1643
1644 void Replace(CYContext &context);
1645 virtual void Output(CYOutput &out) const;
1646 };
1647
1648 struct Try :
1649 CYStatement
1650 {
1651 CYBlock code_;
1652 Catch *catch_;
1653 CYFinally *finally_;
1654
1655 Try(CYStatement *statements, Catch *_catch, CYFinally *finally) :
1656 code_(statements),
1657 catch_(_catch),
1658 finally_(finally)
1659 {
1660 }
1661
1662 virtual CYStatement *Replace(CYContext &context);
1663 virtual void Output(CYOutput &out, CYFlags flags) const;
1664 };
1665
1666 struct Throw :
1667 CYStatement
1668 {
1669 CYExpression *value_;
1670
1671 Throw(CYExpression *value = NULL) :
1672 value_(value)
1673 {
1674 }
1675
1676 virtual CYStatement *Replace(CYContext &context);
1677 virtual void Output(CYOutput &out, CYFlags flags) const;
1678 };
1679
1680 } }
1681
1682 struct CYWith :
1683 CYStatement
1684 {
1685 CYExpression *scope_;
1686 CYStatement *code_;
1687
1688 CYWith(CYExpression *scope, CYStatement *code) :
1689 scope_(scope),
1690 code_(code)
1691 {
1692 }
1693
1694 virtual CYStatement *Replace(CYContext &context);
1695 virtual void Output(CYOutput &out, CYFlags flags) const;
1696 };
1697
1698 struct CYSwitch :
1699 CYStatement
1700 {
1701 CYExpression *value_;
1702 CYClause *clauses_;
1703
1704 CYSwitch(CYExpression *value, CYClause *clauses) :
1705 value_(value),
1706 clauses_(clauses)
1707 {
1708 }
1709
1710 virtual CYStatement *Replace(CYContext &context);
1711 virtual void Output(CYOutput &out, CYFlags flags) const;
1712 };
1713
1714 struct CYCondition :
1715 CYExpression
1716 {
1717 CYExpression *test_;
1718 CYExpression *true_;
1719 CYExpression *false_;
1720
1721 CYCondition(CYExpression *test, CYExpression *_true, CYExpression *_false) :
1722 test_(test),
1723 true_(_true),
1724 false_(_false)
1725 {
1726 }
1727
1728 CYPrecedence(15)
1729
1730 virtual CYExpression *Replace(CYContext &context);
1731 virtual void Output(CYOutput &out, CYFlags flags) const;
1732 };
1733
1734 struct CYAddressOf :
1735 CYPrefix
1736 {
1737 CYAddressOf(CYExpression *rhs) :
1738 CYPrefix(rhs)
1739 {
1740 }
1741
1742 virtual const char *Operator() const {
1743 return "&";
1744 }
1745
1746 CYAlphabetic(false)
1747
1748 virtual CYExpression *Replace(CYContext &context);
1749 };
1750
1751 struct CYIndirect :
1752 CYPrefix
1753 {
1754 CYIndirect(CYExpression *rhs) :
1755 CYPrefix(rhs)
1756 {
1757 }
1758
1759 virtual const char *Operator() const {
1760 return "*";
1761 }
1762
1763 CYAlphabetic(false)
1764
1765 virtual CYExpression *Replace(CYContext &context);
1766 };
1767
1768 #define CYReplace \
1769 virtual CYExpression *Replace(CYContext &context);
1770
1771 #define CYPostfix_(op, name, args...) \
1772 struct CY ## name : \
1773 CYPostfix \
1774 { args \
1775 CY ## name(CYExpression *lhs) : \
1776 CYPostfix(lhs) \
1777 { \
1778 } \
1779 \
1780 virtual const char *Operator() const { \
1781 return op; \
1782 } \
1783 };
1784
1785 #define CYPrefix_(alphabetic, op, name, args...) \
1786 struct CY ## name : \
1787 CYPrefix \
1788 { args \
1789 CY ## name(CYExpression *rhs) : \
1790 CYPrefix(rhs) \
1791 { \
1792 } \
1793 \
1794 CYAlphabetic(alphabetic) \
1795 \
1796 virtual const char *Operator() const { \
1797 return op; \
1798 } \
1799 };
1800
1801 #define CYInfix_(alphabetic, precedence, op, name, args...) \
1802 struct CY ## name : \
1803 CYInfix \
1804 { args \
1805 CY ## name(CYExpression *lhs, CYExpression *rhs) : \
1806 CYInfix(lhs, rhs) \
1807 { \
1808 } \
1809 \
1810 CYAlphabetic(alphabetic) \
1811 CYPrecedence(precedence) \
1812 \
1813 virtual const char *Operator() const { \
1814 return op; \
1815 } \
1816 };
1817
1818 #define CYAssignment_(op, name, args...) \
1819 struct CY ## name ## Assign : \
1820 CYAssignment \
1821 { args \
1822 CY ## name ## Assign(CYExpression *lhs, CYExpression *rhs) : \
1823 CYAssignment(lhs, rhs) \
1824 { \
1825 } \
1826 \
1827 virtual const char *Operator() const { \
1828 return op; \
1829 } \
1830 };
1831
1832 CYPostfix_("++", PostIncrement)
1833 CYPostfix_("--", PostDecrement)
1834
1835 CYPrefix_(true, "delete", Delete)
1836 CYPrefix_(true, "void", Void)
1837 CYPrefix_(true, "typeof", TypeOf)
1838 CYPrefix_(false, "++", PreIncrement)
1839 CYPrefix_(false, "--", PreDecrement)
1840 CYPrefix_(false, "+", Affirm)
1841 CYPrefix_(false, "-", Negate)
1842 CYPrefix_(false, "~", BitwiseNot)
1843 CYPrefix_(false, "!", LogicalNot)
1844
1845 CYInfix_(false, 5, "*", Multiply)
1846 CYInfix_(false, 5, "/", Divide)
1847 CYInfix_(false, 5, "%", Modulus)
1848 CYInfix_(false, 6, "+", Add, CYReplace)
1849 CYInfix_(false, 6, "-", Subtract)
1850 CYInfix_(false, 7, "<<", ShiftLeft)
1851 CYInfix_(false, 7, ">>", ShiftRightSigned)
1852 CYInfix_(false, 7, ">>>", ShiftRightUnsigned)
1853 CYInfix_(false, 8, "<", Less)
1854 CYInfix_(false, 8, ">", Greater)
1855 CYInfix_(false, 8, "<=", LessOrEqual)
1856 CYInfix_(false, 8, ">=", GreaterOrEqual)
1857 CYInfix_(true, 8, "instanceof", InstanceOf)
1858 CYInfix_(true, 8, "in", In)
1859 CYInfix_(false, 9, "==", Equal)
1860 CYInfix_(false, 9, "!=", NotEqual)
1861 CYInfix_(false, 9, "===", Identical)
1862 CYInfix_(false, 9, "!==", NotIdentical)
1863 CYInfix_(false, 10, "&", BitwiseAnd)
1864 CYInfix_(false, 11, "^", BitwiseXOr)
1865 CYInfix_(false, 12, "|", BitwiseOr)
1866 CYInfix_(false, 13, "&&", LogicalAnd)
1867 CYInfix_(false, 14, "||", LogicalOr)
1868
1869 CYAssignment_("=", )
1870 CYAssignment_("*=", Multiply)
1871 CYAssignment_("/=", Divide)
1872 CYAssignment_("%=", Modulus)
1873 CYAssignment_("+=", Add)
1874 CYAssignment_("-=", Subtract)
1875 CYAssignment_("<<=", ShiftLeft)
1876 CYAssignment_(">>=", ShiftRightSigned)
1877 CYAssignment_(">>>=", ShiftRightUnsigned)
1878 CYAssignment_("&=", BitwiseAnd)
1879 CYAssignment_("^=", BitwiseXOr)
1880 CYAssignment_("|=", BitwiseOr)
1881
1882 #endif/*CYPARSER_HPP*/