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 :
156 struct CYExpression :
157 CYNext<CYExpression>,
161 virtual unsigned Precedence() const = 0;
162 virtual void Part(std::ostream &out) const;
163 virtual void Output(std::ostream &out) const = 0;
164 void Output(std::ostream &out, unsigned precedence) const;
166 virtual const char *Word() const {
171 #define CYPrecedence(value) \
172 virtual unsigned Precedence() const { \
179 CYExpression *expressions_;
181 CYCompound(CYExpression *expressions) :
182 expressions_(expressions)
186 void AddPrev(CYExpression *expression) {
187 CYExpression *last(expression);
188 while (last->next_ != NULL)
190 last->SetNext(expressions_);
191 expressions_ = expression;
196 void Output(std::ostream &out) const;
205 struct CYSelectorPart :
206 CYNext<CYSelectorPart>
211 CYSelectorPart(CYWord *name, bool value, CYSelectorPart *next) :
212 CYNext<CYSelectorPart>(next),
218 virtual void Output(std::ostream &out) const;
224 CYSelectorPart *name_;
226 CYSelector(CYSelectorPart *name) :
233 virtual void Output(std::ostream &out) const;
240 CYRange(uint64_t lo, uint64_t hi) :
245 bool operator [](uint8_t value) const {
246 return !(value >> 7) && (value >> 6 ? hi_ : lo_) >> (value & 0x3f) & 0x1;
249 void operator()(uint8_t value) {
252 (value >> 6 ? hi_ : lo_) |= uint64_t(0x1) << (value & 0x3f);
256 extern CYRange WordStartRange_;
257 extern CYRange WordEndRange_;
266 CYString(const char *value, size_t size) :
272 CYString(const CYIdentifier *identifier) :
273 value_(identifier->Value()),
274 size_(strlen(value_))
278 const char *Value() const {
282 virtual const char *Name() const {
286 virtual const char *Word() const {
287 if (size_ == 0 || !WordStartRange_[value_[0]])
289 for (size_t i(1); i != size_; ++i)
290 if (!WordEndRange_[value_[i]])
295 virtual void Output(std::ostream &out) const;
304 CYNumber(double value) :
309 double Value() const {
313 virtual const char *Name() const {
317 virtual void Output(std::ostream &out) const;
329 virtual void Output(std::ostream &out) const;
343 virtual void Output(std::ostream &out) const;
349 virtual bool Value() const = 0;
350 virtual void Output(std::ostream &out) const;
362 virtual bool Value() const {
376 virtual bool Value() const {
386 CYVariable(CYIdentifier *name) :
393 virtual void Output(std::ostream &out) const;
401 CYPrefix(CYExpression *rhs) :
406 virtual const char *Operator() const = 0;
408 virtual void Output(std::ostream &out) const;
417 CYInfix(CYExpression *lhs, CYExpression *rhs) :
423 virtual const char *Operator() const = 0;
425 virtual void Output(std::ostream &out) const;
433 CYPostfix(CYExpression *lhs) :
438 virtual const char *Operator() const = 0;
440 virtual void Output(std::ostream &out) const;
443 struct CYAssignment :
449 CYAssignment(CYExpression *lhs, CYExpression *rhs) :
455 virtual const char *Operator() const = 0;
457 virtual void Output(std::ostream &out) const;
464 CYExpression *value_;
466 CYArgument(CYWord *name, CYExpression *value, CYArgument *next = NULL) :
467 CYNext<CYArgument>(next),
473 void Output(std::ostream &out) const;
492 CYClause(CYExpression *_case, CYStatement *code) :
498 virtual void Output(std::ostream &out) const;
504 CYExpression *value_;
506 CYElement(CYExpression *value, CYElement *next) :
507 CYNext<CYElement>(next),
512 void Output(std::ostream &out) const;
518 CYElement *elements_;
520 CYArray(CYElement *elements) :
525 virtual void Output(std::ostream &out) const;
528 struct CYDeclaration :
532 CYIdentifier *identifier_;
533 CYExpression *initialiser_;
535 CYDeclaration(CYIdentifier *identifier, CYExpression *initialiser) :
536 identifier_(identifier),
537 initialiser_(initialiser)
541 virtual void Part(std::ostream &out) const;
542 virtual void Output(std::ostream &out) const;
545 struct CYDeclarations :
549 CYDeclaration *declaration_;
550 CYDeclarations *next_;
552 CYDeclarations(CYDeclaration *declaration, CYDeclarations *next) :
553 declaration_(declaration),
558 virtual void Part(std::ostream &out) const;
559 virtual void Output(std::ostream &out) const;
568 CYParameter(CYIdentifier *name, CYParameter *next) :
569 CYNext<CYParameter>(next),
574 virtual void Output(std::ostream &out) const;
580 CYForInitialiser *initialiser_;
582 CYExpression *increment_;
585 CYFor(CYForInitialiser *initialiser, CYExpression *test, CYExpression *increment, CYStatement *code) :
586 initialiser_(initialiser),
588 increment_(increment),
593 virtual void Output(std::ostream &out) const;
599 CYForInInitialiser *initialiser_;
603 CYForIn(CYForInInitialiser *initialiser, CYExpression *set, CYStatement *code) :
604 initialiser_(initialiser),
610 virtual void Output(std::ostream &out) const;
617 CYExpression *value_;
619 CYProperty(CYName *name, CYExpression *value, CYProperty *next) :
620 CYNext<CYProperty>(next),
626 virtual void Output(std::ostream &out) const;
632 CYProperty *property_;
634 CYObject(CYProperty *property) :
639 void Output(std::ostream &out) const;
648 CYCatch(CYIdentifier *name, CYStatement *code) :
654 virtual void Output(std::ostream &out) const;
661 CYArgument *arguments_;
663 CYMessage(CYExpression *self, CYArgument *arguments) :
665 arguments_(arguments)
671 virtual void Output(std::ostream &out) const;
677 CYExpression *object_;
678 CYExpression *property_;
680 CYMember(CYExpression *object, CYExpression *property) :
688 virtual void Output(std::ostream &out) const;
694 CYExpression *constructor_;
695 CYArgument *arguments_;
697 CYNew(CYExpression *constructor, CYArgument *arguments) :
698 constructor_(constructor),
699 arguments_(arguments)
705 virtual void Output(std::ostream &out) const;
711 CYExpression *function_;
712 CYArgument *arguments_;
714 CYCall(CYExpression *function, CYArgument *arguments) :
716 arguments_(arguments)
722 virtual void Output(std::ostream &out) const;
732 CYIf(CYExpression *test, CYStatement *_true, CYStatement *_false) :
739 virtual void Output(std::ostream &out) const;
748 CYDoWhile(CYExpression *test, CYStatement *code) :
754 virtual void Output(std::ostream &out) const;
763 CYWhile(CYExpression *test, CYStatement *code) :
769 virtual void Output(std::ostream &out) const;
776 CYParameter *parameters_;
779 CYLambda(CYIdentifier *name, CYParameter *parameters, CYSource *body) :
781 parameters_(parameters),
788 virtual void Output(std::ostream &out) const;
795 CYFunction(CYIdentifier *name, CYParameter *parameters, CYSource *body) :
796 CYLambda(name, parameters, body)
800 virtual void Output(std::ostream &out) const;
806 CYExpression *expression_;
808 CYExpress(CYExpression *expression) :
809 expression_(expression)
813 virtual void Output(std::ostream &out) const;
819 CYIdentifier *label_;
821 CYContinue(CYIdentifier *label) :
826 virtual void Output(std::ostream &out) const;
832 CYIdentifier *label_;
834 CYBreak(CYIdentifier *label) :
839 virtual void Output(std::ostream &out) const;
845 CYExpression *value_;
847 CYReturn(CYExpression *value) :
852 virtual void Output(std::ostream &out) const;
858 virtual void Output(std::ostream &out) const;
859 virtual void Output(std::ostream &out, bool block) const;
867 CYStatement *finally_;
869 CYTry(CYStatement *_try, CYCatch *_catch, CYStatement *finally) :
876 virtual void Output(std::ostream &out) const;
882 CYExpression *value_;
884 CYThrow(CYExpression *value) :
889 virtual void Output(std::ostream &out) const;
895 CYExpression *scope_;
898 CYWith(CYExpression *scope, CYStatement *code) :
904 virtual void Output(std::ostream &out) const;
910 CYExpression *value_;
913 CYSwitch(CYExpression *value, CYClause *clauses) :
919 virtual void Output(std::ostream &out) const;
927 CYExpression *false_;
929 CYCondition(CYExpression *test, CYExpression *_true, CYExpression *_false) :
938 virtual void Output(std::ostream &out) const;
944 CYAddressOf(CYExpression *rhs) :
949 virtual const char *Operator() const {
955 virtual void Output(std::ostream &out) const;
961 CYIndirect(CYExpression *rhs) :
966 virtual const char *Operator() const {
972 virtual void Output(std::ostream &out) const;
975 #define CYPostfix_(op, name) \
976 struct CY ## name : \
979 CY ## name(CYExpression *lhs) : \
986 virtual const char *Operator() const { \
991 #define CYPrefix_(op, name) \
992 struct CY ## name : \
995 CY ## name(CYExpression *rhs) : \
1002 virtual const char *Operator() const { \
1007 #define CYInfix_(precedence, op, name) \
1008 struct CY ## name : \
1011 CY ## name(CYExpression *lhs, CYExpression *rhs) : \
1016 CYPrecedence(precedence) \
1018 virtual const char *Operator() const { \
1023 #define CYAssignment_(op, name) \
1024 struct CY ## name ## Assign : \
1027 CY ## name ## Assign(CYExpression *lhs, CYExpression *rhs) : \
1028 CYAssignment(lhs, rhs) \
1034 virtual const char *Operator() const { \
1039 CYPostfix_("++", PostIncrement)
1040 CYPostfix_("--", PostDecrement)
1042 CYPrefix_("delete", Delete)
1043 CYPrefix_("void", Void)
1044 CYPrefix_("typeof", TypeOf)
1045 CYPrefix_("++", PreIncrement)
1046 CYPrefix_("--", PreDecrement)
1047 CYPrefix_("-", Negate)
1048 CYPrefix_("~", BitwiseNot)
1049 CYPrefix_("!", LogicalNot)
1051 CYInfix_(5, "*", Multiply)
1052 CYInfix_(5, "/", Divide)
1053 CYInfix_(5, "%", Modulus)
1054 CYInfix_(6, "+", Add)
1055 CYInfix_(6, "-", Subtract)
1056 CYInfix_(7, "<<", ShiftLeft)
1057 CYInfix_(7, ">>", ShiftRightSigned)
1058 CYInfix_(7, ">>>", ShiftRightUnsigned)
1059 CYInfix_(8, "<", Less)
1060 CYInfix_(8, ">", Greater)
1061 CYInfix_(8, "<=", LessOrEqual)
1062 CYInfix_(8, ">=", GreaterOrEqual)
1063 CYInfix_(8, "instanceof", InstanceOf)
1064 CYInfix_(8, "in", In)
1065 CYInfix_(9, "==", Equal)
1066 CYInfix_(9, "!=", NotEqual)
1067 CYInfix_(9, "===", Identical)
1068 CYInfix_(9, "!==", NotIdentical)
1069 CYInfix_(10, "&", BitwiseAnd)
1070 CYInfix_(11, "^", BitwiseXOr)
1071 CYInfix_(12, "|", BitwiseOr)
1072 CYInfix_(13, "&&", LogicalAnd)
1073 CYInfix_(14, "||", LogicalOr)
1075 CYAssignment_("=", )
1076 CYAssignment_("*=", Multiply)
1077 CYAssignment_("/=", Divide)
1078 CYAssignment_("%=", Modulus)
1079 CYAssignment_("+=", Add)
1080 CYAssignment_("-=", Subtract)
1081 CYAssignment_("<<=", ShiftLeft)
1082 CYAssignment_(">>=", ShiftRightSigned)
1083 CYAssignment_(">>>=", ShiftRightUnsigned)
1084 CYAssignment_("&=", BitwiseAnd)
1085 CYAssignment_("^=", BitwiseXOr)
1086 CYAssignment_("|=", BitwiseOr)
1088 #endif/*CYPARSER_HPP*/