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