10 template <typename Type_>
19 void SetNext(Type_ *next) {
25 virtual void Output(std::ostream &out) const = 0;
28 _finline std::ostream &operator <<(std::ostream &out, const CYThing &rhs) {
34 virtual void Part(std::ostream &out) const = 0;
40 virtual void Show(std::ostream &out) const;
41 virtual void Output(std::ostream &out) const = 0;
42 virtual void Output(std::ostream &out, bool block) const;
48 virtual const char *Name() const = 0;
56 CYWord(const char *word) :
61 const char *Value() const {
65 virtual const char *Name() const {
69 virtual void Output(std::ostream &out) const;
75 CYIdentifier(const char *word) :
82 CYIdentifier *identifier_;
85 CYLabel(CYIdentifier *identifier, CYLabel *next) :
86 identifier_(identifier),
97 void AddLabel(CYIdentifier *identifier) {
98 label_ = new CYLabel(identifier, label_);
118 std::string filename_;
120 std::vector<CYSource *> source_;
124 void ScannerDestroy();
127 CYDriver(const std::string &filename);
133 struct CYForInitialiser :
138 struct CYForInInitialiser :
143 struct CYExpression :
144 CYNext<CYExpression>,
148 virtual void Part(std::ostream &out) const;
149 virtual void Output(std::ostream &out) const = 0;
150 void Output(std::ostream &out, bool raw) const;
153 _finline std::ostream &operator <<(std::ostream &out, const CYExpression &rhs) {
154 rhs.Output(out, false);
170 CYSelector(CYWord *name, bool value, CYSelector *after) :
177 virtual void Output(std::ostream &out) const;
187 CYString(const char *value, size_t size) :
193 CYString(const CYIdentifier *identifier) :
194 value_(identifier->Value()),
195 size_(strlen(value_))
199 const char *Value() const {
203 virtual const char *Name() const {
207 virtual void Output(std::ostream &out) const;
216 CYNumber(double value) :
221 double Value() const {
225 virtual const char *Name() const {
229 virtual void Output(std::ostream &out) const;
241 virtual void Output(std::ostream &out) const;
253 virtual void Output(std::ostream &out) const;
259 virtual bool Value() const = 0;
260 virtual void Output(std::ostream &out) const;
272 virtual bool Value() const {
286 virtual bool Value() const {
296 CYVariable(CYIdentifier *name) :
301 virtual void Output(std::ostream &out) const;
309 CYPrefix(CYExpression *rhs) :
314 virtual const char *Operator() const = 0;
316 virtual void Output(std::ostream &out) const;
325 CYInfix(CYExpression *lhs, CYExpression *rhs) :
331 virtual const char *Operator() const = 0;
333 virtual void Output(std::ostream &out) const;
341 CYPostfix(CYExpression *lhs) :
346 virtual const char *Operator() const = 0;
348 virtual void Output(std::ostream &out) const;
351 struct CYAssignment :
354 CYAssignment(CYExpression *lhs, CYExpression *rhs) :
359 virtual const char *Operator() const = 0;
364 CYExpression *value_;
367 CYArgument(CYWord *name, CYExpression *value, CYArgument *next = NULL) :
374 void Output(std::ostream &out, bool send) const;
393 CYClause(CYExpression *_case, CYStatement *code) :
399 virtual void Output(std::ostream &out) const;
405 CYExpression *value_;
408 CYElement(CYExpression *value, CYElement *next) :
414 void Output(std::ostream &out, bool raw) const;
415 virtual void Output(std::ostream &out) const;
418 struct CYDeclaration :
422 CYIdentifier *identifier_;
423 CYExpression *initialiser_;
425 CYDeclaration(CYIdentifier *identifier, CYExpression *initialiser) :
426 identifier_(identifier),
427 initialiser_(initialiser)
431 virtual void Part(std::ostream &out) const;
432 virtual void Output(std::ostream &out) const;
435 struct CYDeclarations :
439 CYDeclaration *declaration_;
440 CYDeclarations *next_;
442 CYDeclarations(CYDeclaration *declaration, CYDeclarations *next) :
443 declaration_(declaration),
448 virtual void Part(std::ostream &out) const;
449 virtual void Output(std::ostream &out) const;
458 CYParameter(CYIdentifier *name, CYParameter *next) :
464 virtual void Output(std::ostream &out) const;
470 CYForInitialiser *initialiser_;
472 CYExpression *increment_;
475 CYFor(CYForInitialiser *initialiser, CYExpression *test, CYExpression *increment, CYStatement *code) :
476 initialiser_(initialiser),
478 increment_(increment),
483 virtual void Output(std::ostream &out) const;
489 CYForInInitialiser *initialiser_;
493 CYForIn(CYForInInitialiser *initialiser, CYExpression *set, CYStatement *code) :
494 initialiser_(initialiser),
500 virtual void Output(std::ostream &out) const;
505 CYExpression *value_;
508 CYProperty(CYName *name, CYExpression *value, CYProperty *next) :
515 virtual void Output(std::ostream &out) const;
521 CYProperty *property_;
523 CYObject(CYProperty *property) :
528 void Output(std::ostream &out) const;
537 CYCatch(CYIdentifier *name, CYStatement *code) :
543 virtual void Output(std::ostream &out) const;
550 CYArgument *arguments_;
552 CYMessage(CYExpression *self, CYArgument *arguments) :
554 arguments_(arguments)
558 virtual void Output(std::ostream &out) const;
564 CYExpression *object_;
565 CYExpression *property_;
567 CYMember(CYExpression *object, CYExpression *property) :
573 virtual void Output(std::ostream &out) const;
579 CYExpression *constructor_;
580 CYArgument *arguments_;
582 CYNew(CYExpression *constructor, CYArgument *arguments) :
583 constructor_(constructor),
584 arguments_(arguments)
588 virtual void Output(std::ostream &out) const;
594 CYExpression *function_;
595 CYArgument *arguments_;
597 CYCall(CYExpression *function, CYArgument *arguments) :
599 arguments_(arguments)
603 virtual void Output(std::ostream &out) const;
613 CYIf(CYExpression *test, CYStatement *_true, CYStatement *_false) :
620 virtual void Output(std::ostream &out) const;
629 CYDoWhile(CYExpression *test, CYStatement *code) :
635 virtual void Output(std::ostream &out) const;
644 CYWhile(CYExpression *test, CYStatement *code) :
650 virtual void Output(std::ostream &out) const;
657 CYParameter *parameters_;
660 CYLambda(CYIdentifier *name, CYParameter *parameters, CYSource *body) :
662 parameters_(parameters),
667 virtual void Output(std::ostream &out) const;
674 CYFunction(CYIdentifier *name, CYParameter *parameters, CYSource *body) :
675 CYLambda(name, parameters, body)
679 virtual void Output(std::ostream &out) const;
685 CYExpression *expression_;
687 CYExpress(CYExpression *expression) :
688 expression_(expression)
692 virtual void Output(std::ostream &out) const;
698 CYIdentifier *label_;
700 CYContinue(CYIdentifier *label) :
705 virtual void Output(std::ostream &out) const;
711 CYIdentifier *label_;
713 CYBreak(CYIdentifier *label) :
718 virtual void Output(std::ostream &out) const;
724 CYExpression *value_;
726 CYReturn(CYExpression *value) :
731 virtual void Output(std::ostream &out) const;
737 virtual void Output(std::ostream &out) const;
738 virtual void Output(std::ostream &out, bool block) const;
746 CYStatement *finally_;
748 CYTry(CYStatement *_try, CYCatch *_catch, CYStatement *finally) :
755 virtual void Output(std::ostream &out) const;
761 CYExpression *value_;
763 CYThrow(CYExpression *value) :
768 virtual void Output(std::ostream &out) const;
774 CYExpression *scope_;
777 CYWith(CYExpression *scope, CYStatement *code) :
783 virtual void Output(std::ostream &out) const;
789 CYExpression *value_;
792 CYSwitch(CYExpression *value, CYClause *clauses) :
798 virtual void Output(std::ostream &out) const;
806 CYExpression *false_;
808 CYCondition(CYExpression *test, CYExpression *_true, CYExpression *_false) :
814 virtual void Output(std::ostream &out) const;
820 CYAddressOf(CYExpression *rhs) :
825 virtual const char *Operator() const {
829 virtual void Output(std::ostream &out) const;
835 CYIndirect(CYExpression *rhs) :
840 virtual const char *Operator() const {
844 virtual void Output(std::ostream &out) const;
847 #define CYPostfix_(op, name) \
848 struct CY ## name : \
851 CY ## name(CYExpression *lhs) : \
856 virtual const char *Operator() const { \
861 #define CYPrefix_(op, name) \
862 struct CY ## name : \
865 CY ## name(CYExpression *rhs) : \
870 virtual const char *Operator() const { \
875 #define CYInfix_(op, name) \
876 struct CY ## name : \
879 CY ## name(CYExpression *lhs, CYExpression *rhs) : \
884 virtual const char *Operator() const { \
889 #define CYAssignment_(op, name) \
890 struct CY ## name ## Assign : \
893 CY ## name ## Assign(CYExpression *lhs, CYExpression *rhs) : \
894 CYAssignment(lhs, rhs) \
898 virtual const char *Operator() const { \
903 CYPostfix_("++", PostIncrement)
904 CYPostfix_("--", PostDecrement)
906 CYPrefix_("delete", Delete)
907 CYPrefix_("void", Void)
908 CYPrefix_("typeof", TypeOf)
909 CYPrefix_("++", PreIncrement)
910 CYPrefix_("--", PreDecrement)
911 CYPrefix_("-", Negate)
912 CYPrefix_("~", BitwiseNot)
913 CYPrefix_("!", LogicalNot)
915 CYInfix_("*", Multiply)
916 CYInfix_("/", Divide)
917 CYInfix_("%", Modulus)
919 CYInfix_("-", Subtract)
920 CYInfix_("<<", ShiftLeft)
921 CYInfix_(">>", ShiftRightSigned)
922 CYInfix_(">>>", ShiftRightUnsigned)
924 CYInfix_(">", Greater)
925 CYInfix_("<=", LessOrEqual)
926 CYInfix_(">=", GreaterOrEqual)
927 CYInfix_("instanceof", InstanceOf)
929 CYInfix_("==", Equal)
930 CYInfix_("!=", NotEqual)
931 CYInfix_("===", Identical)
932 CYInfix_("!==", NotIdentical)
933 CYInfix_("&", BitwiseAnd)
934 CYInfix_("^", BitwiseXOr)
935 CYInfix_("|", BitwiseOr)
936 CYInfix_("&&", LogicalAnd)
937 CYInfix_("||", LogicalOr)
940 CYAssignment_("*=", Multiply)
941 CYAssignment_("/=", Divide)
942 CYAssignment_("%=", Modulus)
943 CYAssignment_("+=", Add)
944 CYAssignment_("-=", Subtract)
945 CYAssignment_("<<=", ShiftLeft)
946 CYAssignment_(">>=", ShiftRightSigned)
947 CYAssignment_(">>>=", ShiftRightUnsigned)
948 CYAssignment_("&=", BitwiseAnd)
949 CYAssignment_("^=", BitwiseXOr)
950 CYAssignment_("|=", BitwiseOr)
952 #endif/*CYPARSER_HPP*/