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