]> git.saurik.com Git - cycript.git/blob - Parser.hpp
ceb4b6fd25785a9e803bb4d9d6b3b166d1e2eed1
[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 apr_pool_t *pool_;
373 CYOptions &options_;
374
375 CYScope *scope_;
376 CYIdentifierUsageVector rename_;
377
378 CYNonLocal *nonlocal_;
379 CYNonLocal *nextlocal_;
380 unsigned unique_;
381
382 CYContext(apr_pool_t *pool, CYOptions &options) :
383 pool_(pool),
384 options_(options),
385 scope_(NULL),
386 nonlocal_(NULL),
387 nextlocal_(NULL),
388 unique_(0)
389 {
390 }
391
392 virtual ~CYContext() {
393 }
394
395 template <typename Type_>
396 void Replace(Type_ *&value) {
397 for (;;) if (value == NULL)
398 break;
399 else {
400 Type_ *replace(value->Replace(*this));
401 if (replace != value)
402 value = replace;
403 else break;
404 }
405 }
406
407 void NonLocal(CYStatement *&statements);
408 CYIdentifier *Unique();
409 };
410
411 struct CYNonLocal {
412 CYIdentifier *identifier_;
413
414 CYNonLocal() :
415 identifier_(NULL)
416 {
417 }
418
419 CYIdentifier *Target(CYContext &context) {
420 if (identifier_ == NULL)
421 identifier_ = context.Unique();
422 return identifier_;
423 }
424 };
425
426 struct CYBlock :
427 CYStatement,
428 CYThing
429 {
430 CYStatement *statements_;
431
432 CYBlock(CYStatement *statements) :
433 statements_(statements)
434 {
435 }
436
437 operator CYStatement *() const {
438 return statements_;
439 }
440
441 void AddPrev(CYStatement *statement) {
442 CYStatement *last(statement);
443 while (last->next_ != NULL)
444 last = last->next_;
445 last->SetNext(statements_);
446 statements_ = statement;
447 }
448
449 virtual CYStatement *Replace(CYContext &context);
450
451 virtual void Output(CYOutput &out) const;
452 virtual void Output(CYOutput &out, CYFlags flags) const;
453 };
454
455 enum CYState {
456 CYClear,
457 CYRestricted,
458 CYNewLine
459 };
460
461 class CYDriver {
462 public:
463 CYPool pool_;
464
465 CYState state_;
466 void *scanner_;
467
468 const char *data_;
469 size_t size_;
470 FILE *file_;
471
472 bool strict_;
473
474 enum Condition {
475 RegExpCondition,
476 XMLContentCondition,
477 XMLTagCondition,
478 };
479
480 std::string filename_;
481
482 struct Error {
483 bool warning_;
484 cy::location location_;
485 std::string message_;
486 };
487
488 typedef std::vector<Error> Errors;
489
490 CYProgram *program_;
491 Errors errors_;
492
493 bool auto_;
494
495 struct Context {
496 CYExpression *context_;
497
498 Context(CYExpression *context) :
499 context_(context)
500 {
501 }
502
503 typedef std::vector<CYWord *> Words;
504 Words words_;
505 };
506
507 typedef std::vector<Context> Contexts;
508 Contexts contexts_;
509
510 CYExpression *context_;
511
512 enum Mode {
513 AutoNone,
514 AutoPrimary,
515 AutoDirect,
516 AutoIndirect,
517 AutoMessage
518 } mode_;
519
520 private:
521 void ScannerInit();
522 void ScannerDestroy();
523
524 public:
525 CYDriver(apr_pool_t *pool = NULL, const std::string &filename = "");
526 ~CYDriver();
527
528 Condition GetCondition();
529 void SetCondition(Condition condition);
530
531 void PushCondition(Condition condition);
532 void PopCondition();
533
534 void Warning(const cy::location &location, const char *message);
535 };
536
537 struct CYForInitialiser {
538 virtual ~CYForInitialiser() {
539 }
540
541 virtual void For(CYOutput &out) const = 0;
542 virtual CYExpression *Replace(CYContext &context) = 0;
543 };
544
545 struct CYForInInitialiser {
546 virtual ~CYForInInitialiser() {
547 }
548
549 virtual void ForIn(CYOutput &out, CYFlags flags) const = 0;
550 virtual const char *ForEachIn() const = 0;
551 virtual CYExpression *ForEachIn(CYContext &out) = 0;
552 virtual CYExpression *Replace(CYContext &context) = 0;
553 };
554
555 struct CYNumber;
556 struct CYString;
557
558 struct CYExpression :
559 CYNext<CYExpression>,
560 CYForInitialiser,
561 CYForInInitialiser,
562 CYClassName,
563 CYThing
564 {
565 virtual unsigned Precedence() const = 0;
566
567 virtual bool RightHand() const {
568 return true;
569 }
570
571 virtual void For(CYOutput &out) const;
572 virtual void ForIn(CYOutput &out, CYFlags flags) const;
573
574 virtual const char *ForEachIn() const;
575 virtual CYExpression *ForEachIn(CYContext &out);
576
577 virtual CYExpression *AddArgument(CYContext &context, CYExpression *value);
578
579 virtual void Output(CYOutput &out) const;
580 virtual void Output(CYOutput &out, CYFlags flags) const = 0;
581 void Output(CYOutput &out, unsigned precedence, CYFlags flags) const;
582
583 virtual CYExpression *ClassName(CYContext &context, bool object);
584 virtual void ClassName(CYOutput &out, bool object) const;
585
586 CYExpression *ReplaceAll(CYContext &context);
587
588 virtual CYExpression *Replace(CYContext &context) = 0;
589
590 virtual CYExpression *Primitive(CYContext &context) {
591 return this;
592 }
593
594 virtual CYNumber *Number(CYContext &context) {
595 return NULL;
596 }
597
598 virtual CYString *String(CYContext &context) {
599 return NULL;
600 }
601
602 virtual const char *Word() const {
603 return NULL;
604 }
605 };
606
607 #define CYAlphabetic(value) \
608 virtual bool Alphabetic() const { \
609 return value; \
610 }
611
612 #define CYPrecedence(value) \
613 virtual unsigned Precedence() const { \
614 return value; \
615 }
616
617 #define CYRightHand(value) \
618 virtual bool RightHand() const { \
619 return value; \
620 }
621
622 struct CYCompound :
623 CYExpression
624 {
625 CYExpression *expressions_;
626
627 CYCompound(CYExpression *expressions = NULL) :
628 expressions_(expressions)
629 {
630 }
631
632 void AddPrev(CYExpression *expression) {
633 CYExpression *last(expression);
634 while (last->next_ != NULL)
635 last = last->next_;
636 last->SetNext(expressions_);
637 expressions_ = expression;
638 }
639
640 CYPrecedence(17)
641
642 virtual CYExpression *Replace(CYContext &context);
643 void Output(CYOutput &out, CYFlags flags) const;
644 };
645
646 struct CYFunctionParameter :
647 CYNext<CYFunctionParameter>,
648 CYThing
649 {
650 CYIdentifier *name_;
651
652 CYFunctionParameter(CYIdentifier *name, CYFunctionParameter *next = NULL) :
653 CYNext<CYFunctionParameter>(next),
654 name_(name)
655 {
656 }
657
658 virtual CYFunctionParameter *Replace(CYContext &context, CYBlock &code);
659 virtual void Output(CYOutput &out) const;
660 };
661
662 struct CYOptionalFunctionParameter :
663 CYFunctionParameter
664 {
665 CYExpression *initializer_;
666
667 CYOptionalFunctionParameter(CYIdentifier *name, CYExpression *initializer, CYFunctionParameter *next = NULL) :
668 CYFunctionParameter(name, next),
669 initializer_(initializer)
670 {
671 }
672
673 virtual CYFunctionParameter *Replace(CYContext &context, CYBlock &code);
674 virtual void Output(CYOutput &out) const;
675 };
676
677 struct CYComprehension :
678 CYNext<CYComprehension>,
679 CYThing
680 {
681 virtual const char *Name() const = 0;
682
683 virtual CYFunctionParameter *Parameter(CYContext &context) const = 0;
684 CYFunctionParameter *Parameters(CYContext &context) const;
685 virtual CYStatement *Replace(CYContext &context, CYStatement *statement) const;
686 virtual void Output(CYOutput &out) const = 0;
687 };
688
689 struct CYForInComprehension :
690 CYComprehension
691 {
692 CYIdentifier *name_;
693 CYExpression *set_;
694
695 CYForInComprehension(CYIdentifier *name, CYExpression *set) :
696 name_(name),
697 set_(set)
698 {
699 }
700
701 virtual const char *Name() const {
702 return name_->Word();
703 }
704
705 virtual CYFunctionParameter *Parameter(CYContext &context) const;
706 virtual CYStatement *Replace(CYContext &context, CYStatement *statement) const;
707 virtual void Output(CYOutput &out) const;
708 };
709
710 struct CYForEachInComprehension :
711 CYComprehension
712 {
713 CYIdentifier *name_;
714 CYExpression *set_;
715
716 CYForEachInComprehension(CYIdentifier *name, CYExpression *set) :
717 name_(name),
718 set_(set)
719 {
720 }
721
722 virtual const char *Name() const {
723 return name_->Word();
724 }
725
726 virtual CYFunctionParameter *Parameter(CYContext &context) const;
727 virtual CYStatement *Replace(CYContext &context, CYStatement *statement) const;
728 virtual void Output(CYOutput &out) const;
729 };
730
731 struct CYIfComprehension :
732 CYComprehension
733 {
734 CYExpression *test_;
735
736 CYIfComprehension(CYExpression *test) :
737 test_(test)
738 {
739 }
740
741 virtual const char *Name() const {
742 return NULL;
743 }
744
745 virtual CYFunctionParameter *Parameter(CYContext &context) const;
746 virtual CYStatement *Replace(CYContext &context, CYStatement *statement) const;
747 virtual void Output(CYOutput &out) const;
748 };
749
750 struct CYArrayComprehension :
751 CYExpression
752 {
753 CYExpression *expression_;
754 CYComprehension *comprehensions_;
755
756 CYArrayComprehension(CYExpression *expression, CYComprehension *comprehensions) :
757 expression_(expression),
758 comprehensions_(comprehensions)
759 {
760 }
761
762 CYPrecedence(0)
763
764 virtual CYExpression *Replace(CYContext &context);
765 virtual void Output(CYOutput &out, CYFlags flags) const;
766 };
767
768 struct CYLiteral :
769 CYExpression
770 {
771 CYPrecedence(0)
772 CYRightHand(false)
773 };
774
775 struct CYTrivial :
776 CYLiteral
777 {
778 virtual CYExpression *Replace(CYContext &context);
779 };
780
781 struct CYMagic :
782 CYExpression
783 {
784 CYPrecedence(0)
785 CYRightHand(false)
786 };
787
788 struct CYRange {
789 uint64_t lo_;
790 uint64_t hi_;
791
792 CYRange(uint64_t lo, uint64_t hi) :
793 lo_(lo), hi_(hi)
794 {
795 }
796
797 bool operator [](uint8_t value) const {
798 return !(value >> 7) && (value >> 6 ? hi_ : lo_) >> (value & 0x3f) & 0x1;
799 }
800
801 void operator()(uint8_t value) {
802 if (value >> 7)
803 return;
804 (value >> 6 ? hi_ : lo_) |= uint64_t(0x1) << (value & 0x3f);
805 }
806 };
807
808 extern CYRange DigitRange_;
809 extern CYRange WordStartRange_;
810 extern CYRange WordEndRange_;
811
812 struct CYString :
813 CYTrivial,
814 CYPropertyName
815 {
816 const char *value_;
817 size_t size_;
818
819 CYString() :
820 value_(NULL),
821 size_(0)
822 {
823 }
824
825 CYString(const char *value) :
826 value_(value),
827 size_(strlen(value))
828 {
829 }
830
831 CYString(const char *value, size_t size) :
832 value_(value),
833 size_(size)
834 {
835 }
836
837 CYString(const CYWord *word) :
838 value_(word->Word()),
839 size_(strlen(value_))
840 {
841 }
842
843 const char *Value() const {
844 return value_;
845 }
846
847 virtual const char *Word() const;
848
849 virtual CYNumber *Number(CYContext &context);
850 virtual CYString *String(CYContext &context);
851
852 CYString *Concat(CYContext &out, CYString *rhs) const;
853 virtual void Output(CYOutput &out, CYFlags flags) const;
854 virtual void PropertyName(CYOutput &out) const;
855 };
856
857 struct CYNumber :
858 CYTrivial,
859 CYPropertyName
860 {
861 double value_;
862
863 CYNumber(double value) :
864 value_(value)
865 {
866 }
867
868 double Value() const {
869 return value_;
870 }
871
872 virtual CYNumber *Number(CYContext &context);
873 virtual CYString *String(CYContext &context);
874
875 virtual void Output(CYOutput &out, CYFlags flags) const;
876 virtual void PropertyName(CYOutput &out) const;
877 };
878
879 struct CYRegEx :
880 CYTrivial
881 {
882 const char *value_;
883
884 CYRegEx(const char *value) :
885 value_(value)
886 {
887 }
888
889 const char *Value() const {
890 return value_;
891 }
892
893 virtual void Output(CYOutput &out, CYFlags flags) const;
894 };
895
896 struct CYNull :
897 CYWord,
898 CYTrivial
899 {
900 CYNull() :
901 CYWord("null")
902 {
903 }
904
905 virtual CYNumber *Number(CYContext &context);
906 virtual CYString *String(CYContext &context);
907
908 virtual void Output(CYOutput &out, CYFlags flags) const;
909 };
910
911 struct CYThis :
912 CYWord,
913 CYMagic
914 {
915 CYThis() :
916 CYWord("this")
917 {
918 }
919
920 virtual CYExpression *Replace(CYContext &context);
921 virtual void Output(CYOutput &out, CYFlags flags) const;
922 };
923
924 struct CYBoolean :
925 CYTrivial
926 {
927 virtual bool Value() const = 0;
928 virtual void Output(CYOutput &out, CYFlags flags) const;
929 };
930
931 struct CYFalse :
932 CYWord,
933 CYBoolean
934 {
935 CYFalse() :
936 CYWord("false")
937 {
938 }
939
940 virtual bool Value() const {
941 return false;
942 }
943
944 virtual CYNumber *Number(CYContext &context);
945 virtual CYString *String(CYContext &context);
946 };
947
948 struct CYTrue :
949 CYWord,
950 CYBoolean
951 {
952 CYTrue() :
953 CYWord("true")
954 {
955 }
956
957 virtual bool Value() const {
958 return true;
959 }
960
961 virtual CYNumber *Number(CYContext &context);
962 virtual CYString *String(CYContext &context);
963 };
964
965 struct CYVariable :
966 CYExpression
967 {
968 CYIdentifier *name_;
969
970 CYVariable(CYIdentifier *name) :
971 name_(name)
972 {
973 }
974
975 CYPrecedence(0)
976 CYRightHand(false)
977
978 virtual CYExpression *Replace(CYContext &context);
979 virtual void Output(CYOutput &out, CYFlags flags) const;
980 };
981
982 struct CYPrefix :
983 CYExpression
984 {
985 CYExpression *rhs_;
986
987 CYPrefix(CYExpression *rhs) :
988 rhs_(rhs)
989 {
990 }
991
992 virtual bool Alphabetic() const = 0;
993 virtual const char *Operator() const = 0;
994
995 CYPrecedence(4)
996
997 virtual CYExpression *Replace(CYContext &context);
998 virtual void Output(CYOutput &out, CYFlags flags) const;
999 };
1000
1001 struct CYInfix :
1002 CYExpression
1003 {
1004 CYExpression *lhs_;
1005 CYExpression *rhs_;
1006
1007 CYInfix(CYExpression *lhs, CYExpression *rhs) :
1008 lhs_(lhs),
1009 rhs_(rhs)
1010 {
1011 }
1012
1013 void SetLeft(CYExpression *lhs) {
1014 lhs_ = lhs;
1015 }
1016
1017 virtual bool Alphabetic() const = 0;
1018 virtual const char *Operator() const = 0;
1019
1020 virtual CYExpression *Replace(CYContext &context);
1021 virtual void Output(CYOutput &out, CYFlags flags) const;
1022 };
1023
1024 struct CYPostfix :
1025 CYExpression
1026 {
1027 CYExpression *lhs_;
1028
1029 CYPostfix(CYExpression *lhs) :
1030 lhs_(lhs)
1031 {
1032 }
1033
1034 virtual const char *Operator() const = 0;
1035
1036 CYPrecedence(3)
1037
1038 virtual CYExpression *Replace(CYContext &context);
1039 virtual void Output(CYOutput &out, CYFlags flags) const;
1040 };
1041
1042 struct CYAssignment :
1043 CYExpression
1044 {
1045 CYExpression *lhs_;
1046 CYExpression *rhs_;
1047
1048 CYAssignment(CYExpression *lhs, CYExpression *rhs) :
1049 lhs_(lhs),
1050 rhs_(rhs)
1051 {
1052 }
1053
1054 void SetLeft(CYExpression *lhs) {
1055 lhs_ = lhs;
1056 }
1057
1058 virtual const char *Operator() const = 0;
1059
1060 CYPrecedence(16)
1061
1062 virtual CYExpression *Replace(CYContext &context);
1063 virtual void Output(CYOutput &out, CYFlags flags) const;
1064 };
1065
1066 struct CYArgument :
1067 CYNext<CYArgument>,
1068 CYThing
1069 {
1070 CYWord *name_;
1071 CYExpression *value_;
1072
1073 CYArgument(CYExpression *value, CYArgument *next = NULL) :
1074 CYNext<CYArgument>(next),
1075 name_(NULL),
1076 value_(value)
1077 {
1078 }
1079
1080 CYArgument(CYWord *name, CYExpression *value, CYArgument *next = NULL) :
1081 CYNext<CYArgument>(next),
1082 name_(name),
1083 value_(value)
1084 {
1085 }
1086
1087 void Replace(CYContext &context);
1088 void Output(CYOutput &out) const;
1089 };
1090
1091 struct CYBlank :
1092 public CYWord
1093 {
1094 CYBlank() :
1095 CYWord("")
1096 {
1097 }
1098 };
1099
1100 struct CYClause :
1101 CYThing,
1102 CYNext<CYClause>
1103 {
1104 CYExpression *case_;
1105 CYStatement *statements_;
1106
1107 CYClause(CYExpression *_case, CYStatement *statements) :
1108 case_(_case),
1109 statements_(statements)
1110 {
1111 }
1112
1113 void Replace(CYContext &context);
1114 virtual void Output(CYOutput &out) const;
1115 };
1116
1117 struct CYElement :
1118 CYNext<CYElement>,
1119 CYThing
1120 {
1121 CYExpression *value_;
1122
1123 CYElement(CYExpression *value, CYElement *next) :
1124 CYNext<CYElement>(next),
1125 value_(value)
1126 {
1127 }
1128
1129 void Replace(CYContext &context);
1130 void Output(CYOutput &out) const;
1131 };
1132
1133 struct CYArray :
1134 CYLiteral
1135 {
1136 CYElement *elements_;
1137
1138 CYArray(CYElement *elements = NULL) :
1139 elements_(elements)
1140 {
1141 }
1142
1143 virtual CYExpression *Replace(CYContext &context);
1144 virtual void Output(CYOutput &out, CYFlags flags) const;
1145 };
1146
1147 struct CYProperty :
1148 CYNext<CYProperty>,
1149 CYThing
1150 {
1151 CYPropertyName *name_;
1152 CYExpression *value_;
1153
1154 CYProperty(CYPropertyName *name, CYExpression *value, CYProperty *next = NULL) :
1155 CYNext<CYProperty>(next),
1156 name_(name),
1157 value_(value)
1158 {
1159 }
1160
1161 void Replace(CYContext &context);
1162 virtual void Output(CYOutput &out) const;
1163 };
1164
1165 struct CYDeclaration :
1166 CYForInInitialiser
1167 {
1168 CYIdentifier *identifier_;
1169 CYExpression *initialiser_;
1170
1171 CYDeclaration(CYIdentifier *identifier, CYExpression *initialiser = NULL) :
1172 identifier_(identifier),
1173 initialiser_(initialiser)
1174 {
1175 }
1176
1177 virtual void ForIn(CYOutput &out, CYFlags flags) const;
1178
1179 virtual const char *ForEachIn() const;
1180 virtual CYExpression *ForEachIn(CYContext &out);
1181
1182 virtual CYExpression *Replace(CYContext &context);
1183 virtual CYAssignment *Assignment(CYContext &context);
1184
1185 virtual void Output(CYOutput &out, CYFlags flags) const;
1186 };
1187
1188 struct CYDeclarations :
1189 CYNext<CYDeclarations>,
1190 CYThing,
1191 CYForInitialiser
1192 {
1193 CYDeclaration *declaration_;
1194
1195 CYDeclarations(CYDeclaration *declaration, CYDeclarations *next = NULL) :
1196 CYNext<CYDeclarations>(next),
1197 declaration_(declaration)
1198 {
1199 }
1200
1201 virtual void For(CYOutput &out) const;
1202
1203 virtual CYCompound *Replace(CYContext &context);
1204 CYProperty *Property(CYContext &context);
1205
1206 virtual void Output(CYOutput &out) const;
1207 virtual void Output(CYOutput &out, CYFlags flags) const;
1208 };
1209
1210 struct CYVar :
1211 CYStatement
1212 {
1213 CYDeclarations *declarations_;
1214
1215 CYVar(CYDeclarations *declarations) :
1216 declarations_(declarations)
1217 {
1218 }
1219
1220 virtual CYStatement *Replace(CYContext &context);
1221 virtual void Output(CYOutput &out, CYFlags flags) const;
1222 };
1223
1224 struct CYLet :
1225 CYStatement
1226 {
1227 CYDeclarations *declarations_;
1228 CYBlock code_;
1229
1230 CYLet(CYDeclarations *declarations, CYStatement *statements) :
1231 declarations_(declarations),
1232 code_(statements)
1233 {
1234 }
1235
1236 virtual CYStatement *Replace(CYContext &context);
1237 virtual void Output(CYOutput &out, CYFlags flags) const;
1238 };
1239
1240 struct CYFor :
1241 CYStatement
1242 {
1243 CYForInitialiser *initialiser_;
1244 CYExpression *test_;
1245 CYExpression *increment_;
1246 CYStatement *code_;
1247
1248 CYFor(CYForInitialiser *initialiser, CYExpression *test, CYExpression *increment, CYStatement *code) :
1249 initialiser_(initialiser),
1250 test_(test),
1251 increment_(increment),
1252 code_(code)
1253 {
1254 }
1255
1256 virtual CYStatement *Replace(CYContext &context);
1257 virtual void Output(CYOutput &out, CYFlags flags) const;
1258 };
1259
1260 struct CYForIn :
1261 CYStatement
1262 {
1263 CYForInInitialiser *initialiser_;
1264 CYExpression *set_;
1265 CYStatement *code_;
1266
1267 CYForIn(CYForInInitialiser *initialiser, CYExpression *set, CYStatement *code) :
1268 initialiser_(initialiser),
1269 set_(set),
1270 code_(code)
1271 {
1272 }
1273
1274 virtual CYStatement *Replace(CYContext &context);
1275 virtual void Output(CYOutput &out, CYFlags flags) const;
1276 };
1277
1278 struct CYForEachIn :
1279 CYStatement
1280 {
1281 CYForInInitialiser *initialiser_;
1282 CYExpression *set_;
1283 CYStatement *code_;
1284
1285 CYForEachIn(CYForInInitialiser *initialiser, CYExpression *set, CYStatement *code) :
1286 initialiser_(initialiser),
1287 set_(set),
1288 code_(code)
1289 {
1290 }
1291
1292 virtual CYStatement *Replace(CYContext &context);
1293 virtual void Output(CYOutput &out, CYFlags flags) const;
1294 };
1295
1296 struct CYObject :
1297 CYLiteral
1298 {
1299 CYProperty *properties_;
1300
1301 CYObject(CYProperty *properties = NULL) :
1302 properties_(properties)
1303 {
1304 }
1305
1306 virtual CYExpression *Replace(CYContext &context);
1307 void Output(CYOutput &out, CYFlags flags) const;
1308 };
1309
1310 struct CYMember :
1311 CYExpression
1312 {
1313 CYExpression *object_;
1314 CYExpression *property_;
1315
1316 CYMember(CYExpression *object, CYExpression *property) :
1317 object_(object),
1318 property_(property)
1319 {
1320 }
1321
1322 void SetLeft(CYExpression *object) {
1323 object_ = object;
1324 }
1325
1326 void Replace_(CYContext &context);
1327 };
1328
1329 struct CYDirectMember :
1330 CYMember
1331 {
1332 CYDirectMember(CYExpression *object, CYExpression *property) :
1333 CYMember(object, property)
1334 {
1335 }
1336
1337 CYPrecedence(1)
1338 CYRightHand(false)
1339
1340 virtual CYExpression *Replace(CYContext &context);
1341 virtual void Output(CYOutput &out, CYFlags flags) const;
1342 };
1343
1344 struct CYIndirectMember :
1345 CYMember
1346 {
1347 CYIndirectMember(CYExpression *object, CYExpression *property) :
1348 CYMember(object, property)
1349 {
1350 }
1351
1352 CYPrecedence(1)
1353 CYRightHand(false)
1354
1355 virtual CYExpression *Replace(CYContext &context);
1356 virtual void Output(CYOutput &out, CYFlags flags) const;
1357 };
1358
1359 struct CYNew :
1360 CYExpression
1361 {
1362 CYExpression *constructor_;
1363 CYArgument *arguments_;
1364
1365 CYNew(CYExpression *constructor, CYArgument *arguments) :
1366 constructor_(constructor),
1367 arguments_(arguments)
1368 {
1369 }
1370
1371 virtual unsigned Precedence() const {
1372 return arguments_ == NULL ? 2 : 1;
1373 }
1374
1375 CYRightHand(false)
1376
1377 virtual CYExpression *Replace(CYContext &context);
1378 virtual void Output(CYOutput &out, CYFlags flags) const;
1379
1380 virtual CYExpression *AddArgument(CYContext &context, CYExpression *value);
1381 };
1382
1383 struct CYCall :
1384 CYExpression
1385 {
1386 CYExpression *function_;
1387 CYArgument *arguments_;
1388
1389 CYCall(CYExpression *function, CYArgument *arguments = NULL) :
1390 function_(function),
1391 arguments_(arguments)
1392 {
1393 }
1394
1395 CYPrecedence(1)
1396 CYRightHand(false)
1397
1398 virtual CYExpression *Replace(CYContext &context);
1399 virtual void Output(CYOutput &out, CYFlags flags) const;
1400
1401 virtual CYExpression *AddArgument(CYContext &context, CYExpression *value);
1402 };
1403
1404 struct CYRubyProc;
1405
1406 struct CYRubyBlock :
1407 CYExpression
1408 {
1409 CYExpression *call_;
1410 CYRubyProc *proc_;
1411
1412 CYRubyBlock(CYExpression *call, CYRubyProc *proc) :
1413 call_(call),
1414 proc_(proc)
1415 {
1416 }
1417
1418 CYPrecedence(1)
1419 CYRightHand(false)
1420
1421 virtual CYExpression *Replace(CYContext &context);
1422 virtual void Output(CYOutput &out, CYFlags flags) const;
1423 };
1424
1425 struct CYIf :
1426 CYStatement
1427 {
1428 CYExpression *test_;
1429 CYStatement *true_;
1430 CYStatement *false_;
1431
1432 CYIf(CYExpression *test, CYStatement *_true, CYStatement *_false = NULL) :
1433 test_(test),
1434 true_(_true),
1435 false_(_false)
1436 {
1437 }
1438
1439 virtual CYStatement *Replace(CYContext &context);
1440 virtual void Output(CYOutput &out, CYFlags flags) const;
1441 };
1442
1443 struct CYDoWhile :
1444 CYStatement
1445 {
1446 CYExpression *test_;
1447 CYStatement *code_;
1448
1449 CYDoWhile(CYExpression *test, CYStatement *code) :
1450 test_(test),
1451 code_(code)
1452 {
1453 }
1454
1455 virtual CYStatement *Replace(CYContext &context);
1456 virtual void Output(CYOutput &out, CYFlags flags) const;
1457 };
1458
1459 struct CYWhile :
1460 CYStatement
1461 {
1462 CYExpression *test_;
1463 CYStatement *code_;
1464
1465 CYWhile(CYExpression *test, CYStatement *code) :
1466 test_(test),
1467 code_(code)
1468 {
1469 }
1470
1471 virtual CYStatement *Replace(CYContext &context);
1472 virtual void Output(CYOutput &out, CYFlags flags) const;
1473 };
1474
1475 // XXX: this should be split up into CYAnonymousFunction and CYNamedFunction (subclass)
1476 struct CYFunction {
1477 CYIdentifier *name_;
1478 CYFunctionParameter *parameters_;
1479 CYBlock code_;
1480 CYNonLocal *nonlocal_;
1481
1482 CYFunction(CYIdentifier *name, CYFunctionParameter *parameters, CYStatement *statements) :
1483 name_(name),
1484 parameters_(parameters),
1485 code_(statements),
1486 nonlocal_(NULL)
1487 {
1488 }
1489
1490 virtual ~CYFunction() {
1491 }
1492
1493 void Inject(CYContext &context);
1494 virtual void Replace_(CYContext &context, bool outer);
1495 virtual void Output(CYOutput &out, CYFlags flags) const;
1496 };
1497
1498 // XXX: this should be split up into CYAnonymousFunctionExpression and CYNamedFunctionExpression
1499 struct CYFunctionExpression :
1500 CYFunction,
1501 CYExpression
1502 {
1503 CYFunctionExpression(CYIdentifier *name, CYFunctionParameter *parameters, CYStatement *statements) :
1504 CYFunction(name, parameters, statements)
1505 {
1506 }
1507
1508 CYPrecedence(0)
1509 CYRightHand(false)
1510
1511 virtual CYExpression *Replace(CYContext &context);
1512 virtual void Output(CYOutput &out, CYFlags flags) const;
1513 };
1514
1515 // XXX: this should derive from CYAnonymousFunctionExpression
1516 struct CYRubyProc :
1517 CYFunctionExpression
1518 {
1519 CYRubyProc(CYFunctionParameter *parameters, CYStatement *statements) :
1520 CYFunctionExpression(NULL, parameters, statements)
1521 {
1522 }
1523
1524 virtual CYExpression *Replace(CYContext &context);
1525 virtual void Output(CYOutput &out, CYFlags flags) const;
1526 };
1527
1528 // XXX: this should derive from CYNamedFunction
1529 struct CYFunctionStatement :
1530 CYFunction,
1531 CYStatement
1532 {
1533 CYFunctionStatement(CYIdentifier *name, CYFunctionParameter *parameters, CYStatement *statements) :
1534 CYFunction(name, parameters, statements)
1535 {
1536 }
1537
1538 virtual CYStatement *Replace(CYContext &context);
1539 virtual void Output(CYOutput &out, CYFlags flags) const;
1540 };
1541
1542 struct CYExpress :
1543 CYStatement
1544 {
1545 CYExpression *expression_;
1546
1547 CYExpress(CYExpression *expression) :
1548 expression_(expression)
1549 {
1550 if (expression == NULL)
1551 throw;
1552 }
1553
1554 virtual CYStatement *Collapse(CYContext &context);
1555 virtual CYStatement *Replace(CYContext &context);
1556 virtual void Output(CYOutput &out, CYFlags flags) const;
1557 };
1558
1559 struct CYContinue :
1560 CYStatement
1561 {
1562 CYIdentifier *label_;
1563
1564 CYContinue(CYIdentifier *label) :
1565 label_(label)
1566 {
1567 }
1568
1569 virtual CYStatement *Replace(CYContext &context);
1570 virtual void Output(CYOutput &out, CYFlags flags) const;
1571 };
1572
1573 struct CYBreak :
1574 CYStatement
1575 {
1576 CYIdentifier *label_;
1577
1578 CYBreak(CYIdentifier *label) :
1579 label_(label)
1580 {
1581 }
1582
1583 virtual CYStatement *Replace(CYContext &context);
1584 virtual void Output(CYOutput &out, CYFlags flags) const;
1585 };
1586
1587 struct CYReturn :
1588 CYStatement
1589 {
1590 CYExpression *value_;
1591
1592 CYReturn(CYExpression *value) :
1593 value_(value)
1594 {
1595 }
1596
1597 virtual CYStatement *Replace(CYContext &context);
1598 virtual void Output(CYOutput &out, CYFlags flags) const;
1599 };
1600
1601 struct CYEmpty :
1602 CYStatement
1603 {
1604 virtual CYStatement *Collapse(CYContext &context);
1605 virtual CYStatement *Replace(CYContext &context);
1606 virtual void Output(CYOutput &out, CYFlags flags) const;
1607 };
1608
1609 struct CYFinally :
1610 CYThing
1611 {
1612 CYBlock code_;
1613
1614 CYFinally(CYStatement *statements) :
1615 code_(statements)
1616 {
1617 }
1618
1619 void Replace(CYContext &context);
1620 virtual void Output(CYOutput &out) const;
1621 };
1622
1623 namespace cy {
1624 namespace Syntax {
1625
1626 struct Catch :
1627 CYThing
1628 {
1629 CYIdentifier *name_;
1630 CYBlock code_;
1631
1632 Catch(CYIdentifier *name, CYStatement *statements) :
1633 name_(name),
1634 code_(statements)
1635 {
1636 }
1637
1638 void Replace(CYContext &context);
1639 virtual void Output(CYOutput &out) const;
1640 };
1641
1642 struct Try :
1643 CYStatement
1644 {
1645 CYBlock code_;
1646 Catch *catch_;
1647 CYFinally *finally_;
1648
1649 Try(CYStatement *statements, Catch *_catch, CYFinally *finally) :
1650 code_(statements),
1651 catch_(_catch),
1652 finally_(finally)
1653 {
1654 }
1655
1656 virtual CYStatement *Replace(CYContext &context);
1657 virtual void Output(CYOutput &out, CYFlags flags) const;
1658 };
1659
1660 struct Throw :
1661 CYStatement
1662 {
1663 CYExpression *value_;
1664
1665 Throw(CYExpression *value = NULL) :
1666 value_(value)
1667 {
1668 }
1669
1670 virtual CYStatement *Replace(CYContext &context);
1671 virtual void Output(CYOutput &out, CYFlags flags) const;
1672 };
1673
1674 } }
1675
1676 struct CYWith :
1677 CYStatement
1678 {
1679 CYExpression *scope_;
1680 CYStatement *code_;
1681
1682 CYWith(CYExpression *scope, CYStatement *code) :
1683 scope_(scope),
1684 code_(code)
1685 {
1686 }
1687
1688 virtual CYStatement *Replace(CYContext &context);
1689 virtual void Output(CYOutput &out, CYFlags flags) const;
1690 };
1691
1692 struct CYSwitch :
1693 CYStatement
1694 {
1695 CYExpression *value_;
1696 CYClause *clauses_;
1697
1698 CYSwitch(CYExpression *value, CYClause *clauses) :
1699 value_(value),
1700 clauses_(clauses)
1701 {
1702 }
1703
1704 virtual CYStatement *Replace(CYContext &context);
1705 virtual void Output(CYOutput &out, CYFlags flags) const;
1706 };
1707
1708 struct CYCondition :
1709 CYExpression
1710 {
1711 CYExpression *test_;
1712 CYExpression *true_;
1713 CYExpression *false_;
1714
1715 CYCondition(CYExpression *test, CYExpression *_true, CYExpression *_false) :
1716 test_(test),
1717 true_(_true),
1718 false_(_false)
1719 {
1720 }
1721
1722 CYPrecedence(15)
1723
1724 virtual CYExpression *Replace(CYContext &context);
1725 virtual void Output(CYOutput &out, CYFlags flags) const;
1726 };
1727
1728 struct CYAddressOf :
1729 CYPrefix
1730 {
1731 CYAddressOf(CYExpression *rhs) :
1732 CYPrefix(rhs)
1733 {
1734 }
1735
1736 virtual const char *Operator() const {
1737 return "&";
1738 }
1739
1740 CYAlphabetic(false)
1741
1742 virtual CYExpression *Replace(CYContext &context);
1743 };
1744
1745 struct CYIndirect :
1746 CYPrefix
1747 {
1748 CYIndirect(CYExpression *rhs) :
1749 CYPrefix(rhs)
1750 {
1751 }
1752
1753 virtual const char *Operator() const {
1754 return "*";
1755 }
1756
1757 CYAlphabetic(false)
1758
1759 virtual CYExpression *Replace(CYContext &context);
1760 };
1761
1762 #define CYReplace \
1763 virtual CYExpression *Replace(CYContext &context);
1764
1765 #define CYPostfix_(op, name, args...) \
1766 struct CY ## name : \
1767 CYPostfix \
1768 { args \
1769 CY ## name(CYExpression *lhs) : \
1770 CYPostfix(lhs) \
1771 { \
1772 } \
1773 \
1774 virtual const char *Operator() const { \
1775 return op; \
1776 } \
1777 };
1778
1779 #define CYPrefix_(alphabetic, op, name, args...) \
1780 struct CY ## name : \
1781 CYPrefix \
1782 { args \
1783 CY ## name(CYExpression *rhs) : \
1784 CYPrefix(rhs) \
1785 { \
1786 } \
1787 \
1788 CYAlphabetic(alphabetic) \
1789 \
1790 virtual const char *Operator() const { \
1791 return op; \
1792 } \
1793 };
1794
1795 #define CYInfix_(alphabetic, precedence, op, name, args...) \
1796 struct CY ## name : \
1797 CYInfix \
1798 { args \
1799 CY ## name(CYExpression *lhs, CYExpression *rhs) : \
1800 CYInfix(lhs, rhs) \
1801 { \
1802 } \
1803 \
1804 CYAlphabetic(alphabetic) \
1805 CYPrecedence(precedence) \
1806 \
1807 virtual const char *Operator() const { \
1808 return op; \
1809 } \
1810 };
1811
1812 #define CYAssignment_(op, name, args...) \
1813 struct CY ## name ## Assign : \
1814 CYAssignment \
1815 { args \
1816 CY ## name ## Assign(CYExpression *lhs, CYExpression *rhs) : \
1817 CYAssignment(lhs, rhs) \
1818 { \
1819 } \
1820 \
1821 virtual const char *Operator() const { \
1822 return op; \
1823 } \
1824 };
1825
1826 CYPostfix_("++", PostIncrement)
1827 CYPostfix_("--", PostDecrement)
1828
1829 CYPrefix_(true, "delete", Delete)
1830 CYPrefix_(true, "void", Void)
1831 CYPrefix_(true, "typeof", TypeOf)
1832 CYPrefix_(false, "++", PreIncrement)
1833 CYPrefix_(false, "--", PreDecrement)
1834 CYPrefix_(false, "+", Affirm)
1835 CYPrefix_(false, "-", Negate)
1836 CYPrefix_(false, "~", BitwiseNot)
1837 CYPrefix_(false, "!", LogicalNot)
1838
1839 CYInfix_(false, 5, "*", Multiply)
1840 CYInfix_(false, 5, "/", Divide)
1841 CYInfix_(false, 5, "%", Modulus)
1842 CYInfix_(false, 6, "+", Add, CYReplace)
1843 CYInfix_(false, 6, "-", Subtract)
1844 CYInfix_(false, 7, "<<", ShiftLeft)
1845 CYInfix_(false, 7, ">>", ShiftRightSigned)
1846 CYInfix_(false, 7, ">>>", ShiftRightUnsigned)
1847 CYInfix_(false, 8, "<", Less)
1848 CYInfix_(false, 8, ">", Greater)
1849 CYInfix_(false, 8, "<=", LessOrEqual)
1850 CYInfix_(false, 8, ">=", GreaterOrEqual)
1851 CYInfix_(true, 8, "instanceof", InstanceOf)
1852 CYInfix_(true, 8, "in", In)
1853 CYInfix_(false, 9, "==", Equal)
1854 CYInfix_(false, 9, "!=", NotEqual)
1855 CYInfix_(false, 9, "===", Identical)
1856 CYInfix_(false, 9, "!==", NotIdentical)
1857 CYInfix_(false, 10, "&", BitwiseAnd)
1858 CYInfix_(false, 11, "^", BitwiseXOr)
1859 CYInfix_(false, 12, "|", BitwiseOr)
1860 CYInfix_(false, 13, "&&", LogicalAnd)
1861 CYInfix_(false, 14, "||", LogicalOr)
1862
1863 CYAssignment_("=", )
1864 CYAssignment_("*=", Multiply)
1865 CYAssignment_("/=", Divide)
1866 CYAssignment_("%=", Modulus)
1867 CYAssignment_("+=", Add)
1868 CYAssignment_("-=", Subtract)
1869 CYAssignment_("<<=", ShiftLeft)
1870 CYAssignment_(">>=", ShiftRightSigned)
1871 CYAssignment_(">>>=", ShiftRightUnsigned)
1872 CYAssignment_("&=", BitwiseAnd)
1873 CYAssignment_("^=", BitwiseXOr)
1874 CYAssignment_("|=", BitwiseOr)
1875
1876 #endif/*CYPARSER_HPP*/