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