11 template <typename Type_>
25 void SetNext(Type_ *next) {
31 virtual void Output(std::ostream &out) const = 0;
34 _finline std::ostream &operator <<(std::ostream &out, const CYThing &rhs) {
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;
50 virtual const char *Name() const = 0;
58 CYWord(const char *word) :
63 const char *Value() const {
67 virtual const char *Name() const {
71 virtual void Output(std::ostream &out) const;
77 CYIdentifier(const char *word) :
86 CYIdentifier *identifier_;
88 CYLabel(CYIdentifier *identifier, CYLabel *next) :
89 CYNext<CYLabel>(next),
90 identifier_(identifier)
100 void AddLabel(CYIdentifier *identifier) {
101 label_ = new CYLabel(identifier, label_);
121 std::string filename_;
124 cy::location location_;
125 std::string message_;
128 typedef std::vector<Error> Errors;
135 void ScannerDestroy();
138 CYDriver(const std::string &filename);
143 virtual void Part(std::ostream &out) const = 0;
146 struct CYForInitialiser :
151 struct CYForInInitialiser :
165 struct CYExpression :
166 CYNext<CYExpression>,
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;
175 virtual const char *Word() const {
180 #define CYAlphabetic(value) \
181 virtual bool Alphabetic() const { \
185 #define CYPrecedence(value) \
186 virtual unsigned Precedence() const { \
193 CYExpression *expressions_;
195 CYCompound(CYExpression *expressions) :
196 expressions_(expressions)
200 void AddPrev(CYExpression *expression) {
201 CYExpression *last(expression);
202 while (last->next_ != NULL)
204 last->SetNext(expressions_);
205 expressions_ = expression;
210 void Output(std::ostream &out, CYFlags flags) const;
219 struct CYSelectorPart :
220 CYNext<CYSelectorPart>
225 CYSelectorPart(CYWord *name, bool value, CYSelectorPart *next) :
226 CYNext<CYSelectorPart>(next),
232 virtual void Output(std::ostream &out) const;
238 CYSelectorPart *name_;
240 CYSelector(CYSelectorPart *name) :
247 virtual void Output(std::ostream &out, CYFlags flags) const;
254 CYRange(uint64_t lo, uint64_t hi) :
259 bool operator [](uint8_t value) const {
260 return !(value >> 7) && (value >> 6 ? hi_ : lo_) >> (value & 0x3f) & 0x1;
263 void operator()(uint8_t value) {
266 (value >> 6 ? hi_ : lo_) |= uint64_t(0x1) << (value & 0x3f);
270 extern CYRange WordStartRange_;
271 extern CYRange WordEndRange_;
280 CYString(const char *value, size_t size) :
286 CYString(const CYIdentifier *identifier) :
287 value_(identifier->Value()),
288 size_(strlen(value_))
292 const char *Value() const {
296 virtual const char *Name() const {
300 virtual const char *Word() const {
301 if (size_ == 0 || !WordStartRange_[value_[0]])
303 for (size_t i(1); i != size_; ++i)
304 if (!WordEndRange_[value_[i]])
309 virtual void Output(std::ostream &out) const {
310 return Output(out, CYNoFlags);
313 virtual void Output(std::ostream &out, CYFlags flags) const;
322 CYNumber(double value) :
327 double Value() const {
331 virtual const char *Name() const {
335 virtual void Output(std::ostream &out) const {
336 return Output(out, CYNoFlags);
339 virtual void Output(std::ostream &out, CYFlags flags) const;
351 virtual void Output(std::ostream &out, CYFlags flags) const;
365 virtual void Output(std::ostream &out, CYFlags flags) const;
371 virtual bool Value() const = 0;
372 virtual void Output(std::ostream &out, CYFlags flags) const;
384 virtual bool Value() const;
396 virtual bool Value() const;
404 CYVariable(CYIdentifier *name) :
411 virtual void Output(std::ostream &out, CYFlags flags) const;
419 CYPrefix(CYExpression *rhs) :
424 virtual bool Alphabetic() const = 0;
425 virtual const char *Operator() const = 0;
427 virtual void Output(std::ostream &out, CYFlags flags) const;
436 CYInfix(CYExpression *lhs, CYExpression *rhs) :
442 virtual bool Alphabetic() const = 0;
443 virtual const char *Operator() const = 0;
445 virtual void Output(std::ostream &out, CYFlags flags) const;
453 CYPostfix(CYExpression *lhs) :
458 virtual const char *Operator() const = 0;
460 virtual void Output(std::ostream &out, CYFlags flags) const;
463 struct CYAssignment :
469 CYAssignment(CYExpression *lhs, CYExpression *rhs) :
475 virtual const char *Operator() const = 0;
477 virtual void Output(std::ostream &out, CYFlags flags) const;
484 CYExpression *value_;
486 CYArgument(CYWord *name, CYExpression *value, CYArgument *next = NULL) :
487 CYNext<CYArgument>(next),
493 void Output(std::ostream &out) const;
512 CYClause(CYExpression *_case, CYStatement *code) :
518 virtual void Output(std::ostream &out) const;
524 CYExpression *value_;
526 CYElement(CYExpression *value, CYElement *next) :
527 CYNext<CYElement>(next),
532 void Output(std::ostream &out) const;
538 CYElement *elements_;
540 CYArray(CYElement *elements) :
545 virtual void Output(std::ostream &out, CYFlags flags) const;
548 struct CYDeclaration :
552 CYIdentifier *identifier_;
553 CYExpression *initialiser_;
555 CYDeclaration(CYIdentifier *identifier, CYExpression *initialiser) :
556 identifier_(identifier),
557 initialiser_(initialiser)
561 virtual void Part(std::ostream &out) const;
562 virtual void Output(std::ostream &out) const;
565 struct CYDeclarations :
569 CYDeclaration *declaration_;
570 CYDeclarations *next_;
572 CYDeclarations(CYDeclaration *declaration, CYDeclarations *next) :
573 declaration_(declaration),
578 virtual void Part(std::ostream &out) const;
579 virtual void Output(std::ostream &out) const;
585 virtual void Output(std::ostream &out) const;
588 struct CYMessageParameter :
589 CYNext<CYMessageParameter>
595 CYMessageParameter(CYWord *tag, CYExpression *type, CYIdentifier *name) :
608 CYMessageParameter *parameter_;
611 CYMessage(bool instance, CYExpression *type, CYMessageParameter *parameter, CYSource *body) :
614 parameter_(parameter),
619 virtual void Output(std::ostream &out) const;
626 CYExpression *super_;
628 CYMessage *messages_;
630 CYClass(CYIdentifier *name, CYExpression *super, CYField *fields, CYMessage *messages) :
638 virtual void Output(std::ostream &out) const;
641 struct CYFunctionParameter :
642 CYNext<CYFunctionParameter>,
647 CYFunctionParameter(CYIdentifier *name, CYFunctionParameter *next) :
648 CYNext<CYFunctionParameter>(next),
653 virtual void Output(std::ostream &out) const;
659 CYForInitialiser *initialiser_;
661 CYExpression *increment_;
664 CYFor(CYForInitialiser *initialiser, CYExpression *test, CYExpression *increment, CYStatement *code) :
665 initialiser_(initialiser),
667 increment_(increment),
672 virtual void Output(std::ostream &out) const;
678 CYForInInitialiser *initialiser_;
682 CYForIn(CYForInInitialiser *initialiser, CYExpression *set, CYStatement *code) :
683 initialiser_(initialiser),
689 virtual void Output(std::ostream &out) const;
696 CYExpression *value_;
698 CYProperty(CYName *name, CYExpression *value, CYProperty *next) :
699 CYNext<CYProperty>(next),
705 virtual void Output(std::ostream &out) const;
711 CYProperty *property_;
713 CYObject(CYProperty *property) :
718 void Output(std::ostream &out, CYFlags flags) const;
727 CYCatch(CYIdentifier *name, CYStatement *code) :
733 virtual void Output(std::ostream &out) const;
740 CYArgument *arguments_;
742 CYSend(CYExpression *self, CYArgument *arguments) :
744 arguments_(arguments)
750 virtual void Output(std::ostream &out, CYFlags flags) const;
756 CYExpression *object_;
757 CYExpression *property_;
759 CYMember(CYExpression *object, CYExpression *property) :
767 virtual void Output(std::ostream &out, CYFlags flags) const;
773 CYExpression *constructor_;
774 CYArgument *arguments_;
776 CYNew(CYExpression *constructor, CYArgument *arguments) :
777 constructor_(constructor),
778 arguments_(arguments)
784 virtual void Output(std::ostream &out, CYFlags flags) const;
790 CYExpression *function_;
791 CYArgument *arguments_;
793 CYCall(CYExpression *function, CYArgument *arguments) :
795 arguments_(arguments)
801 virtual void Output(std::ostream &out, CYFlags flags) const;
811 CYIf(CYExpression *test, CYStatement *_true, CYStatement *_false) :
818 virtual void Output(std::ostream &out) const;
827 CYDoWhile(CYExpression *test, CYStatement *code) :
833 virtual void Output(std::ostream &out) const;
842 CYWhile(CYExpression *test, CYStatement *code) :
848 virtual void Output(std::ostream &out) const;
855 CYFunctionParameter *parameters_;
858 CYLambda(CYIdentifier *name, CYFunctionParameter *parameters, CYSource *body) :
860 parameters_(parameters),
867 virtual void Output(std::ostream &out, CYFlags flags) const;
874 CYFunction(CYIdentifier *name, CYFunctionParameter *parameters, CYSource *body) :
875 CYLambda(name, parameters, body)
879 virtual void Output(std::ostream &out) const;
885 CYExpression *expression_;
887 CYExpress(CYExpression *expression) :
888 expression_(expression)
892 virtual void Output(std::ostream &out) const;
898 CYIdentifier *label_;
900 CYContinue(CYIdentifier *label) :
905 virtual void Output(std::ostream &out) const;
911 CYIdentifier *label_;
913 CYBreak(CYIdentifier *label) :
918 virtual void Output(std::ostream &out) const;
924 CYExpression *value_;
926 CYReturn(CYExpression *value) :
931 virtual void Output(std::ostream &out) const;
937 virtual void Output(std::ostream &out) const;
938 virtual void Output(std::ostream &out, bool block) const;
946 CYStatement *finally_;
948 CYTry(CYStatement *_try, CYCatch *_catch, CYStatement *finally) :
955 virtual void Output(std::ostream &out) const;
961 CYExpression *value_;
963 CYThrow(CYExpression *value) :
968 virtual void Output(std::ostream &out) const;
974 CYExpression *scope_;
977 CYWith(CYExpression *scope, CYStatement *code) :
983 virtual void Output(std::ostream &out) const;
989 CYExpression *value_;
992 CYSwitch(CYExpression *value, CYClause *clauses) :
998 virtual void Output(std::ostream &out) const;
1001 struct CYCondition :
1004 CYExpression *test_;
1005 CYExpression *true_;
1006 CYExpression *false_;
1008 CYCondition(CYExpression *test, CYExpression *_true, CYExpression *_false) :
1017 virtual void Output(std::ostream &out, CYFlags flags) const;
1020 struct CYAddressOf :
1023 CYAddressOf(CYExpression *rhs) :
1028 virtual const char *Operator() const {
1035 virtual void Output(std::ostream &out, CYFlags flags) const;
1041 CYIndirect(CYExpression *rhs) :
1046 virtual const char *Operator() const {
1053 virtual void Output(std::ostream &out, CYFlags flags) const;
1056 #define CYPostfix_(op, name) \
1057 struct CY ## name : \
1060 CY ## name(CYExpression *lhs) : \
1067 virtual const char *Operator() const { \
1072 #define CYPrefix_(alphabetic, op, name) \
1073 struct CY ## name : \
1076 CY ## name(CYExpression *rhs) : \
1081 CYAlphabetic(alphabetic) \
1084 virtual const char *Operator() const { \
1089 #define CYInfix_(alphabetic, precedence, op, name) \
1090 struct CY ## name : \
1093 CY ## name(CYExpression *lhs, CYExpression *rhs) : \
1098 CYAlphabetic(alphabetic) \
1099 CYPrecedence(precedence) \
1101 virtual const char *Operator() const { \
1106 #define CYAssignment_(op, name) \
1107 struct CY ## name ## Assign : \
1110 CY ## name ## Assign(CYExpression *lhs, CYExpression *rhs) : \
1111 CYAssignment(lhs, rhs) \
1117 virtual const char *Operator() const { \
1122 CYPostfix_("++", PostIncrement)
1123 CYPostfix_("--", PostDecrement)
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)
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)
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)
1171 #endif/*CYPARSER_HPP*/