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 :
158 CYNoBrace = (1 << 0),
159 CYNoFunction = (1 << 1),
160 CYNoLeader = (1 << 2),
161 CYNoTrailer = (1 << 3),
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;
225 struct CYSelectorPart :
226 CYNext<CYSelectorPart>
231 CYSelectorPart(CYWord *name, bool value, CYSelectorPart *next) :
232 CYNext<CYSelectorPart>(next),
238 virtual void Output(std::ostream &out) const;
244 CYSelectorPart *name_;
246 CYSelector(CYSelectorPart *name) :
253 virtual void Output(std::ostream &out, CYFlags flags) const;
260 CYRange(uint64_t lo, uint64_t hi) :
265 bool operator [](uint8_t value) const {
266 return !(value >> 7) && (value >> 6 ? hi_ : lo_) >> (value & 0x3f) & 0x1;
269 void operator()(uint8_t value) {
272 (value >> 6 ? hi_ : lo_) |= uint64_t(0x1) << (value & 0x3f);
276 extern CYRange WordStartRange_;
277 extern CYRange WordEndRange_;
286 CYString(const char *value, size_t size) :
292 CYString(const CYIdentifier *identifier) :
293 value_(identifier->Value()),
294 size_(strlen(value_))
298 const char *Value() const {
302 virtual const char *Name() const {
306 virtual const char *Word() const {
307 if (size_ == 0 || !WordStartRange_[value_[0]])
309 for (size_t i(1); i != size_; ++i)
310 if (!WordEndRange_[value_[i]])
315 virtual void Output(std::ostream &out) const {
316 return Output(out, CYNoFlags);
319 virtual void Output(std::ostream &out, CYFlags flags) const;
328 CYNumber(double value) :
333 double Value() const {
337 virtual const char *Name() const {
341 virtual void Output(std::ostream &out) const {
342 return Output(out, CYNoFlags);
345 virtual void Output(std::ostream &out, CYFlags flags) const;
357 virtual void Output(std::ostream &out, CYFlags flags) const;
369 virtual void Output(std::ostream &out, CYFlags flags) const;
375 virtual bool Value() const = 0;
376 virtual void Output(std::ostream &out, CYFlags flags) const;
388 virtual bool Value() const;
400 virtual bool Value() const;
408 CYVariable(CYIdentifier *name) :
415 virtual void Output(std::ostream &out, CYFlags flags) const;
423 CYPrefix(CYExpression *rhs) :
428 virtual bool Alphabetic() const = 0;
429 virtual const char *Operator() const = 0;
431 virtual void Output(std::ostream &out, CYFlags flags) const;
440 CYInfix(CYExpression *lhs, CYExpression *rhs) :
446 virtual bool Alphabetic() const = 0;
447 virtual const char *Operator() const = 0;
449 virtual void Output(std::ostream &out, CYFlags flags) const;
457 CYPostfix(CYExpression *lhs) :
462 virtual const char *Operator() const = 0;
464 virtual void Output(std::ostream &out, CYFlags flags) const;
467 struct CYAssignment :
473 CYAssignment(CYExpression *lhs, CYExpression *rhs) :
479 virtual const char *Operator() const = 0;
481 virtual void Output(std::ostream &out, CYFlags flags) const;
488 CYExpression *value_;
490 CYArgument(CYWord *name, CYExpression *value, CYArgument *next = NULL) :
491 CYNext<CYArgument>(next),
497 void Output(std::ostream &out) const;
516 CYClause(CYExpression *_case, CYStatement *code) :
522 virtual void Output(std::ostream &out) const;
528 CYExpression *value_;
530 CYElement(CYExpression *value, CYElement *next) :
531 CYNext<CYElement>(next),
536 void Output(std::ostream &out) const;
542 CYElement *elements_;
544 CYArray(CYElement *elements) :
549 virtual void Output(std::ostream &out, CYFlags flags) const;
552 struct CYDeclaration :
556 CYIdentifier *identifier_;
557 CYExpression *initialiser_;
559 CYDeclaration(CYIdentifier *identifier, CYExpression *initialiser) :
560 identifier_(identifier),
561 initialiser_(initialiser)
565 virtual void Part(std::ostream &out) const;
566 virtual void Output(std::ostream &out) const;
569 struct CYDeclarations :
573 CYDeclaration *declaration_;
574 CYDeclarations *next_;
576 CYDeclarations(CYDeclaration *declaration, CYDeclarations *next) :
577 declaration_(declaration),
582 virtual void Part(std::ostream &out) const;
583 virtual void Output(std::ostream &out) const;
589 virtual void Output(std::ostream &out) const;
592 struct CYMessageParameter :
593 CYNext<CYMessageParameter>
599 CYMessageParameter(CYWord *tag, CYExpression *type, CYIdentifier *name) :
612 CYMessageParameter *parameter_;
615 CYMessage(bool instance, CYExpression *type, CYMessageParameter *parameter, CYSource *body) :
618 parameter_(parameter),
623 virtual void Output(std::ostream &out) const;
630 CYExpression *super_;
632 CYMessage *messages_;
634 CYClass(CYIdentifier *name, CYExpression *super, CYField *fields, CYMessage *messages) :
642 virtual void Output(std::ostream &out) const;
645 struct CYFunctionParameter :
646 CYNext<CYFunctionParameter>,
651 CYFunctionParameter(CYIdentifier *name, CYFunctionParameter *next) :
652 CYNext<CYFunctionParameter>(next),
657 virtual void Output(std::ostream &out) const;
663 CYForInitialiser *initialiser_;
665 CYExpression *increment_;
668 CYFor(CYForInitialiser *initialiser, CYExpression *test, CYExpression *increment, CYStatement *code) :
669 initialiser_(initialiser),
671 increment_(increment),
676 virtual void Output(std::ostream &out) const;
682 CYForInInitialiser *initialiser_;
686 CYForIn(CYForInInitialiser *initialiser, CYExpression *set, CYStatement *code) :
687 initialiser_(initialiser),
693 virtual void Output(std::ostream &out) const;
700 CYExpression *value_;
702 CYProperty(CYName *name, CYExpression *value, CYProperty *next) :
703 CYNext<CYProperty>(next),
709 virtual void Output(std::ostream &out) const;
715 CYProperty *property_;
717 CYObject(CYProperty *property) :
722 void Output(std::ostream &out, CYFlags flags) const;
731 CYCatch(CYIdentifier *name, CYStatement *code) :
737 virtual void Output(std::ostream &out) const;
744 CYArgument *arguments_;
746 CYSend(CYExpression *self, CYArgument *arguments) :
748 arguments_(arguments)
754 virtual void Output(std::ostream &out, CYFlags flags) const;
760 CYExpression *object_;
761 CYExpression *property_;
763 CYMember(CYExpression *object, CYExpression *property) :
771 virtual void Output(std::ostream &out, CYFlags flags) const;
777 CYExpression *constructor_;
778 CYArgument *arguments_;
780 CYNew(CYExpression *constructor, CYArgument *arguments) :
781 constructor_(constructor),
782 arguments_(arguments)
788 virtual void Output(std::ostream &out, CYFlags flags) const;
794 CYExpression *function_;
795 CYArgument *arguments_;
797 CYCall(CYExpression *function, CYArgument *arguments) :
799 arguments_(arguments)
805 virtual void Output(std::ostream &out, CYFlags flags) const;
815 CYIf(CYExpression *test, CYStatement *_true, CYStatement *_false) :
822 virtual void Output(std::ostream &out) const;
831 CYDoWhile(CYExpression *test, CYStatement *code) :
837 virtual void Output(std::ostream &out) const;
846 CYWhile(CYExpression *test, CYStatement *code) :
852 virtual void Output(std::ostream &out) const;
859 CYFunctionParameter *parameters_;
862 CYLambda(CYIdentifier *name, CYFunctionParameter *parameters, CYSource *body) :
864 parameters_(parameters),
871 virtual void Output(std::ostream &out, CYFlags flags) const;
878 CYFunction(CYIdentifier *name, CYFunctionParameter *parameters, CYSource *body) :
879 CYLambda(name, parameters, body)
883 virtual void Output(std::ostream &out) const;
889 CYExpression *expression_;
891 CYExpress(CYExpression *expression) :
892 expression_(expression)
896 virtual void Output(std::ostream &out) const;
902 CYIdentifier *label_;
904 CYContinue(CYIdentifier *label) :
909 virtual void Output(std::ostream &out) const;
915 CYIdentifier *label_;
917 CYBreak(CYIdentifier *label) :
922 virtual void Output(std::ostream &out) const;
928 CYExpression *value_;
930 CYReturn(CYExpression *value) :
935 virtual void Output(std::ostream &out) const;
941 virtual void Output(std::ostream &out) const;
942 virtual void Output(std::ostream &out, bool block) const;
950 CYStatement *finally_;
952 CYTry(CYStatement *_try, CYCatch *_catch, CYStatement *finally) :
959 virtual void Output(std::ostream &out) const;
965 CYExpression *value_;
967 CYThrow(CYExpression *value) :
972 virtual void Output(std::ostream &out) const;
978 CYExpression *scope_;
981 CYWith(CYExpression *scope, CYStatement *code) :
987 virtual void Output(std::ostream &out) const;
993 CYExpression *value_;
996 CYSwitch(CYExpression *value, CYClause *clauses) :
1002 virtual void Output(std::ostream &out) const;
1005 struct CYCondition :
1008 CYExpression *test_;
1009 CYExpression *true_;
1010 CYExpression *false_;
1012 CYCondition(CYExpression *test, CYExpression *_true, CYExpression *_false) :
1021 virtual void Output(std::ostream &out, CYFlags flags) const;
1024 struct CYAddressOf :
1027 CYAddressOf(CYExpression *rhs) :
1032 virtual const char *Operator() const {
1039 virtual void Output(std::ostream &out, CYFlags flags) const;
1045 CYIndirect(CYExpression *rhs) :
1050 virtual const char *Operator() const {
1057 virtual void Output(std::ostream &out, CYFlags flags) const;
1060 #define CYPostfix_(op, name) \
1061 struct CY ## name : \
1064 CY ## name(CYExpression *lhs) : \
1071 virtual const char *Operator() const { \
1076 #define CYPrefix_(alphabetic, op, name) \
1077 struct CY ## name : \
1080 CY ## name(CYExpression *rhs) : \
1085 CYAlphabetic(alphabetic) \
1088 virtual const char *Operator() const { \
1093 #define CYInfix_(alphabetic, precedence, op, name) \
1094 struct CY ## name : \
1097 CY ## name(CYExpression *lhs, CYExpression *rhs) : \
1102 CYAlphabetic(alphabetic) \
1103 CYPrecedence(precedence) \
1105 virtual const char *Operator() const { \
1110 #define CYAssignment_(op, name) \
1111 struct CY ## name ## Assign : \
1114 CY ## name ## Assign(CYExpression *lhs, CYExpression *rhs) : \
1115 CYAssignment(lhs, rhs) \
1121 virtual const char *Operator() const { \
1126 CYPostfix_("++", PostIncrement)
1127 CYPostfix_("--", PostDecrement)
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)
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)
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)
1175 #endif/*CYPARSER_HPP*/