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