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 void Part(std::ostream &out) const;
162 virtual void Output(std::ostream &out) const = 0;
163 void Output(std::ostream &out, bool raw) const;
166 _finline std::ostream &operator <<(std::ostream &out, const CYExpression &rhs) {
167 rhs.Output(out, false);
176 struct CYSelectorPart :
177 CYNext<CYSelectorPart>
182 CYSelectorPart(CYWord *name, bool value, CYSelectorPart *next) :
183 CYNext<CYSelectorPart>(next),
189 virtual void Output(std::ostream &out) const;
195 CYSelectorPart *name_;
197 CYSelector(CYSelectorPart *name) :
202 virtual void Output(std::ostream &out) const;
212 CYString(const char *value, size_t size) :
218 CYString(const CYIdentifier *identifier) :
219 value_(identifier->Value()),
220 size_(strlen(value_))
224 const char *Value() const {
228 virtual const char *Name() const {
232 virtual void Output(std::ostream &out) const;
241 CYNumber(double value) :
246 double Value() const {
250 virtual const char *Name() const {
254 virtual void Output(std::ostream &out) const;
266 virtual void Output(std::ostream &out) const;
278 virtual void Output(std::ostream &out) const;
284 virtual bool Value() const = 0;
285 virtual void Output(std::ostream &out) const;
297 virtual bool Value() const {
311 virtual bool Value() const {
321 CYVariable(CYIdentifier *name) :
326 virtual void Output(std::ostream &out) const;
334 CYPrefix(CYExpression *rhs) :
339 virtual const char *Operator() const = 0;
341 virtual void Output(std::ostream &out) const;
350 CYInfix(CYExpression *lhs, CYExpression *rhs) :
356 virtual const char *Operator() const = 0;
358 virtual void Output(std::ostream &out) const;
366 CYPostfix(CYExpression *lhs) :
371 virtual const char *Operator() const = 0;
373 virtual void Output(std::ostream &out) const;
376 struct CYAssignment :
379 CYAssignment(CYExpression *lhs, CYExpression *rhs) :
384 virtual const char *Operator() const = 0;
391 CYExpression *value_;
393 CYArgument(CYWord *name, CYExpression *value, CYArgument *next = NULL) :
394 CYNext<CYArgument>(next),
400 void Output(std::ostream &out, bool send) const;
419 CYClause(CYExpression *_case, CYStatement *code) :
425 virtual void Output(std::ostream &out) const;
431 CYExpression *value_;
433 CYElement(CYExpression *value, CYElement *next) :
434 CYNext<CYElement>(next),
439 void Output(std::ostream &out) const;
445 CYElement *elements_;
447 CYArray(CYElement *elements) :
452 virtual void Output(std::ostream &out) const;
455 struct CYDeclaration :
459 CYIdentifier *identifier_;
460 CYExpression *initialiser_;
462 CYDeclaration(CYIdentifier *identifier, CYExpression *initialiser) :
463 identifier_(identifier),
464 initialiser_(initialiser)
468 virtual void Part(std::ostream &out) const;
469 virtual void Output(std::ostream &out) const;
472 struct CYDeclarations :
476 CYDeclaration *declaration_;
477 CYDeclarations *next_;
479 CYDeclarations(CYDeclaration *declaration, CYDeclarations *next) :
480 declaration_(declaration),
485 virtual void Part(std::ostream &out) const;
486 virtual void Output(std::ostream &out) const;
495 CYParameter(CYIdentifier *name, CYParameter *next) :
496 CYNext<CYParameter>(next),
501 virtual void Output(std::ostream &out) const;
507 CYForInitialiser *initialiser_;
509 CYExpression *increment_;
512 CYFor(CYForInitialiser *initialiser, CYExpression *test, CYExpression *increment, CYStatement *code) :
513 initialiser_(initialiser),
515 increment_(increment),
520 virtual void Output(std::ostream &out) const;
526 CYForInInitialiser *initialiser_;
530 CYForIn(CYForInInitialiser *initialiser, CYExpression *set, CYStatement *code) :
531 initialiser_(initialiser),
537 virtual void Output(std::ostream &out) const;
544 CYExpression *value_;
546 CYProperty(CYName *name, CYExpression *value, CYProperty *next) :
547 CYNext<CYProperty>(next),
553 virtual void Output(std::ostream &out) const;
559 CYProperty *property_;
561 CYObject(CYProperty *property) :
566 void Output(std::ostream &out) const;
575 CYCatch(CYIdentifier *name, CYStatement *code) :
581 virtual void Output(std::ostream &out) const;
588 CYArgument *arguments_;
590 CYMessage(CYExpression *self, CYArgument *arguments) :
592 arguments_(arguments)
596 virtual void Output(std::ostream &out) const;
602 CYExpression *object_;
603 CYExpression *property_;
605 CYMember(CYExpression *object, CYExpression *property) :
611 virtual void Output(std::ostream &out) const;
617 CYExpression *constructor_;
618 CYArgument *arguments_;
620 CYNew(CYExpression *constructor, CYArgument *arguments) :
621 constructor_(constructor),
622 arguments_(arguments)
626 virtual void Output(std::ostream &out) const;
632 CYExpression *function_;
633 CYArgument *arguments_;
635 CYCall(CYExpression *function, CYArgument *arguments) :
637 arguments_(arguments)
641 virtual void Output(std::ostream &out) const;
651 CYIf(CYExpression *test, CYStatement *_true, CYStatement *_false) :
658 virtual void Output(std::ostream &out) const;
667 CYDoWhile(CYExpression *test, CYStatement *code) :
673 virtual void Output(std::ostream &out) const;
682 CYWhile(CYExpression *test, CYStatement *code) :
688 virtual void Output(std::ostream &out) const;
695 CYParameter *parameters_;
698 CYLambda(CYIdentifier *name, CYParameter *parameters, CYSource *body) :
700 parameters_(parameters),
705 virtual void Output(std::ostream &out) const;
712 CYFunction(CYIdentifier *name, CYParameter *parameters, CYSource *body) :
713 CYLambda(name, parameters, body)
717 virtual void Output(std::ostream &out) const;
723 CYExpression *expression_;
725 CYExpress(CYExpression *expression) :
726 expression_(expression)
730 virtual void Output(std::ostream &out) const;
736 CYIdentifier *label_;
738 CYContinue(CYIdentifier *label) :
743 virtual void Output(std::ostream &out) const;
749 CYIdentifier *label_;
751 CYBreak(CYIdentifier *label) :
756 virtual void Output(std::ostream &out) const;
762 CYExpression *value_;
764 CYReturn(CYExpression *value) :
769 virtual void Output(std::ostream &out) const;
775 virtual void Output(std::ostream &out) const;
776 virtual void Output(std::ostream &out, bool block) const;
784 CYStatement *finally_;
786 CYTry(CYStatement *_try, CYCatch *_catch, CYStatement *finally) :
793 virtual void Output(std::ostream &out) const;
799 CYExpression *value_;
801 CYThrow(CYExpression *value) :
806 virtual void Output(std::ostream &out) const;
812 CYExpression *scope_;
815 CYWith(CYExpression *scope, CYStatement *code) :
821 virtual void Output(std::ostream &out) const;
827 CYExpression *value_;
830 CYSwitch(CYExpression *value, CYClause *clauses) :
836 virtual void Output(std::ostream &out) const;
844 CYExpression *false_;
846 CYCondition(CYExpression *test, CYExpression *_true, CYExpression *_false) :
852 virtual void Output(std::ostream &out) const;
858 CYAddressOf(CYExpression *rhs) :
863 virtual const char *Operator() const {
867 virtual void Output(std::ostream &out) const;
873 CYIndirect(CYExpression *rhs) :
878 virtual const char *Operator() const {
882 virtual void Output(std::ostream &out) const;
885 #define CYPostfix_(op, name) \
886 struct CY ## name : \
889 CY ## name(CYExpression *lhs) : \
894 virtual const char *Operator() const { \
899 #define CYPrefix_(op, name) \
900 struct CY ## name : \
903 CY ## name(CYExpression *rhs) : \
908 virtual const char *Operator() const { \
913 #define CYInfix_(op, name) \
914 struct CY ## name : \
917 CY ## name(CYExpression *lhs, CYExpression *rhs) : \
922 virtual const char *Operator() const { \
927 #define CYAssignment_(op, name) \
928 struct CY ## name ## Assign : \
931 CY ## name ## Assign(CYExpression *lhs, CYExpression *rhs) : \
932 CYAssignment(lhs, rhs) \
936 virtual const char *Operator() const { \
941 CYPostfix_("++", PostIncrement)
942 CYPostfix_("--", PostDecrement)
944 CYPrefix_("delete", Delete)
945 CYPrefix_("void", Void)
946 CYPrefix_("typeof", TypeOf)
947 CYPrefix_("++", PreIncrement)
948 CYPrefix_("--", PreDecrement)
949 CYPrefix_("-", Negate)
950 CYPrefix_("~", BitwiseNot)
951 CYPrefix_("!", LogicalNot)
953 CYInfix_("*", Multiply)
954 CYInfix_("/", Divide)
955 CYInfix_("%", Modulus)
957 CYInfix_("-", Subtract)
958 CYInfix_("<<", ShiftLeft)
959 CYInfix_(">>", ShiftRightSigned)
960 CYInfix_(">>>", ShiftRightUnsigned)
962 CYInfix_(">", Greater)
963 CYInfix_("<=", LessOrEqual)
964 CYInfix_(">=", GreaterOrEqual)
965 CYInfix_("instanceof", InstanceOf)
967 CYInfix_("==", Equal)
968 CYInfix_("!=", NotEqual)
969 CYInfix_("===", Identical)
970 CYInfix_("!==", NotIdentical)
971 CYInfix_("&", BitwiseAnd)
972 CYInfix_("^", BitwiseXOr)
973 CYInfix_("|", BitwiseOr)
974 CYInfix_("&&", LogicalAnd)
975 CYInfix_("||", LogicalOr)
978 CYAssignment_("*=", Multiply)
979 CYAssignment_("/=", Divide)
980 CYAssignment_("%=", Modulus)
981 CYAssignment_("+=", Add)
982 CYAssignment_("-=", Subtract)
983 CYAssignment_("<<=", ShiftLeft)
984 CYAssignment_(">>=", ShiftRightSigned)
985 CYAssignment_(">>>=", ShiftRightUnsigned)
986 CYAssignment_("&=", BitwiseAnd)
987 CYAssignment_("^=", BitwiseXOr)
988 CYAssignment_("|=", BitwiseOr)
990 #endif/*CYPARSER_HPP*/