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) {
40 virtual void Part(std::ostream &out) const = 0;
46 virtual void Show(std::ostream &out) const;
47 virtual void Output(std::ostream &out) const = 0;
48 virtual void Output(std::ostream &out, bool block) const;
54 virtual const char *Name() const = 0;
62 CYWord(const char *word) :
67 const char *Value() const {
71 virtual const char *Name() const {
75 virtual void Output(std::ostream &out) const;
81 CYIdentifier(const char *word) :
90 CYIdentifier *identifier_;
92 CYLabel(CYIdentifier *identifier, CYLabel *next) :
93 CYNext<CYLabel>(next),
94 identifier_(identifier)
104 void AddLabel(CYIdentifier *identifier) {
105 label_ = new CYLabel(identifier, label_);
125 std::string filename_;
128 cy::location location_;
129 std::string message_;
132 typedef std::vector<Error> Errors;
139 void ScannerDestroy();
142 CYDriver(const std::string &filename);
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;
167 #define CYPrecedence(value) \
168 virtual unsigned Precedence() const { \
175 CYExpression *expressions_;
177 CYCompound(CYExpression *expressions) :
178 expressions_(expressions)
182 void AddPrev(CYExpression *expression) {
183 CYExpression *last(expression);
184 while (last->next_ != NULL)
186 last->SetNext(expressions_);
187 expressions_ = expression;
192 void Output(std::ostream &out) const;
201 struct CYSelectorPart :
202 CYNext<CYSelectorPart>
207 CYSelectorPart(CYWord *name, bool value, CYSelectorPart *next) :
208 CYNext<CYSelectorPart>(next),
214 virtual void Output(std::ostream &out) const;
220 CYSelectorPart *name_;
222 CYSelector(CYSelectorPart *name) :
227 virtual void Output(std::ostream &out) const;
237 CYString(const char *value, size_t size) :
243 CYString(const CYIdentifier *identifier) :
244 value_(identifier->Value()),
245 size_(strlen(value_))
249 const char *Value() const {
253 virtual const char *Name() const {
257 virtual void Output(std::ostream &out) const;
266 CYNumber(double value) :
271 double Value() const {
275 virtual const char *Name() const {
279 virtual void Output(std::ostream &out) const;
291 virtual void Output(std::ostream &out) const;
305 virtual void Output(std::ostream &out) const;
311 virtual bool Value() const = 0;
312 virtual void Output(std::ostream &out) const;
324 virtual bool Value() const {
338 virtual bool Value() const {
348 CYVariable(CYIdentifier *name) :
355 virtual void Output(std::ostream &out) const;
363 CYPrefix(CYExpression *rhs) :
368 virtual const char *Operator() const = 0;
370 virtual void Output(std::ostream &out) const;
379 CYInfix(CYExpression *lhs, CYExpression *rhs) :
385 virtual const char *Operator() const = 0;
387 virtual void Output(std::ostream &out) const;
395 CYPostfix(CYExpression *lhs) :
400 virtual const char *Operator() const = 0;
402 virtual void Output(std::ostream &out) const;
405 struct CYAssignment :
411 CYAssignment(CYExpression *lhs, CYExpression *rhs) :
417 virtual const char *Operator() const = 0;
419 virtual void Output(std::ostream &out) const;
426 CYExpression *value_;
428 CYArgument(CYWord *name, CYExpression *value, CYArgument *next = NULL) :
429 CYNext<CYArgument>(next),
435 void Output(std::ostream &out) const;
454 CYClause(CYExpression *_case, CYStatement *code) :
460 virtual void Output(std::ostream &out) const;
466 CYExpression *value_;
468 CYElement(CYExpression *value, CYElement *next) :
469 CYNext<CYElement>(next),
474 void Output(std::ostream &out) const;
480 CYElement *elements_;
482 CYArray(CYElement *elements) :
487 virtual void Output(std::ostream &out) const;
490 struct CYDeclaration :
494 CYIdentifier *identifier_;
495 CYExpression *initialiser_;
497 CYDeclaration(CYIdentifier *identifier, CYExpression *initialiser) :
498 identifier_(identifier),
499 initialiser_(initialiser)
503 virtual void Part(std::ostream &out) const;
504 virtual void Output(std::ostream &out) const;
507 struct CYDeclarations :
511 CYDeclaration *declaration_;
512 CYDeclarations *next_;
514 CYDeclarations(CYDeclaration *declaration, CYDeclarations *next) :
515 declaration_(declaration),
520 virtual void Part(std::ostream &out) const;
521 virtual void Output(std::ostream &out) const;
530 CYParameter(CYIdentifier *name, CYParameter *next) :
531 CYNext<CYParameter>(next),
536 virtual void Output(std::ostream &out) const;
542 CYForInitialiser *initialiser_;
544 CYExpression *increment_;
547 CYFor(CYForInitialiser *initialiser, CYExpression *test, CYExpression *increment, CYStatement *code) :
548 initialiser_(initialiser),
550 increment_(increment),
555 virtual void Output(std::ostream &out) const;
561 CYForInInitialiser *initialiser_;
565 CYForIn(CYForInInitialiser *initialiser, CYExpression *set, CYStatement *code) :
566 initialiser_(initialiser),
572 virtual void Output(std::ostream &out) const;
579 CYExpression *value_;
581 CYProperty(CYName *name, CYExpression *value, CYProperty *next) :
582 CYNext<CYProperty>(next),
588 virtual void Output(std::ostream &out) const;
594 CYProperty *property_;
596 CYObject(CYProperty *property) :
601 void Output(std::ostream &out) const;
610 CYCatch(CYIdentifier *name, CYStatement *code) :
616 virtual void Output(std::ostream &out) const;
623 CYArgument *arguments_;
625 CYMessage(CYExpression *self, CYArgument *arguments) :
627 arguments_(arguments)
633 virtual void Output(std::ostream &out) const;
639 CYExpression *object_;
640 CYExpression *property_;
642 CYMember(CYExpression *object, CYExpression *property) :
650 virtual void Output(std::ostream &out) const;
656 CYExpression *constructor_;
657 CYArgument *arguments_;
659 CYNew(CYExpression *constructor, CYArgument *arguments) :
660 constructor_(constructor),
661 arguments_(arguments)
667 virtual void Output(std::ostream &out) const;
673 CYExpression *function_;
674 CYArgument *arguments_;
676 CYCall(CYExpression *function, CYArgument *arguments) :
678 arguments_(arguments)
684 virtual void Output(std::ostream &out) const;
694 CYIf(CYExpression *test, CYStatement *_true, CYStatement *_false) :
701 virtual void Output(std::ostream &out) const;
710 CYDoWhile(CYExpression *test, CYStatement *code) :
716 virtual void Output(std::ostream &out) const;
725 CYWhile(CYExpression *test, CYStatement *code) :
731 virtual void Output(std::ostream &out) const;
738 CYParameter *parameters_;
741 CYLambda(CYIdentifier *name, CYParameter *parameters, CYSource *body) :
743 parameters_(parameters),
750 virtual void Output(std::ostream &out) const;
757 CYFunction(CYIdentifier *name, CYParameter *parameters, CYSource *body) :
758 CYLambda(name, parameters, body)
762 virtual void Output(std::ostream &out) const;
768 CYExpression *expression_;
770 CYExpress(CYExpression *expression) :
771 expression_(expression)
775 virtual void Output(std::ostream &out) const;
781 CYIdentifier *label_;
783 CYContinue(CYIdentifier *label) :
788 virtual void Output(std::ostream &out) const;
794 CYIdentifier *label_;
796 CYBreak(CYIdentifier *label) :
801 virtual void Output(std::ostream &out) const;
807 CYExpression *value_;
809 CYReturn(CYExpression *value) :
814 virtual void Output(std::ostream &out) const;
820 virtual void Output(std::ostream &out) const;
821 virtual void Output(std::ostream &out, bool block) const;
829 CYStatement *finally_;
831 CYTry(CYStatement *_try, CYCatch *_catch, CYStatement *finally) :
838 virtual void Output(std::ostream &out) const;
844 CYExpression *value_;
846 CYThrow(CYExpression *value) :
851 virtual void Output(std::ostream &out) const;
857 CYExpression *scope_;
860 CYWith(CYExpression *scope, CYStatement *code) :
866 virtual void Output(std::ostream &out) const;
872 CYExpression *value_;
875 CYSwitch(CYExpression *value, CYClause *clauses) :
881 virtual void Output(std::ostream &out) const;
889 CYExpression *false_;
891 CYCondition(CYExpression *test, CYExpression *_true, CYExpression *_false) :
899 virtual void Output(std::ostream &out) const;
905 CYAddressOf(CYExpression *rhs) :
910 virtual const char *Operator() const {
916 virtual void Output(std::ostream &out) const;
922 CYIndirect(CYExpression *rhs) :
927 virtual const char *Operator() const {
933 virtual void Output(std::ostream &out) const;
936 #define CYPostfix_(op, name) \
937 struct CY ## name : \
940 CY ## name(CYExpression *lhs) : \
947 virtual const char *Operator() const { \
952 #define CYPrefix_(op, name) \
953 struct CY ## name : \
956 CY ## name(CYExpression *rhs) : \
963 virtual const char *Operator() const { \
968 #define CYInfix_(precedence, op, name) \
969 struct CY ## name : \
972 CY ## name(CYExpression *lhs, CYExpression *rhs) : \
977 CYPrecedence(precedence) \
979 virtual const char *Operator() const { \
984 #define CYAssignment_(op, name) \
985 struct CY ## name ## Assign : \
988 CY ## name ## Assign(CYExpression *lhs, CYExpression *rhs) : \
989 CYAssignment(lhs, rhs) \
995 virtual const char *Operator() const { \
1000 CYPostfix_("++", PostIncrement)
1001 CYPostfix_("--", PostDecrement)
1003 CYPrefix_("delete", Delete)
1004 CYPrefix_("void", Void)
1005 CYPrefix_("typeof", TypeOf)
1006 CYPrefix_("++", PreIncrement)
1007 CYPrefix_("--", PreDecrement)
1008 CYPrefix_("-", Negate)
1009 CYPrefix_("~", BitwiseNot)
1010 CYPrefix_("!", LogicalNot)
1012 CYInfix_(5, "*", Multiply)
1013 CYInfix_(5, "/", Divide)
1014 CYInfix_(5, "%", Modulus)
1015 CYInfix_(6, "+", Add)
1016 CYInfix_(6, "-", Subtract)
1017 CYInfix_(7, "<<", ShiftLeft)
1018 CYInfix_(7, ">>", ShiftRightSigned)
1019 CYInfix_(7, ">>>", ShiftRightUnsigned)
1020 CYInfix_(8, "<", Less)
1021 CYInfix_(8, ">", Greater)
1022 CYInfix_(8, "<=", LessOrEqual)
1023 CYInfix_(8, ">=", GreaterOrEqual)
1024 CYInfix_(8, "instanceof", InstanceOf)
1025 CYInfix_(8, "in", In)
1026 CYInfix_(9, "==", Equal)
1027 CYInfix_(9, "!=", NotEqual)
1028 CYInfix_(9, "===", Identical)
1029 CYInfix_(9, "!==", NotIdentical)
1030 CYInfix_(10, "&", BitwiseAnd)
1031 CYInfix_(11, "^", BitwiseXOr)
1032 CYInfix_(12, "|", BitwiseOr)
1033 CYInfix_(13, "&&", LogicalAnd)
1034 CYInfix_(14, "||", LogicalOr)
1036 CYAssignment_("=", )
1037 CYAssignment_("*=", Multiply)
1038 CYAssignment_("/=", Divide)
1039 CYAssignment_("%=", Modulus)
1040 CYAssignment_("+=", Add)
1041 CYAssignment_("-=", Subtract)
1042 CYAssignment_("<<=", ShiftLeft)
1043 CYAssignment_(">>=", ShiftRightSigned)
1044 CYAssignment_(">>>=", ShiftRightUnsigned)
1045 CYAssignment_("&=", BitwiseAnd)
1046 CYAssignment_("^=", BitwiseXOr)
1047 CYAssignment_("|=", BitwiseOr)
1049 #endif/*CYPARSER_HPP*/