]> git.saurik.com Git - cycript.git/blob - Parser.hpp
a5d11488f110527f69778d6a186b839763981841
[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 virtual void Output(CYOutput &out, CYFlags flags) const = 0;
541 };
542
543 struct CYNumber;
544 struct CYString;
545
546 struct CYExpression :
547 CYNext<CYExpression>,
548 CYForInitialiser,
549 CYForInInitialiser,
550 CYClassName,
551 CYThing
552 {
553 virtual unsigned Precedence() const = 0;
554
555 virtual bool RightHand() const {
556 return true;
557 }
558
559 virtual void ForIn(CYOutput &out, CYFlags flags) const;
560 virtual CYStatement *ForEachIn(CYContext &out, CYExpression *value);
561
562 virtual CYExpression *AddArgument(CYContext &context, CYExpression *value);
563
564 virtual void Output(CYOutput &out) const;
565 virtual void Output(CYOutput &out, CYFlags flags) const = 0;
566 void Output(CYOutput &out, unsigned precedence, CYFlags flags) const;
567
568 virtual CYExpression *ClassName(CYContext &context, bool object);
569 virtual void ClassName(CYOutput &out, bool object) const;
570
571 virtual CYExpression *Replace(CYContext &context) = 0;
572 virtual CYAssignment *Assignment(CYContext &context);
573
574 virtual CYExpression *Primitive(CYContext &context) {
575 return this;
576 }
577
578 virtual CYNumber *Number(CYContext &context) {
579 return NULL;
580 }
581
582 virtual CYString *String(CYContext &context) {
583 return NULL;
584 }
585
586 virtual const char *Word() const {
587 return NULL;
588 }
589 };
590
591 #define CYAlphabetic(value) \
592 virtual bool Alphabetic() const { \
593 return value; \
594 }
595
596 #define CYPrecedence(value) \
597 static const unsigned Precedence_ = value; \
598 virtual unsigned Precedence() const { \
599 return Precedence_; \
600 }
601
602 #define CYRightHand(value) \
603 virtual bool RightHand() const { \
604 return value; \
605 }
606
607 struct CYCompound :
608 CYExpression
609 {
610 CYExpression *expressions_;
611
612 CYCompound(CYExpression *expressions = NULL) :
613 expressions_(expressions)
614 {
615 }
616
617 void AddPrev(CYExpression *expression) {
618 CYSetLast(expression, expressions_);
619 expressions_ = expression;
620 }
621
622 CYPrecedence(17)
623
624 virtual CYExpression *Replace(CYContext &context);
625 void Output(CYOutput &out, CYFlags flags) const;
626 };
627
628 struct CYDeclaration;
629
630 struct CYFunctionParameter :
631 CYNext<CYFunctionParameter>,
632 CYThing
633 {
634 CYForInInitialiser *initialiser_;
635
636 CYFunctionParameter(CYForInInitialiser *initialiser, CYFunctionParameter *next = NULL) :
637 CYNext<CYFunctionParameter>(next),
638 initialiser_(initialiser)
639 {
640 }
641
642 void Replace(CYContext &context, CYBlock &code);
643 void Output(CYOutput &out) const;
644 };
645
646 struct CYComprehension :
647 CYNext<CYComprehension>,
648 CYThing
649 {
650 virtual const char *Name() const = 0;
651
652 virtual CYFunctionParameter *Parameter(CYContext &context) const = 0;
653 CYFunctionParameter *Parameters(CYContext &context) const;
654 virtual CYStatement *Replace(CYContext &context, CYStatement *statement) const;
655 virtual void Output(CYOutput &out) const = 0;
656 };
657
658 struct CYForInComprehension :
659 CYComprehension
660 {
661 CYIdentifier *name_;
662 CYExpression *set_;
663
664 CYForInComprehension(CYIdentifier *name, CYExpression *set) :
665 name_(name),
666 set_(set)
667 {
668 }
669
670 virtual const char *Name() const {
671 return name_->Word();
672 }
673
674 virtual CYFunctionParameter *Parameter(CYContext &context) const;
675 virtual CYStatement *Replace(CYContext &context, CYStatement *statement) const;
676 virtual void Output(CYOutput &out) const;
677 };
678
679 struct CYForEachInComprehension :
680 CYComprehension
681 {
682 CYIdentifier *name_;
683 CYExpression *set_;
684
685 CYForEachInComprehension(CYIdentifier *name, CYExpression *set) :
686 name_(name),
687 set_(set)
688 {
689 }
690
691 virtual const char *Name() const {
692 return name_->Word();
693 }
694
695 virtual CYFunctionParameter *Parameter(CYContext &context) const;
696 virtual CYStatement *Replace(CYContext &context, CYStatement *statement) const;
697 virtual void Output(CYOutput &out) const;
698 };
699
700 struct CYIfComprehension :
701 CYComprehension
702 {
703 CYExpression *test_;
704
705 CYIfComprehension(CYExpression *test) :
706 test_(test)
707 {
708 }
709
710 virtual const char *Name() const {
711 return NULL;
712 }
713
714 virtual CYFunctionParameter *Parameter(CYContext &context) const;
715 virtual CYStatement *Replace(CYContext &context, CYStatement *statement) const;
716 virtual void Output(CYOutput &out) const;
717 };
718
719 struct CYArrayComprehension :
720 CYExpression
721 {
722 CYExpression *expression_;
723 CYComprehension *comprehensions_;
724
725 CYArrayComprehension(CYExpression *expression, CYComprehension *comprehensions) :
726 expression_(expression),
727 comprehensions_(comprehensions)
728 {
729 }
730
731 CYPrecedence(0)
732
733 virtual CYExpression *Replace(CYContext &context);
734 virtual void Output(CYOutput &out, CYFlags flags) const;
735 };
736
737 struct CYLiteral :
738 CYExpression
739 {
740 CYPrecedence(0)
741 CYRightHand(false)
742 };
743
744 struct CYTrivial :
745 CYLiteral
746 {
747 virtual CYExpression *Replace(CYContext &context);
748 };
749
750 struct CYMagic :
751 CYExpression
752 {
753 CYPrecedence(0)
754 CYRightHand(false)
755 };
756
757 struct CYRange {
758 uint64_t lo_;
759 uint64_t hi_;
760
761 CYRange(uint64_t lo, uint64_t hi) :
762 lo_(lo), hi_(hi)
763 {
764 }
765
766 bool operator [](uint8_t value) const {
767 return !(value >> 7) && (value >> 6 ? hi_ : lo_) >> (value & 0x3f) & 0x1;
768 }
769
770 void operator()(uint8_t value) {
771 if (value >> 7)
772 return;
773 (value >> 6 ? hi_ : lo_) |= uint64_t(0x1) << (value & 0x3f);
774 }
775 };
776
777 extern CYRange DigitRange_;
778 extern CYRange WordStartRange_;
779 extern CYRange WordEndRange_;
780
781 struct CYString :
782 CYTrivial,
783 CYPropertyName
784 {
785 const char *value_;
786 size_t size_;
787
788 CYString() :
789 value_(NULL),
790 size_(0)
791 {
792 }
793
794 CYString(const char *value) :
795 value_(value),
796 size_(strlen(value))
797 {
798 }
799
800 CYString(const char *value, size_t size) :
801 value_(value),
802 size_(size)
803 {
804 }
805
806 CYString(const CYWord *word) :
807 value_(word->Word()),
808 size_(strlen(value_))
809 {
810 }
811
812 const char *Value() const {
813 return value_;
814 }
815
816 virtual const char *Word() const;
817
818 virtual CYNumber *Number(CYContext &context);
819 virtual CYString *String(CYContext &context);
820
821 CYString *Concat(CYContext &out, CYString *rhs) const;
822 virtual void Output(CYOutput &out, CYFlags flags) const;
823 virtual void PropertyName(CYOutput &out) const;
824 };
825
826 struct CYNumber :
827 CYTrivial,
828 CYPropertyName
829 {
830 double value_;
831
832 CYNumber(double value) :
833 value_(value)
834 {
835 }
836
837 double Value() const {
838 return value_;
839 }
840
841 virtual CYNumber *Number(CYContext &context);
842 virtual CYString *String(CYContext &context);
843
844 virtual void Output(CYOutput &out, CYFlags flags) const;
845 virtual void PropertyName(CYOutput &out) const;
846 };
847
848 struct CYRegEx :
849 CYTrivial
850 {
851 const char *value_;
852
853 CYRegEx(const char *value) :
854 value_(value)
855 {
856 }
857
858 const char *Value() const {
859 return value_;
860 }
861
862 virtual void Output(CYOutput &out, CYFlags flags) const;
863 };
864
865 struct CYNull :
866 CYWord,
867 CYTrivial
868 {
869 CYNull() :
870 CYWord("null")
871 {
872 }
873
874 virtual CYNumber *Number(CYContext &context);
875 virtual CYString *String(CYContext &context);
876
877 virtual void Output(CYOutput &out, CYFlags flags) const;
878 };
879
880 struct CYThis :
881 CYWord,
882 CYMagic
883 {
884 CYThis() :
885 CYWord("this")
886 {
887 }
888
889 virtual CYExpression *Replace(CYContext &context);
890 virtual void Output(CYOutput &out, CYFlags flags) const;
891 };
892
893 struct CYBoolean :
894 CYTrivial
895 {
896 virtual bool Value() const = 0;
897 virtual void Output(CYOutput &out, CYFlags flags) const;
898 };
899
900 struct CYFalse :
901 CYWord,
902 CYBoolean
903 {
904 CYFalse() :
905 CYWord("false")
906 {
907 }
908
909 virtual bool Value() const {
910 return false;
911 }
912
913 virtual CYNumber *Number(CYContext &context);
914 virtual CYString *String(CYContext &context);
915 };
916
917 struct CYTrue :
918 CYWord,
919 CYBoolean
920 {
921 CYTrue() :
922 CYWord("true")
923 {
924 }
925
926 virtual bool Value() const {
927 return true;
928 }
929
930 virtual CYNumber *Number(CYContext &context);
931 virtual CYString *String(CYContext &context);
932 };
933
934 struct CYVariable :
935 CYExpression
936 {
937 CYIdentifier *name_;
938
939 CYVariable(CYIdentifier *name) :
940 name_(name)
941 {
942 }
943
944 CYVariable(const char *name) :
945 name_(new($pool) CYIdentifier(name))
946 {
947 }
948
949 CYPrecedence(0)
950 CYRightHand(false)
951
952 virtual CYExpression *Replace(CYContext &context);
953 virtual void Output(CYOutput &out, CYFlags flags) const;
954 };
955
956 struct CYPrefix :
957 CYExpression
958 {
959 CYExpression *rhs_;
960
961 CYPrefix(CYExpression *rhs) :
962 rhs_(rhs)
963 {
964 }
965
966 virtual bool Alphabetic() const = 0;
967 virtual const char *Operator() const = 0;
968
969 CYPrecedence(4)
970
971 virtual CYExpression *Replace(CYContext &context);
972 virtual void Output(CYOutput &out, CYFlags flags) const;
973 };
974
975 struct CYInfix :
976 CYExpression
977 {
978 CYExpression *lhs_;
979 CYExpression *rhs_;
980
981 CYInfix(CYExpression *lhs, CYExpression *rhs) :
982 lhs_(lhs),
983 rhs_(rhs)
984 {
985 }
986
987 void SetLeft(CYExpression *lhs) {
988 lhs_ = lhs;
989 }
990
991 virtual bool Alphabetic() const = 0;
992 virtual const char *Operator() const = 0;
993
994 virtual CYExpression *Replace(CYContext &context);
995 virtual void Output(CYOutput &out, CYFlags flags) const;
996 };
997
998 struct CYPostfix :
999 CYExpression
1000 {
1001 CYExpression *lhs_;
1002
1003 CYPostfix(CYExpression *lhs) :
1004 lhs_(lhs)
1005 {
1006 }
1007
1008 virtual const char *Operator() const = 0;
1009
1010 CYPrecedence(3)
1011
1012 virtual CYExpression *Replace(CYContext &context);
1013 virtual void Output(CYOutput &out, CYFlags flags) const;
1014 };
1015
1016 struct CYAssignment :
1017 CYExpression
1018 {
1019 CYExpression *lhs_;
1020 CYExpression *rhs_;
1021
1022 CYAssignment(CYExpression *lhs, CYExpression *rhs) :
1023 lhs_(lhs),
1024 rhs_(rhs)
1025 {
1026 }
1027
1028 void SetLeft(CYExpression *lhs) {
1029 lhs_ = lhs;
1030 }
1031
1032 virtual const char *Operator() const = 0;
1033
1034 CYPrecedence(16)
1035
1036 virtual CYExpression *Replace(CYContext &context);
1037 virtual void Output(CYOutput &out, CYFlags flags) const;
1038 };
1039
1040 struct CYArgument :
1041 CYNext<CYArgument>,
1042 CYThing
1043 {
1044 CYWord *name_;
1045 CYExpression *value_;
1046
1047 CYArgument(CYExpression *value, CYArgument *next = NULL) :
1048 CYNext<CYArgument>(next),
1049 name_(NULL),
1050 value_(value)
1051 {
1052 }
1053
1054 CYArgument(CYWord *name, CYExpression *value, CYArgument *next = NULL) :
1055 CYNext<CYArgument>(next),
1056 name_(name),
1057 value_(value)
1058 {
1059 }
1060
1061 CYArgument *Replace(CYContext &context);
1062 void Output(CYOutput &out) const;
1063 };
1064
1065 struct CYBlank :
1066 public CYWord
1067 {
1068 CYBlank() :
1069 CYWord("")
1070 {
1071 }
1072 };
1073
1074 struct CYClause :
1075 CYThing,
1076 CYNext<CYClause>
1077 {
1078 CYExpression *case_;
1079 CYStatement *statements_;
1080
1081 CYClause(CYExpression *_case, CYStatement *statements) :
1082 case_(_case),
1083 statements_(statements)
1084 {
1085 }
1086
1087 void Replace(CYContext &context);
1088 virtual void Output(CYOutput &out) const;
1089 };
1090
1091 struct CYElement :
1092 CYNext<CYElement>,
1093 CYThing
1094 {
1095 CYExpression *value_;
1096
1097 CYElement(CYExpression *value, CYElement *next) :
1098 CYNext<CYElement>(next),
1099 value_(value)
1100 {
1101 }
1102
1103 void Replace(CYContext &context);
1104 void Output(CYOutput &out) const;
1105 };
1106
1107 struct CYArray :
1108 CYLiteral
1109 {
1110 CYElement *elements_;
1111
1112 CYArray(CYElement *elements = NULL) :
1113 elements_(elements)
1114 {
1115 }
1116
1117 virtual CYExpression *Replace(CYContext &context);
1118 virtual void Output(CYOutput &out, CYFlags flags) const;
1119 };
1120
1121 struct CYProperty :
1122 CYNext<CYProperty>,
1123 CYThing
1124 {
1125 CYPropertyName *name_;
1126 CYExpression *value_;
1127
1128 CYProperty(CYPropertyName *name, CYExpression *value, CYProperty *next = NULL) :
1129 CYNext<CYProperty>(next),
1130 name_(name),
1131 value_(value)
1132 {
1133 }
1134
1135 void Replace(CYContext &context);
1136 virtual void Output(CYOutput &out) const;
1137 };
1138
1139 struct CYDeclaration :
1140 CYForInInitialiser
1141 {
1142 CYIdentifier *identifier_;
1143 CYExpression *initialiser_;
1144
1145 CYDeclaration(CYIdentifier *identifier, CYExpression *initialiser = NULL) :
1146 identifier_(identifier),
1147 initialiser_(initialiser)
1148 {
1149 }
1150
1151 virtual void ForIn(CYOutput &out, CYFlags flags) const;
1152 virtual CYStatement *ForEachIn(CYContext &out, CYExpression *value);
1153
1154 virtual CYExpression *Replace(CYContext &context);
1155
1156 virtual CYAssignment *Assignment(CYContext &context);
1157 CYVariable *Variable(CYContext &context);
1158
1159 virtual void Output(CYOutput &out, CYFlags flags) const;
1160 };
1161
1162 struct CYDeclarations :
1163 CYNext<CYDeclarations>,
1164 CYThing
1165 {
1166 CYDeclaration *declaration_;
1167
1168 CYDeclarations(CYDeclaration *declaration, CYDeclarations *next = NULL) :
1169 CYNext<CYDeclarations>(next),
1170 declaration_(declaration)
1171 {
1172 }
1173
1174 void Replace(CYContext &context);
1175
1176 CYCompound *Compound(CYContext &context);
1177 CYProperty *Property(CYContext &context);
1178 CYArgument *Argument(CYContext &context);
1179 CYFunctionParameter *Parameter(CYContext &context);
1180
1181 virtual void Output(CYOutput &out) const;
1182 virtual void Output(CYOutput &out, CYFlags flags) const;
1183 };
1184
1185 struct CYForDeclarations :
1186 CYForInitialiser
1187 {
1188 CYDeclarations *declarations_;
1189
1190 CYForDeclarations(CYDeclarations *declarations) :
1191 declarations_(declarations)
1192 {
1193 }
1194
1195 virtual CYCompound *Replace(CYContext &context);
1196 virtual void Output(CYOutput &out, CYFlags flags) const;
1197 };
1198
1199 struct CYVar :
1200 CYStatement
1201 {
1202 CYDeclarations *declarations_;
1203
1204 CYVar(CYDeclarations *declarations) :
1205 declarations_(declarations)
1206 {
1207 }
1208
1209 virtual CYStatement *Replace(CYContext &context);
1210 virtual void Output(CYOutput &out, CYFlags flags) const;
1211 };
1212
1213 struct CYLetStatement :
1214 CYStatement
1215 {
1216 CYDeclarations *declarations_;
1217 CYStatement *code_;
1218
1219 CYLetStatement(CYDeclarations *declarations, CYStatement *code) :
1220 declarations_(declarations),
1221 code_(code)
1222 {
1223 }
1224
1225 virtual CYStatement *Replace(CYContext &context);
1226 virtual void Output(CYOutput &out, CYFlags flags) const;
1227 };
1228
1229 struct CYFor :
1230 CYStatement
1231 {
1232 CYForInitialiser *initialiser_;
1233 CYExpression *test_;
1234 CYExpression *increment_;
1235 CYStatement *code_;
1236
1237 CYFor(CYForInitialiser *initialiser, CYExpression *test, CYExpression *increment, CYStatement *code) :
1238 initialiser_(initialiser),
1239 test_(test),
1240 increment_(increment),
1241 code_(code)
1242 {
1243 }
1244
1245 virtual CYStatement *Replace(CYContext &context);
1246 virtual void Output(CYOutput &out, CYFlags flags) const;
1247 };
1248
1249 struct CYForIn :
1250 CYStatement
1251 {
1252 CYForInInitialiser *initialiser_;
1253 CYExpression *set_;
1254 CYStatement *code_;
1255
1256 CYForIn(CYForInInitialiser *initialiser, CYExpression *set, CYStatement *code) :
1257 initialiser_(initialiser),
1258 set_(set),
1259 code_(code)
1260 {
1261 }
1262
1263 virtual CYStatement *Replace(CYContext &context);
1264 virtual void Output(CYOutput &out, CYFlags flags) const;
1265 };
1266
1267 struct CYForEachIn :
1268 CYStatement
1269 {
1270 CYForInInitialiser *initialiser_;
1271 CYExpression *set_;
1272 CYStatement *code_;
1273
1274 CYForEachIn(CYForInInitialiser *initialiser, CYExpression *set, CYStatement *code) :
1275 initialiser_(initialiser),
1276 set_(set),
1277 code_(code)
1278 {
1279 }
1280
1281 virtual CYStatement *Replace(CYContext &context);
1282 virtual void Output(CYOutput &out, CYFlags flags) const;
1283 };
1284
1285 struct CYObject :
1286 CYLiteral
1287 {
1288 CYProperty *properties_;
1289
1290 CYObject(CYProperty *properties = NULL) :
1291 properties_(properties)
1292 {
1293 }
1294
1295 virtual CYExpression *Replace(CYContext &context);
1296 void Output(CYOutput &out, CYFlags flags) const;
1297 };
1298
1299 struct CYMember :
1300 CYExpression
1301 {
1302 CYExpression *object_;
1303 CYExpression *property_;
1304
1305 CYMember(CYExpression *object, CYExpression *property) :
1306 object_(object),
1307 property_(property)
1308 {
1309 }
1310
1311 void SetLeft(CYExpression *object) {
1312 object_ = object;
1313 }
1314 };
1315
1316 struct CYDirectMember :
1317 CYMember
1318 {
1319 CYDirectMember(CYExpression *object, CYExpression *property) :
1320 CYMember(object, property)
1321 {
1322 }
1323
1324 CYPrecedence(1)
1325 CYRightHand(false)
1326
1327 virtual CYExpression *Replace(CYContext &context);
1328 virtual void Output(CYOutput &out, CYFlags flags) const;
1329 };
1330
1331 struct CYIndirectMember :
1332 CYMember
1333 {
1334 CYIndirectMember(CYExpression *object, CYExpression *property) :
1335 CYMember(object, property)
1336 {
1337 }
1338
1339 CYPrecedence(1)
1340 CYRightHand(false)
1341
1342 virtual CYExpression *Replace(CYContext &context);
1343 virtual void Output(CYOutput &out, CYFlags flags) const;
1344 };
1345
1346 namespace cy {
1347 namespace Syntax {
1348
1349 struct New :
1350 CYExpression
1351 {
1352 CYExpression *constructor_;
1353 CYArgument *arguments_;
1354
1355 New(CYExpression *constructor, CYArgument *arguments) :
1356 constructor_(constructor),
1357 arguments_(arguments)
1358 {
1359 }
1360
1361 virtual unsigned Precedence() const {
1362 return arguments_ == NULL ? 2 : 1;
1363 }
1364
1365 CYRightHand(false)
1366
1367 virtual CYExpression *Replace(CYContext &context);
1368 virtual void Output(CYOutput &out, CYFlags flags) const;
1369
1370 virtual CYExpression *AddArgument(CYContext &context, CYExpression *value);
1371 };
1372
1373 } }
1374
1375 struct CYCall :
1376 CYExpression
1377 {
1378 CYExpression *function_;
1379 CYArgument *arguments_;
1380
1381 CYCall(CYExpression *function, CYArgument *arguments = NULL) :
1382 function_(function),
1383 arguments_(arguments)
1384 {
1385 }
1386
1387 CYPrecedence(1)
1388 CYRightHand(false)
1389
1390 virtual CYExpression *Replace(CYContext &context);
1391 virtual void Output(CYOutput &out, CYFlags flags) const;
1392
1393 virtual CYExpression *AddArgument(CYContext &context, CYExpression *value);
1394 };
1395
1396 struct CYRubyProc;
1397
1398 struct CYRubyBlock :
1399 CYExpression
1400 {
1401 CYExpression *call_;
1402 CYRubyProc *proc_;
1403
1404 CYRubyBlock(CYExpression *call, CYRubyProc *proc) :
1405 call_(call),
1406 proc_(proc)
1407 {
1408 }
1409
1410 CYPrecedence(1)
1411 CYRightHand(false)
1412
1413 virtual CYExpression *Replace(CYContext &context);
1414 virtual void Output(CYOutput &out, CYFlags flags) const;
1415 };
1416
1417 struct CYIf :
1418 CYStatement
1419 {
1420 CYExpression *test_;
1421 CYStatement *true_;
1422 CYStatement *false_;
1423
1424 CYIf(CYExpression *test, CYStatement *_true, CYStatement *_false = NULL) :
1425 test_(test),
1426 true_(_true),
1427 false_(_false)
1428 {
1429 }
1430
1431 virtual CYStatement *Replace(CYContext &context);
1432 virtual void Output(CYOutput &out, CYFlags flags) const;
1433 };
1434
1435 struct CYDoWhile :
1436 CYStatement
1437 {
1438 CYExpression *test_;
1439 CYStatement *code_;
1440
1441 CYDoWhile(CYExpression *test, CYStatement *code) :
1442 test_(test),
1443 code_(code)
1444 {
1445 }
1446
1447 virtual CYStatement *Replace(CYContext &context);
1448 virtual void Output(CYOutput &out, CYFlags flags) const;
1449 };
1450
1451 struct CYWhile :
1452 CYStatement
1453 {
1454 CYExpression *test_;
1455 CYStatement *code_;
1456
1457 CYWhile(CYExpression *test, CYStatement *code) :
1458 test_(test),
1459 code_(code)
1460 {
1461 }
1462
1463 virtual CYStatement *Replace(CYContext &context);
1464 virtual void Output(CYOutput &out, CYFlags flags) const;
1465 };
1466
1467 // XXX: this should be split up into CYAnonymousFunction and CYNamedFunction (subclass)
1468 struct CYFunction {
1469 CYIdentifier *name_;
1470 CYFunctionParameter *parameters_;
1471 CYBlock code_;
1472 CYNonLocal *nonlocal_;
1473
1474 CYFunction(CYIdentifier *name, CYFunctionParameter *parameters, CYStatement *statements) :
1475 name_(name),
1476 parameters_(parameters),
1477 code_(statements),
1478 nonlocal_(NULL)
1479 {
1480 }
1481
1482 virtual ~CYFunction() {
1483 }
1484
1485 void Inject(CYContext &context);
1486 virtual void Replace_(CYContext &context, bool outer);
1487 virtual void Output(CYOutput &out, CYFlags flags) const;
1488 };
1489
1490 // XXX: this should be split up into CYAnonymousFunctionExpression and CYNamedFunctionExpression
1491 struct CYFunctionExpression :
1492 CYFunction,
1493 CYExpression
1494 {
1495 CYFunctionExpression(CYIdentifier *name, CYFunctionParameter *parameters, CYStatement *statements) :
1496 CYFunction(name, parameters, statements)
1497 {
1498 }
1499
1500 CYPrecedence(0)
1501 CYRightHand(false)
1502
1503 virtual CYExpression *Replace(CYContext &context);
1504 virtual void Output(CYOutput &out, CYFlags flags) const;
1505 };
1506
1507 // XXX: this should derive from CYAnonymousFunctionExpression
1508 struct CYRubyProc :
1509 CYFunctionExpression
1510 {
1511 CYRubyProc(CYFunctionParameter *parameters, CYStatement *statements) :
1512 CYFunctionExpression(NULL, parameters, statements)
1513 {
1514 }
1515
1516 virtual CYExpression *Replace(CYContext &context);
1517 virtual void Output(CYOutput &out, CYFlags flags) const;
1518 };
1519
1520 // XXX: this should derive from CYNamedFunction
1521 struct CYFunctionStatement :
1522 CYFunction,
1523 CYStatement
1524 {
1525 CYFunctionStatement(CYIdentifier *name, CYFunctionParameter *parameters, CYStatement *statements) :
1526 CYFunction(name, parameters, statements)
1527 {
1528 }
1529
1530 virtual CYStatement *Replace(CYContext &context);
1531 virtual void Output(CYOutput &out, CYFlags flags) const;
1532 };
1533
1534 struct CYExpress :
1535 CYStatement
1536 {
1537 CYExpression *expression_;
1538
1539 CYExpress(CYExpression *expression) :
1540 expression_(expression)
1541 {
1542 if (expression == NULL)
1543 throw;
1544 }
1545
1546 virtual CYStatement *Replace(CYContext &context);
1547 virtual void Output(CYOutput &out, CYFlags flags) const;
1548 };
1549
1550 struct CYContinue :
1551 CYStatement
1552 {
1553 CYIdentifier *label_;
1554
1555 CYContinue(CYIdentifier *label) :
1556 label_(label)
1557 {
1558 }
1559
1560 virtual CYStatement *Replace(CYContext &context);
1561 virtual void Output(CYOutput &out, CYFlags flags) const;
1562 };
1563
1564 struct CYBreak :
1565 CYStatement
1566 {
1567 CYIdentifier *label_;
1568
1569 CYBreak(CYIdentifier *label) :
1570 label_(label)
1571 {
1572 }
1573
1574 virtual CYStatement *Replace(CYContext &context);
1575 virtual void Output(CYOutput &out, CYFlags flags) const;
1576 };
1577
1578 struct CYReturn :
1579 CYStatement
1580 {
1581 CYExpression *value_;
1582
1583 CYReturn(CYExpression *value) :
1584 value_(value)
1585 {
1586 }
1587
1588 virtual CYStatement *Replace(CYContext &context);
1589 virtual void Output(CYOutput &out, CYFlags flags) const;
1590 };
1591
1592 struct CYEmpty :
1593 CYStatement
1594 {
1595 virtual CYStatement *Replace(CYContext &context);
1596 virtual void Output(CYOutput &out, CYFlags flags) const;
1597 };
1598
1599 struct CYFinally :
1600 CYThing
1601 {
1602 CYBlock code_;
1603
1604 CYFinally(CYStatement *statements) :
1605 code_(statements)
1606 {
1607 }
1608
1609 void Replace(CYContext &context);
1610 virtual void Output(CYOutput &out) const;
1611 };
1612
1613 namespace cy {
1614 namespace Syntax {
1615
1616 struct Catch :
1617 CYThing
1618 {
1619 CYIdentifier *name_;
1620 CYBlock code_;
1621
1622 Catch(CYIdentifier *name, CYStatement *statements) :
1623 name_(name),
1624 code_(statements)
1625 {
1626 }
1627
1628 void Replace(CYContext &context);
1629 virtual void Output(CYOutput &out) const;
1630 };
1631
1632 struct Try :
1633 CYStatement
1634 {
1635 CYBlock code_;
1636 Catch *catch_;
1637 CYFinally *finally_;
1638
1639 Try(CYStatement *statements, Catch *_catch, CYFinally *finally) :
1640 code_(statements),
1641 catch_(_catch),
1642 finally_(finally)
1643 {
1644 }
1645
1646 virtual CYStatement *Replace(CYContext &context);
1647 virtual void Output(CYOutput &out, CYFlags flags) const;
1648 };
1649
1650 struct Throw :
1651 CYStatement
1652 {
1653 CYExpression *value_;
1654
1655 Throw(CYExpression *value = NULL) :
1656 value_(value)
1657 {
1658 }
1659
1660 virtual CYStatement *Replace(CYContext &context);
1661 virtual void Output(CYOutput &out, CYFlags flags) const;
1662 };
1663
1664 } }
1665
1666 struct CYWith :
1667 CYStatement
1668 {
1669 CYExpression *scope_;
1670 CYStatement *code_;
1671
1672 CYWith(CYExpression *scope, CYStatement *code) :
1673 scope_(scope),
1674 code_(code)
1675 {
1676 }
1677
1678 virtual CYStatement *Replace(CYContext &context);
1679 virtual void Output(CYOutput &out, CYFlags flags) const;
1680 };
1681
1682 struct CYSwitch :
1683 CYStatement
1684 {
1685 CYExpression *value_;
1686 CYClause *clauses_;
1687
1688 CYSwitch(CYExpression *value, CYClause *clauses) :
1689 value_(value),
1690 clauses_(clauses)
1691 {
1692 }
1693
1694 virtual CYStatement *Replace(CYContext &context);
1695 virtual void Output(CYOutput &out, CYFlags flags) const;
1696 };
1697
1698 struct CYDebugger :
1699 CYStatement
1700 {
1701 CYDebugger()
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*/