]> git.saurik.com Git - cycript.git/blob - Parser.hpp
9daf63e993535a3af09ebcf4e43d681abd2c0c29
[cycript.git] / Parser.hpp
1 #ifndef CYPARSER_HPP
2 #define CYPARSER_HPP
3
4 #include <cstdlib>
5 #include <string>
6 #include <vector>
7
8 #include "location.hh"
9 #include "Pooling.hpp"
10
11 template <typename Type_>
12 struct CYNext {
13 Type_ *next_;
14
15 CYNext() :
16 next_(NULL)
17 {
18 }
19
20 CYNext(Type_ *next) :
21 next_(next)
22 {
23 }
24
25 void SetNext(Type_ *next) {
26 next_ = next;
27 }
28 };
29
30 struct CYThing {
31 virtual void Output(std::ostream &out) const = 0;
32 };
33
34 _finline std::ostream &operator <<(std::ostream &out, const CYThing &rhs) {
35 rhs.Output(out);
36 return out;
37 }
38
39 struct CYSource :
40 CYNext<CYSource>
41 {
42 virtual void Show(std::ostream &out) const;
43 virtual void Output(std::ostream &out) const = 0;
44 virtual void Output(std::ostream &out, bool block) const;
45 };
46
47 struct CYName :
48 CYThing
49 {
50 virtual const char *Name() const = 0;
51 };
52
53 struct CYWord :
54 CYName
55 {
56 const char *word_;
57
58 CYWord(const char *word) :
59 word_(word)
60 {
61 }
62
63 const char *Value() const {
64 return word_;
65 }
66
67 virtual const char *Name() const {
68 return Value();
69 }
70
71 virtual void Output(std::ostream &out) const;
72 };
73
74 struct CYIdentifier :
75 CYWord
76 {
77 CYIdentifier(const char *word) :
78 CYWord(word)
79 {
80 }
81 };
82
83 struct CYLabel :
84 CYNext<CYLabel>
85 {
86 CYIdentifier *identifier_;
87
88 CYLabel(CYIdentifier *identifier, CYLabel *next) :
89 CYNext<CYLabel>(next),
90 identifier_(identifier)
91 {
92 }
93 };
94
95 struct CYStatement :
96 CYSource
97 {
98 CYLabel *label_;
99
100 void AddLabel(CYIdentifier *identifier) {
101 label_ = new CYLabel(identifier, label_);
102 }
103 };
104
105 enum CYState {
106 CYClear,
107 CYRestricted,
108 CYNewLine
109 };
110
111 class CYDriver {
112 public:
113 CYPool pool_;
114
115 CYState state_;
116 void *scanner_;
117
118 const char *data_;
119 size_t size_;
120
121 std::string filename_;
122
123 struct Error {
124 cy::location location_;
125 std::string message_;
126 };
127
128 typedef std::vector<Error> Errors;
129
130 CYSource *source_;
131 Errors errors_;
132
133 private:
134 void ScannerInit();
135 void ScannerDestroy();
136
137 public:
138 CYDriver(const std::string &filename);
139 ~CYDriver();
140 };
141
142 struct CYPart {
143 virtual void Part(std::ostream &out) const = 0;
144 };
145
146 struct CYForInitialiser :
147 CYPart
148 {
149 };
150
151 struct CYForInInitialiser :
152 CYPart
153 {
154 };
155
156 enum CYFlags {
157 CYNoFlags,
158 CYNoBrace,
159 CYNoFunction,
160 CYNoLeader,
161 CYNoTrailer,
162 CYNoIn
163 };
164
165 struct CYExpression :
166 CYNext<CYExpression>,
167 CYForInitialiser,
168 CYForInInitialiser
169 {
170 virtual unsigned Precedence() const = 0;
171 virtual void Part(std::ostream &out) const;
172 virtual void Output(std::ostream &out, CYFlags flags) const = 0;
173 void Output(std::ostream &out, unsigned precedence, CYFlags flags) const;
174
175 virtual const char *Word() const {
176 return NULL;
177 }
178 };
179
180 #define CYAlphabetic(value) \
181 virtual bool Alphabetic() const { \
182 return value; \
183 }
184
185 #define CYPrecedence(value) \
186 virtual unsigned Precedence() const { \
187 return value; \
188 }
189
190 struct CYCompound :
191 CYExpression
192 {
193 CYExpression *expressions_;
194
195 CYCompound(CYExpression *expressions) :
196 expressions_(expressions)
197 {
198 }
199
200 void AddPrev(CYExpression *expression) {
201 CYExpression *last(expression);
202 while (last->next_ != NULL)
203 last = last->next_;
204 last->SetNext(expressions_);
205 expressions_ = expression;
206 }
207
208 CYPrecedence(17)
209
210 void Output(std::ostream &out, CYFlags flags) const;
211 };
212
213 struct CYLiteral :
214 CYExpression
215 {
216 CYPrecedence(0)
217 };
218
219 struct CYSelectorPart :
220 CYNext<CYSelectorPart>
221 {
222 CYWord *name_;
223 bool value_;
224
225 CYSelectorPart(CYWord *name, bool value, CYSelectorPart *next) :
226 CYNext<CYSelectorPart>(next),
227 name_(name),
228 value_(value)
229 {
230 }
231
232 virtual void Output(std::ostream &out) const;
233 };
234
235 struct CYSelector :
236 CYLiteral
237 {
238 CYSelectorPart *name_;
239
240 CYSelector(CYSelectorPart *name) :
241 name_(name)
242 {
243 }
244
245 CYPrecedence(1)
246
247 virtual void Output(std::ostream &out, CYFlags flags) const;
248 };
249
250 struct CYRange {
251 uint64_t lo_;
252 uint64_t hi_;
253
254 CYRange(uint64_t lo, uint64_t hi) :
255 lo_(lo), hi_(hi)
256 {
257 }
258
259 bool operator [](uint8_t value) const {
260 return !(value >> 7) && (value >> 6 ? hi_ : lo_) >> (value & 0x3f) & 0x1;
261 }
262
263 void operator()(uint8_t value) {
264 if (value >> 7)
265 return;
266 (value >> 6 ? hi_ : lo_) |= uint64_t(0x1) << (value & 0x3f);
267 }
268 };
269
270 extern CYRange WordStartRange_;
271 extern CYRange WordEndRange_;
272
273 struct CYString :
274 CYLiteral,
275 CYName
276 {
277 const char *value_;
278 size_t size_;
279
280 CYString(const char *value, size_t size) :
281 value_(value),
282 size_(size)
283 {
284 }
285
286 CYString(const CYIdentifier *identifier) :
287 value_(identifier->Value()),
288 size_(strlen(value_))
289 {
290 }
291
292 const char *Value() const {
293 return value_;
294 }
295
296 virtual const char *Name() const {
297 return Value();
298 }
299
300 virtual const char *Word() const {
301 if (size_ == 0 || !WordStartRange_[value_[0]])
302 return NULL;
303 for (size_t i(1); i != size_; ++i)
304 if (!WordEndRange_[value_[i]])
305 return NULL;
306 return Value();
307 }
308
309 virtual void Output(std::ostream &out) const {
310 return Output(out, CYNoFlags);
311 }
312
313 virtual void Output(std::ostream &out, CYFlags flags) const;
314 };
315
316 struct CYNumber :
317 CYLiteral,
318 CYName
319 {
320 double value_;
321
322 CYNumber(double value) :
323 value_(value)
324 {
325 }
326
327 double Value() const {
328 return value_;
329 }
330
331 virtual const char *Name() const {
332 throw;
333 }
334
335 virtual void Output(std::ostream &out) const {
336 return Output(out, CYNoFlags);
337 }
338
339 virtual void Output(std::ostream &out, CYFlags flags) const;
340 };
341
342 struct CYNull :
343 CYWord,
344 CYLiteral
345 {
346 CYNull() :
347 CYWord("null")
348 {
349 }
350
351 virtual void Output(std::ostream &out, CYFlags flags) const;
352 };
353
354 struct CYThis :
355 CYWord,
356 CYExpression
357 {
358 CYThis() :
359 CYWord("this")
360 {
361 }
362
363 CYPrecedence(0)
364
365 virtual void Output(std::ostream &out, CYFlags flags) const;
366 };
367
368 struct CYBoolean :
369 CYLiteral
370 {
371 virtual bool Value() const = 0;
372 virtual void Output(std::ostream &out, CYFlags flags) const;
373 };
374
375 struct CYFalse :
376 CYWord,
377 CYBoolean
378 {
379 CYFalse() :
380 CYWord("false")
381 {
382 }
383
384 virtual bool Value() const;
385 };
386
387 struct CYTrue :
388 CYWord,
389 CYBoolean
390 {
391 CYTrue() :
392 CYWord("true")
393 {
394 }
395
396 virtual bool Value() const;
397 };
398
399 struct CYVariable :
400 CYExpression
401 {
402 CYIdentifier *name_;
403
404 CYVariable(CYIdentifier *name) :
405 name_(name)
406 {
407 }
408
409 CYPrecedence(0)
410
411 virtual void Output(std::ostream &out, CYFlags flags) const;
412 };
413
414 struct CYPrefix :
415 CYExpression
416 {
417 CYExpression *rhs_;
418
419 CYPrefix(CYExpression *rhs) :
420 rhs_(rhs)
421 {
422 }
423
424 virtual bool Alphabetic() const = 0;
425 virtual const char *Operator() const = 0;
426
427 virtual void Output(std::ostream &out, CYFlags flags) const;
428 };
429
430 struct CYInfix :
431 CYExpression
432 {
433 CYExpression *lhs_;
434 CYExpression *rhs_;
435
436 CYInfix(CYExpression *lhs, CYExpression *rhs) :
437 lhs_(lhs),
438 rhs_(rhs)
439 {
440 }
441
442 virtual bool Alphabetic() const = 0;
443 virtual const char *Operator() const = 0;
444
445 virtual void Output(std::ostream &out, CYFlags flags) const;
446 };
447
448 struct CYPostfix :
449 CYExpression
450 {
451 CYExpression *lhs_;
452
453 CYPostfix(CYExpression *lhs) :
454 lhs_(lhs)
455 {
456 }
457
458 virtual const char *Operator() const = 0;
459
460 virtual void Output(std::ostream &out, CYFlags flags) const;
461 };
462
463 struct CYAssignment :
464 CYExpression
465 {
466 CYExpression *lhs_;
467 CYExpression *rhs_;
468
469 CYAssignment(CYExpression *lhs, CYExpression *rhs) :
470 lhs_(lhs),
471 rhs_(rhs)
472 {
473 }
474
475 virtual const char *Operator() const = 0;
476
477 virtual void Output(std::ostream &out, CYFlags flags) const;
478 };
479
480 struct CYArgument :
481 CYNext<CYArgument>
482 {
483 CYWord *name_;
484 CYExpression *value_;
485
486 CYArgument(CYWord *name, CYExpression *value, CYArgument *next = NULL) :
487 CYNext<CYArgument>(next),
488 name_(name),
489 value_(value)
490 {
491 }
492
493 void Output(std::ostream &out) const;
494 };
495
496 struct CYBlank :
497 public CYWord
498 {
499 CYBlank() :
500 CYWord("")
501 {
502 }
503 };
504
505 struct CYClause :
506 CYThing,
507 CYNext<CYClause>
508 {
509 CYExpression *case_;
510 CYStatement *code_;
511
512 CYClause(CYExpression *_case, CYStatement *code) :
513 case_(_case),
514 code_(code)
515 {
516 }
517
518 virtual void Output(std::ostream &out) const;
519 };
520
521 struct CYElement :
522 CYNext<CYElement>
523 {
524 CYExpression *value_;
525
526 CYElement(CYExpression *value, CYElement *next) :
527 CYNext<CYElement>(next),
528 value_(value)
529 {
530 }
531
532 void Output(std::ostream &out) const;
533 };
534
535 struct CYArray :
536 CYLiteral
537 {
538 CYElement *elements_;
539
540 CYArray(CYElement *elements) :
541 elements_(elements)
542 {
543 }
544
545 virtual void Output(std::ostream &out, CYFlags flags) const;
546 };
547
548 struct CYDeclaration :
549 CYThing,
550 CYForInInitialiser
551 {
552 CYIdentifier *identifier_;
553 CYExpression *initialiser_;
554
555 CYDeclaration(CYIdentifier *identifier, CYExpression *initialiser) :
556 identifier_(identifier),
557 initialiser_(initialiser)
558 {
559 }
560
561 virtual void Part(std::ostream &out) const;
562 virtual void Output(std::ostream &out) const;
563 };
564
565 struct CYDeclarations :
566 CYStatement,
567 CYForInitialiser
568 {
569 CYDeclaration *declaration_;
570 CYDeclarations *next_;
571
572 CYDeclarations(CYDeclaration *declaration, CYDeclarations *next) :
573 declaration_(declaration),
574 next_(next)
575 {
576 }
577
578 virtual void Part(std::ostream &out) const;
579 virtual void Output(std::ostream &out) const;
580 };
581
582 struct CYField :
583 CYNext<CYField>
584 {
585 virtual void Output(std::ostream &out) const;
586 };
587
588 struct CYMessageParameter :
589 CYNext<CYMessageParameter>
590 {
591 CYWord *tag_;
592 CYExpression *type_;
593 CYIdentifier *name_;
594
595 CYMessageParameter(CYWord *tag, CYExpression *type, CYIdentifier *name) :
596 tag_(tag),
597 type_(type),
598 name_(name)
599 {
600 }
601 };
602
603 struct CYMessage :
604 CYSource
605 {
606 bool instance_;
607 CYExpression *type_;
608 CYMessageParameter *parameter_;
609 CYSource *body_;
610
611 CYMessage(bool instance, CYExpression *type, CYMessageParameter *parameter, CYSource *body) :
612 instance_(instance),
613 type_(type),
614 parameter_(parameter),
615 body_(body)
616 {
617 }
618
619 virtual void Output(std::ostream &out) const;
620 };
621
622 struct CYClass :
623 CYSource
624 {
625 CYIdentifier *name_;
626 CYExpression *super_;
627 CYField *fields_;
628 CYMessage *messages_;
629
630 CYClass(CYIdentifier *name, CYExpression *super, CYField *fields, CYMessage *messages) :
631 name_(name),
632 super_(super),
633 fields_(fields),
634 messages_(messages)
635 {
636 }
637
638 virtual void Output(std::ostream &out) const;
639 };
640
641 struct CYFunctionParameter :
642 CYNext<CYFunctionParameter>,
643 CYThing
644 {
645 CYIdentifier *name_;
646
647 CYFunctionParameter(CYIdentifier *name, CYFunctionParameter *next) :
648 CYNext<CYFunctionParameter>(next),
649 name_(name)
650 {
651 }
652
653 virtual void Output(std::ostream &out) const;
654 };
655
656 struct CYFor :
657 CYStatement
658 {
659 CYForInitialiser *initialiser_;
660 CYExpression *test_;
661 CYExpression *increment_;
662 CYStatement *code_;
663
664 CYFor(CYForInitialiser *initialiser, CYExpression *test, CYExpression *increment, CYStatement *code) :
665 initialiser_(initialiser),
666 test_(test),
667 increment_(increment),
668 code_(code)
669 {
670 }
671
672 virtual void Output(std::ostream &out) const;
673 };
674
675 struct CYForIn :
676 CYStatement
677 {
678 CYForInInitialiser *initialiser_;
679 CYExpression *set_;
680 CYStatement *code_;
681
682 CYForIn(CYForInInitialiser *initialiser, CYExpression *set, CYStatement *code) :
683 initialiser_(initialiser),
684 set_(set),
685 code_(code)
686 {
687 }
688
689 virtual void Output(std::ostream &out) const;
690 };
691
692 struct CYProperty :
693 CYNext<CYProperty>
694 {
695 CYName *name_;
696 CYExpression *value_;
697
698 CYProperty(CYName *name, CYExpression *value, CYProperty *next) :
699 CYNext<CYProperty>(next),
700 name_(name),
701 value_(value)
702 {
703 }
704
705 virtual void Output(std::ostream &out) const;
706 };
707
708 struct CYObject :
709 CYLiteral
710 {
711 CYProperty *property_;
712
713 CYObject(CYProperty *property) :
714 property_(property)
715 {
716 }
717
718 void Output(std::ostream &out, CYFlags flags) const;
719 };
720
721 struct CYCatch :
722 CYThing
723 {
724 CYIdentifier *name_;
725 CYStatement *code_;
726
727 CYCatch(CYIdentifier *name, CYStatement *code) :
728 name_(name),
729 code_(code)
730 {
731 }
732
733 virtual void Output(std::ostream &out) const;
734 };
735
736 struct CYSend :
737 CYExpression
738 {
739 CYExpression *self_;
740 CYArgument *arguments_;
741
742 CYSend(CYExpression *self, CYArgument *arguments) :
743 self_(self),
744 arguments_(arguments)
745 {
746 }
747
748 CYPrecedence(0)
749
750 virtual void Output(std::ostream &out, CYFlags flags) const;
751 };
752
753 struct CYMember :
754 CYExpression
755 {
756 CYExpression *object_;
757 CYExpression *property_;
758
759 CYMember(CYExpression *object, CYExpression *property) :
760 object_(object),
761 property_(property)
762 {
763 }
764
765 CYPrecedence(1)
766
767 virtual void Output(std::ostream &out, CYFlags flags) const;
768 };
769
770 struct CYNew :
771 CYExpression
772 {
773 CYExpression *constructor_;
774 CYArgument *arguments_;
775
776 CYNew(CYExpression *constructor, CYArgument *arguments) :
777 constructor_(constructor),
778 arguments_(arguments)
779 {
780 }
781
782 CYPrecedence(1)
783
784 virtual void Output(std::ostream &out, CYFlags flags) const;
785 };
786
787 struct CYCall :
788 CYExpression
789 {
790 CYExpression *function_;
791 CYArgument *arguments_;
792
793 CYCall(CYExpression *function, CYArgument *arguments) :
794 function_(function),
795 arguments_(arguments)
796 {
797 }
798
799 CYPrecedence(2)
800
801 virtual void Output(std::ostream &out, CYFlags flags) const;
802 };
803
804 struct CYIf :
805 CYStatement
806 {
807 CYExpression *test_;
808 CYStatement *true_;
809 CYStatement *false_;
810
811 CYIf(CYExpression *test, CYStatement *_true, CYStatement *_false) :
812 test_(test),
813 true_(_true),
814 false_(_false)
815 {
816 }
817
818 virtual void Output(std::ostream &out) const;
819 };
820
821 struct CYDoWhile :
822 CYStatement
823 {
824 CYExpression *test_;
825 CYStatement *code_;
826
827 CYDoWhile(CYExpression *test, CYStatement *code) :
828 test_(test),
829 code_(code)
830 {
831 }
832
833 virtual void Output(std::ostream &out) const;
834 };
835
836 struct CYWhile :
837 CYStatement
838 {
839 CYExpression *test_;
840 CYStatement *code_;
841
842 CYWhile(CYExpression *test, CYStatement *code) :
843 test_(test),
844 code_(code)
845 {
846 }
847
848 virtual void Output(std::ostream &out) const;
849 };
850
851 struct CYLambda :
852 CYExpression
853 {
854 CYIdentifier *name_;
855 CYFunctionParameter *parameters_;
856 CYSource *body_;
857
858 CYLambda(CYIdentifier *name, CYFunctionParameter *parameters, CYSource *body) :
859 name_(name),
860 parameters_(parameters),
861 body_(body)
862 {
863 }
864
865 CYPrecedence(0)
866
867 virtual void Output(std::ostream &out, CYFlags flags) const;
868 };
869
870 struct CYFunction :
871 CYLambda,
872 CYSource
873 {
874 CYFunction(CYIdentifier *name, CYFunctionParameter *parameters, CYSource *body) :
875 CYLambda(name, parameters, body)
876 {
877 }
878
879 virtual void Output(std::ostream &out) const;
880 };
881
882 struct CYExpress :
883 CYStatement
884 {
885 CYExpression *expression_;
886
887 CYExpress(CYExpression *expression) :
888 expression_(expression)
889 {
890 }
891
892 virtual void Output(std::ostream &out) const;
893 };
894
895 struct CYContinue :
896 CYStatement
897 {
898 CYIdentifier *label_;
899
900 CYContinue(CYIdentifier *label) :
901 label_(label)
902 {
903 }
904
905 virtual void Output(std::ostream &out) const;
906 };
907
908 struct CYBreak :
909 CYStatement
910 {
911 CYIdentifier *label_;
912
913 CYBreak(CYIdentifier *label) :
914 label_(label)
915 {
916 }
917
918 virtual void Output(std::ostream &out) const;
919 };
920
921 struct CYReturn :
922 CYStatement
923 {
924 CYExpression *value_;
925
926 CYReturn(CYExpression *value) :
927 value_(value)
928 {
929 }
930
931 virtual void Output(std::ostream &out) const;
932 };
933
934 struct CYEmpty :
935 CYStatement
936 {
937 virtual void Output(std::ostream &out) const;
938 virtual void Output(std::ostream &out, bool block) const;
939 };
940
941 struct CYTry :
942 CYStatement
943 {
944 CYStatement *try_;
945 CYCatch *catch_;
946 CYStatement *finally_;
947
948 CYTry(CYStatement *_try, CYCatch *_catch, CYStatement *finally) :
949 try_(_try),
950 catch_(_catch),
951 finally_(finally)
952 {
953 }
954
955 virtual void Output(std::ostream &out) const;
956 };
957
958 struct CYThrow :
959 CYStatement
960 {
961 CYExpression *value_;
962
963 CYThrow(CYExpression *value) :
964 value_(value)
965 {
966 }
967
968 virtual void Output(std::ostream &out) const;
969 };
970
971 struct CYWith :
972 CYStatement
973 {
974 CYExpression *scope_;
975 CYStatement *code_;
976
977 CYWith(CYExpression *scope, CYStatement *code) :
978 scope_(scope),
979 code_(code)
980 {
981 }
982
983 virtual void Output(std::ostream &out) const;
984 };
985
986 struct CYSwitch :
987 CYStatement
988 {
989 CYExpression *value_;
990 CYClause *clauses_;
991
992 CYSwitch(CYExpression *value, CYClause *clauses) :
993 value_(value),
994 clauses_(clauses)
995 {
996 }
997
998 virtual void Output(std::ostream &out) const;
999 };
1000
1001 struct CYCondition :
1002 CYExpression
1003 {
1004 CYExpression *test_;
1005 CYExpression *true_;
1006 CYExpression *false_;
1007
1008 CYCondition(CYExpression *test, CYExpression *_true, CYExpression *_false) :
1009 test_(test),
1010 true_(_true),
1011 false_(_false)
1012 {
1013 }
1014
1015 CYPrecedence(15)
1016
1017 virtual void Output(std::ostream &out, CYFlags flags) const;
1018 };
1019
1020 struct CYAddressOf :
1021 CYPrefix
1022 {
1023 CYAddressOf(CYExpression *rhs) :
1024 CYPrefix(rhs)
1025 {
1026 }
1027
1028 virtual const char *Operator() const {
1029 return "&";
1030 }
1031
1032 CYAlphabetic(false)
1033 CYPrecedence(2)
1034
1035 virtual void Output(std::ostream &out, CYFlags flags) const;
1036 };
1037
1038 struct CYIndirect :
1039 CYPrefix
1040 {
1041 CYIndirect(CYExpression *rhs) :
1042 CYPrefix(rhs)
1043 {
1044 }
1045
1046 virtual const char *Operator() const {
1047 return "*";
1048 }
1049
1050 CYAlphabetic(false)
1051 CYPrecedence(1)
1052
1053 virtual void Output(std::ostream &out, CYFlags flags) const;
1054 };
1055
1056 #define CYPostfix_(op, name) \
1057 struct CY ## name : \
1058 CYPostfix \
1059 { \
1060 CY ## name(CYExpression *lhs) : \
1061 CYPostfix(lhs) \
1062 { \
1063 } \
1064 \
1065 CYPrecedence(3) \
1066 \
1067 virtual const char *Operator() const { \
1068 return op; \
1069 } \
1070 };
1071
1072 #define CYPrefix_(alphabetic, op, name) \
1073 struct CY ## name : \
1074 CYPrefix \
1075 { \
1076 CY ## name(CYExpression *rhs) : \
1077 CYPrefix(rhs) \
1078 { \
1079 } \
1080 \
1081 CYAlphabetic(alphabetic) \
1082 CYPrecedence(4) \
1083 \
1084 virtual const char *Operator() const { \
1085 return op; \
1086 } \
1087 };
1088
1089 #define CYInfix_(alphabetic, precedence, op, name) \
1090 struct CY ## name : \
1091 CYInfix \
1092 { \
1093 CY ## name(CYExpression *lhs, CYExpression *rhs) : \
1094 CYInfix(lhs, rhs) \
1095 { \
1096 } \
1097 \
1098 CYAlphabetic(alphabetic) \
1099 CYPrecedence(precedence) \
1100 \
1101 virtual const char *Operator() const { \
1102 return op; \
1103 } \
1104 };
1105
1106 #define CYAssignment_(op, name) \
1107 struct CY ## name ## Assign : \
1108 CYAssignment \
1109 { \
1110 CY ## name ## Assign(CYExpression *lhs, CYExpression *rhs) : \
1111 CYAssignment(lhs, rhs) \
1112 { \
1113 } \
1114 \
1115 CYPrecedence(16) \
1116 \
1117 virtual const char *Operator() const { \
1118 return op; \
1119 } \
1120 };
1121
1122 CYPostfix_("++", PostIncrement)
1123 CYPostfix_("--", PostDecrement)
1124
1125 CYPrefix_(true, "delete", Delete)
1126 CYPrefix_(true, "void", Void)
1127 CYPrefix_(true, "typeof", TypeOf)
1128 CYPrefix_(false, "++", PreIncrement)
1129 CYPrefix_(false, "--", PreDecrement)
1130 CYPrefix_(false, "-", Negate)
1131 CYPrefix_(false, "~", BitwiseNot)
1132 CYPrefix_(false, "!", LogicalNot)
1133
1134 CYInfix_(false, 5, "*", Multiply)
1135 CYInfix_(false, 5, "/", Divide)
1136 CYInfix_(false, 5, "%", Modulus)
1137 CYInfix_(false, 6, "+", Add)
1138 CYInfix_(false, 6, "-", Subtract)
1139 CYInfix_(false, 7, "<<", ShiftLeft)
1140 CYInfix_(false, 7, ">>", ShiftRightSigned)
1141 CYInfix_(false, 7, ">>>", ShiftRightUnsigned)
1142 CYInfix_(false, 8, "<", Less)
1143 CYInfix_(false, 8, ">", Greater)
1144 CYInfix_(false, 8, "<=", LessOrEqual)
1145 CYInfix_(false, 8, ">=", GreaterOrEqual)
1146 CYInfix_(true, 8, "instanceof", InstanceOf)
1147 CYInfix_(true, 8, "in", In)
1148 CYInfix_(false, 9, "==", Equal)
1149 CYInfix_(false, 9, "!=", NotEqual)
1150 CYInfix_(false, 9, "===", Identical)
1151 CYInfix_(false, 9, "!==", NotIdentical)
1152 CYInfix_(false, 10, "&", BitwiseAnd)
1153 CYInfix_(false, 11, "^", BitwiseXOr)
1154 CYInfix_(false, 12, "|", BitwiseOr)
1155 CYInfix_(false, 13, "&&", LogicalAnd)
1156 CYInfix_(false, 14, "||", LogicalOr)
1157
1158 CYAssignment_("=", )
1159 CYAssignment_("*=", Multiply)
1160 CYAssignment_("/=", Divide)
1161 CYAssignment_("%=", Modulus)
1162 CYAssignment_("+=", Add)
1163 CYAssignment_("-=", Subtract)
1164 CYAssignment_("<<=", ShiftLeft)
1165 CYAssignment_(">>=", ShiftRightSigned)
1166 CYAssignment_(">>>=", ShiftRightUnsigned)
1167 CYAssignment_("&=", BitwiseAnd)
1168 CYAssignment_("^=", BitwiseXOr)
1169 CYAssignment_("|=", BitwiseOr)
1170
1171 #endif/*CYPARSER_HPP*/