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