11 template <typename Type_>
20 void SetNext(Type_ *next) {
26 virtual void Output(std::ostream &out) const = 0;
29 _finline std::ostream &operator <<(std::ostream &out, const CYThing &rhs) {
35 virtual void Part(std::ostream &out) const = 0;
41 virtual void Show(std::ostream &out) const;
42 virtual void Output(std::ostream &out) const = 0;
43 virtual void Output(std::ostream &out, bool block) const;
49 virtual const char *Name() const = 0;
57 CYWord(const char *word) :
62 const char *Value() const {
66 virtual const char *Name() const {
70 virtual void Output(std::ostream &out) const;
76 CYIdentifier(const char *word) :
83 CYIdentifier *identifier_;
86 CYLabel(CYIdentifier *identifier, CYLabel *next) :
87 identifier_(identifier),
98 void AddLabel(CYIdentifier *identifier) {
99 label_ = new CYLabel(identifier, label_);
119 std::string filename_;
122 cy::location location_;
123 std::string message_;
126 typedef std::vector<Error> Errors;
133 void ScannerDestroy();
136 CYDriver(const std::string &filename);
140 struct CYForInitialiser :
145 struct CYForInInitialiser :
150 struct CYExpression :
151 CYNext<CYExpression>,
155 virtual void Part(std::ostream &out) const;
156 virtual void Output(std::ostream &out) const = 0;
157 void Output(std::ostream &out, bool raw) const;
160 _finline std::ostream &operator <<(std::ostream &out, const CYExpression &rhs) {
161 rhs.Output(out, false);
177 CYSelector(CYWord *name, bool value, CYSelector *after) :
184 virtual void Output(std::ostream &out) const;
194 CYString(const char *value, size_t size) :
200 CYString(const CYIdentifier *identifier) :
201 value_(identifier->Value()),
202 size_(strlen(value_))
206 const char *Value() const {
210 virtual const char *Name() const {
214 virtual void Output(std::ostream &out) const;
223 CYNumber(double value) :
228 double Value() const {
232 virtual const char *Name() const {
236 virtual void Output(std::ostream &out) const;
248 virtual void Output(std::ostream &out) const;
260 virtual void Output(std::ostream &out) const;
266 virtual bool Value() const = 0;
267 virtual void Output(std::ostream &out) const;
279 virtual bool Value() const {
293 virtual bool Value() const {
303 CYVariable(CYIdentifier *name) :
308 virtual void Output(std::ostream &out) const;
316 CYPrefix(CYExpression *rhs) :
321 virtual const char *Operator() const = 0;
323 virtual void Output(std::ostream &out) const;
332 CYInfix(CYExpression *lhs, CYExpression *rhs) :
338 virtual const char *Operator() const = 0;
340 virtual void Output(std::ostream &out) const;
348 CYPostfix(CYExpression *lhs) :
353 virtual const char *Operator() const = 0;
355 virtual void Output(std::ostream &out) const;
358 struct CYAssignment :
361 CYAssignment(CYExpression *lhs, CYExpression *rhs) :
366 virtual const char *Operator() const = 0;
371 CYExpression *value_;
374 CYArgument(CYWord *name, CYExpression *value, CYArgument *next = NULL) :
381 void Output(std::ostream &out, bool send) const;
400 CYClause(CYExpression *_case, CYStatement *code) :
406 virtual void Output(std::ostream &out) const;
410 CYExpression *value_;
413 CYElement(CYExpression *value, CYElement *next) :
419 void Output(std::ostream &out) const;
425 CYElement *elements_;
427 CYArray(CYElement *elements) :
432 virtual void Output(std::ostream &out) const;
435 struct CYDeclaration :
439 CYIdentifier *identifier_;
440 CYExpression *initialiser_;
442 CYDeclaration(CYIdentifier *identifier, CYExpression *initialiser) :
443 identifier_(identifier),
444 initialiser_(initialiser)
448 virtual void Part(std::ostream &out) const;
449 virtual void Output(std::ostream &out) const;
452 struct CYDeclarations :
456 CYDeclaration *declaration_;
457 CYDeclarations *next_;
459 CYDeclarations(CYDeclaration *declaration, CYDeclarations *next) :
460 declaration_(declaration),
465 virtual void Part(std::ostream &out) const;
466 virtual void Output(std::ostream &out) const;
475 CYParameter(CYIdentifier *name, CYParameter *next) :
481 virtual void Output(std::ostream &out) const;
487 CYForInitialiser *initialiser_;
489 CYExpression *increment_;
492 CYFor(CYForInitialiser *initialiser, CYExpression *test, CYExpression *increment, CYStatement *code) :
493 initialiser_(initialiser),
495 increment_(increment),
500 virtual void Output(std::ostream &out) const;
506 CYForInInitialiser *initialiser_;
510 CYForIn(CYForInInitialiser *initialiser, CYExpression *set, CYStatement *code) :
511 initialiser_(initialiser),
517 virtual void Output(std::ostream &out) const;
522 CYExpression *value_;
525 CYProperty(CYName *name, CYExpression *value, CYProperty *next) :
532 virtual void Output(std::ostream &out) const;
538 CYProperty *property_;
540 CYObject(CYProperty *property) :
545 void Output(std::ostream &out) const;
554 CYCatch(CYIdentifier *name, CYStatement *code) :
560 virtual void Output(std::ostream &out) const;
567 CYArgument *arguments_;
569 CYMessage(CYExpression *self, CYArgument *arguments) :
571 arguments_(arguments)
575 virtual void Output(std::ostream &out) const;
581 CYExpression *object_;
582 CYExpression *property_;
584 CYMember(CYExpression *object, CYExpression *property) :
590 virtual void Output(std::ostream &out) const;
596 CYExpression *constructor_;
597 CYArgument *arguments_;
599 CYNew(CYExpression *constructor, CYArgument *arguments) :
600 constructor_(constructor),
601 arguments_(arguments)
605 virtual void Output(std::ostream &out) const;
611 CYExpression *function_;
612 CYArgument *arguments_;
614 CYCall(CYExpression *function, CYArgument *arguments) :
616 arguments_(arguments)
620 virtual void Output(std::ostream &out) const;
630 CYIf(CYExpression *test, CYStatement *_true, CYStatement *_false) :
637 virtual void Output(std::ostream &out) const;
646 CYDoWhile(CYExpression *test, CYStatement *code) :
652 virtual void Output(std::ostream &out) const;
661 CYWhile(CYExpression *test, CYStatement *code) :
667 virtual void Output(std::ostream &out) const;
674 CYParameter *parameters_;
677 CYLambda(CYIdentifier *name, CYParameter *parameters, CYSource *body) :
679 parameters_(parameters),
684 virtual void Output(std::ostream &out) const;
691 CYFunction(CYIdentifier *name, CYParameter *parameters, CYSource *body) :
692 CYLambda(name, parameters, body)
696 virtual void Output(std::ostream &out) const;
702 CYExpression *expression_;
704 CYExpress(CYExpression *expression) :
705 expression_(expression)
709 virtual void Output(std::ostream &out) const;
715 CYIdentifier *label_;
717 CYContinue(CYIdentifier *label) :
722 virtual void Output(std::ostream &out) const;
728 CYIdentifier *label_;
730 CYBreak(CYIdentifier *label) :
735 virtual void Output(std::ostream &out) const;
741 CYExpression *value_;
743 CYReturn(CYExpression *value) :
748 virtual void Output(std::ostream &out) const;
754 virtual void Output(std::ostream &out) const;
755 virtual void Output(std::ostream &out, bool block) const;
763 CYStatement *finally_;
765 CYTry(CYStatement *_try, CYCatch *_catch, CYStatement *finally) :
772 virtual void Output(std::ostream &out) const;
778 CYExpression *value_;
780 CYThrow(CYExpression *value) :
785 virtual void Output(std::ostream &out) const;
791 CYExpression *scope_;
794 CYWith(CYExpression *scope, CYStatement *code) :
800 virtual void Output(std::ostream &out) const;
806 CYExpression *value_;
809 CYSwitch(CYExpression *value, CYClause *clauses) :
815 virtual void Output(std::ostream &out) const;
823 CYExpression *false_;
825 CYCondition(CYExpression *test, CYExpression *_true, CYExpression *_false) :
831 virtual void Output(std::ostream &out) const;
837 CYAddressOf(CYExpression *rhs) :
842 virtual const char *Operator() const {
846 virtual void Output(std::ostream &out) const;
852 CYIndirect(CYExpression *rhs) :
857 virtual const char *Operator() const {
861 virtual void Output(std::ostream &out) const;
864 #define CYPostfix_(op, name) \
865 struct CY ## name : \
868 CY ## name(CYExpression *lhs) : \
873 virtual const char *Operator() const { \
878 #define CYPrefix_(op, name) \
879 struct CY ## name : \
882 CY ## name(CYExpression *rhs) : \
887 virtual const char *Operator() const { \
892 #define CYInfix_(op, name) \
893 struct CY ## name : \
896 CY ## name(CYExpression *lhs, CYExpression *rhs) : \
901 virtual const char *Operator() const { \
906 #define CYAssignment_(op, name) \
907 struct CY ## name ## Assign : \
910 CY ## name ## Assign(CYExpression *lhs, CYExpression *rhs) : \
911 CYAssignment(lhs, rhs) \
915 virtual const char *Operator() const { \
920 CYPostfix_("++", PostIncrement)
921 CYPostfix_("--", PostDecrement)
923 CYPrefix_("delete", Delete)
924 CYPrefix_("void", Void)
925 CYPrefix_("typeof", TypeOf)
926 CYPrefix_("++", PreIncrement)
927 CYPrefix_("--", PreDecrement)
928 CYPrefix_("-", Negate)
929 CYPrefix_("~", BitwiseNot)
930 CYPrefix_("!", LogicalNot)
932 CYInfix_("*", Multiply)
933 CYInfix_("/", Divide)
934 CYInfix_("%", Modulus)
936 CYInfix_("-", Subtract)
937 CYInfix_("<<", ShiftLeft)
938 CYInfix_(">>", ShiftRightSigned)
939 CYInfix_(">>>", ShiftRightUnsigned)
941 CYInfix_(">", Greater)
942 CYInfix_("<=", LessOrEqual)
943 CYInfix_(">=", GreaterOrEqual)
944 CYInfix_("instanceof", InstanceOf)
946 CYInfix_("==", Equal)
947 CYInfix_("!=", NotEqual)
948 CYInfix_("===", Identical)
949 CYInfix_("!==", NotIdentical)
950 CYInfix_("&", BitwiseAnd)
951 CYInfix_("^", BitwiseXOr)
952 CYInfix_("|", BitwiseOr)
953 CYInfix_("&&", LogicalAnd)
954 CYInfix_("||", LogicalOr)
957 CYAssignment_("*=", Multiply)
958 CYAssignment_("/=", Divide)
959 CYAssignment_("%=", Modulus)
960 CYAssignment_("+=", Add)
961 CYAssignment_("-=", Subtract)
962 CYAssignment_("<<=", ShiftLeft)
963 CYAssignment_(">>=", ShiftRightSigned)
964 CYAssignment_(">>>=", ShiftRightUnsigned)
965 CYAssignment_("&=", BitwiseAnd)
966 CYAssignment_("^=", BitwiseXOr)
967 CYAssignment_("|=", BitwiseOr)
969 #endif/*CYPARSER_HPP*/