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