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