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