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_);
112 std::string filename_;
113 std::vector<CYSource *> source_;
118 void ScannerDestroy();
121 CYDriver(const std::string &filename);
127 struct CYForInitialiser :
132 struct CYForInInitialiser :
137 struct CYExpression :
138 CYNext<CYExpression>,
142 virtual void Part(std::ostream &out) const;
143 virtual void Output(std::ostream &out) const = 0;
144 void Output(std::ostream &out, bool raw) const;
147 _finline std::ostream &operator <<(std::ostream &out, const CYExpression &rhs) {
148 rhs.Output(out, false);
164 CYString(const char *value, size_t size) :
170 CYString(const CYIdentifier *identifier) :
171 value_(identifier->Value()),
172 size_(strlen(value_))
176 const char *Value() const {
180 virtual const char *Name() const {
184 virtual void Output(std::ostream &out) const;
193 CYNumber(double value) :
198 double Value() const {
202 virtual const char *Name() const {
206 virtual void Output(std::ostream &out) const;
218 virtual void Output(std::ostream &out) const;
230 virtual void Output(std::ostream &out) const;
236 virtual bool Value() const = 0;
237 virtual void Output(std::ostream &out) const;
249 virtual bool Value() const {
263 virtual bool Value() const {
273 CYVariable(CYIdentifier *name) :
278 virtual void Output(std::ostream &out) const;
286 CYPrefix(CYExpression *rhs) :
291 virtual const char *Operator() const = 0;
293 virtual void Output(std::ostream &out) const;
302 CYInfix(CYExpression *lhs, CYExpression *rhs) :
308 virtual const char *Operator() const = 0;
310 virtual void Output(std::ostream &out) const;
318 CYPostfix(CYExpression *lhs) :
323 virtual const char *Operator() const = 0;
325 virtual void Output(std::ostream &out) const;
328 struct CYAssignment :
331 CYAssignment(CYExpression *lhs, CYExpression *rhs) :
336 virtual const char *Operator() const = 0;
341 CYExpression *value_;
344 CYArgument(CYWord *name, CYExpression *value, CYArgument *next = NULL) :
351 void Output(std::ostream &out, bool send) const;
370 CYClause(CYExpression *_case, CYStatement *code) :
376 virtual void Output(std::ostream &out) const;
382 CYExpression *value_;
385 CYElement(CYExpression *value, CYElement *next) :
391 void Output(std::ostream &out, bool raw) const;
392 virtual void Output(std::ostream &out) const;
395 struct CYDeclaration :
399 CYIdentifier *identifier_;
400 CYExpression *initialiser_;
402 CYDeclaration(CYIdentifier *identifier, CYExpression *initialiser) :
403 identifier_(identifier),
404 initialiser_(initialiser)
408 virtual void Part(std::ostream &out) const;
409 virtual void Output(std::ostream &out) const;
412 struct CYDeclarations :
416 CYDeclaration *declaration_;
417 CYDeclarations *next_;
419 CYDeclarations(CYDeclaration *declaration, CYDeclarations *next) :
420 declaration_(declaration),
425 virtual void Part(std::ostream &out) const;
426 virtual void Output(std::ostream &out) const;
435 CYParameter(CYIdentifier *name, CYParameter *next) :
441 virtual void Output(std::ostream &out) const;
447 CYForInitialiser *initialiser_;
449 CYExpression *increment_;
452 CYFor(CYForInitialiser *initialiser, CYExpression *test, CYExpression *increment, CYStatement *code) :
453 initialiser_(initialiser),
455 increment_(increment),
460 virtual void Output(std::ostream &out) const;
466 CYForInInitialiser *initialiser_;
470 CYForIn(CYForInInitialiser *initialiser, CYExpression *set, CYStatement *code) :
471 initialiser_(initialiser),
477 virtual void Output(std::ostream &out) const;
482 CYExpression *value_;
485 CYProperty(CYName *name, CYExpression *value, CYProperty *next) :
492 virtual void Output(std::ostream &out) const;
498 CYProperty *property_;
500 CYObject(CYProperty *property) :
505 void Output(std::ostream &out) const;
514 CYCatch(CYIdentifier *name, CYStatement *code) :
520 virtual void Output(std::ostream &out) const;
527 CYArgument *arguments_;
529 CYMessage(CYExpression *self, CYArgument *arguments) :
531 arguments_(arguments)
535 virtual void Output(std::ostream &out) const;
541 CYExpression *object_;
542 CYExpression *property_;
544 CYMember(CYExpression *object, CYExpression *property) :
550 virtual void Output(std::ostream &out) const;
556 CYExpression *constructor_;
557 CYArgument *arguments_;
559 CYNew(CYExpression *constructor, CYArgument *arguments) :
560 constructor_(constructor),
561 arguments_(arguments)
565 virtual void Output(std::ostream &out) const;
571 CYExpression *function_;
572 CYArgument *arguments_;
574 CYCall(CYExpression *function, CYArgument *arguments) :
576 arguments_(arguments)
580 virtual void Output(std::ostream &out) const;
590 CYIf(CYExpression *test, CYStatement *_true, CYStatement *_false) :
597 virtual void Output(std::ostream &out) const;
606 CYDoWhile(CYExpression *test, CYStatement *code) :
612 virtual void Output(std::ostream &out) const;
621 CYWhile(CYExpression *test, CYStatement *code) :
627 virtual void Output(std::ostream &out) const;
634 CYParameter *parameters_;
637 CYLambda(CYIdentifier *name, CYParameter *parameters, CYSource *body) :
639 parameters_(parameters),
644 virtual void Output(std::ostream &out) const;
651 CYFunction(CYIdentifier *name, CYParameter *parameters, CYSource *body) :
652 CYLambda(name, parameters, body)
656 virtual void Output(std::ostream &out) const;
662 CYExpression *expression_;
664 CYExpress(CYExpression *expression) :
665 expression_(expression)
669 virtual void Output(std::ostream &out) const;
675 CYIdentifier *label_;
677 CYContinue(CYIdentifier *label) :
682 virtual void Output(std::ostream &out) const;
688 CYIdentifier *label_;
690 CYBreak(CYIdentifier *label) :
695 virtual void Output(std::ostream &out) const;
701 CYExpression *value_;
703 CYReturn(CYExpression *value) :
708 virtual void Output(std::ostream &out) const;
714 virtual void Output(std::ostream &out) const;
715 virtual void Output(std::ostream &out, bool block) const;
723 CYStatement *finally_;
725 CYTry(CYStatement *_try, CYCatch *_catch, CYStatement *finally) :
732 virtual void Output(std::ostream &out) const;
738 CYExpression *value_;
740 CYThrow(CYExpression *value) :
745 virtual void Output(std::ostream &out) const;
751 CYExpression *scope_;
754 CYWith(CYExpression *scope, CYStatement *code) :
760 virtual void Output(std::ostream &out) const;
766 CYExpression *value_;
769 CYSwitch(CYExpression *value, CYClause *clauses) :
775 virtual void Output(std::ostream &out) const;
783 CYExpression *false_;
785 CYCondition(CYExpression *test, CYExpression *_true, CYExpression *_false) :
791 virtual void Output(std::ostream &out) const;
797 CYAddressOf(CYExpression *rhs) :
802 virtual const char *Operator() const {
806 virtual void Output(std::ostream &out) const;
812 CYIndirect(CYExpression *rhs) :
817 virtual const char *Operator() const {
821 virtual void Output(std::ostream &out) const;
824 #define CYPostfix_(op, name) \
825 struct CY ## name : \
828 CY ## name(CYExpression *lhs) : \
833 virtual const char *Operator() const { \
838 #define CYPrefix_(op, name) \
839 struct CY ## name : \
842 CY ## name(CYExpression *rhs) : \
847 virtual const char *Operator() const { \
852 #define CYInfix_(op, name) \
853 struct CY ## name : \
856 CY ## name(CYExpression *lhs, CYExpression *rhs) : \
861 virtual const char *Operator() const { \
866 #define CYAssignment_(op, name) \
867 struct CY ## name ## Assign : \
870 CY ## name ## Assign(CYExpression *lhs, CYExpression *rhs) : \
871 CYAssignment(lhs, rhs) \
875 virtual const char *Operator() const { \
880 CYPostfix_("++", PostIncrement)
881 CYPostfix_("--", PostDecrement)
883 CYPrefix_("delete", Delete)
884 CYPrefix_("void", Void)
885 CYPrefix_("typeof", TypeOf)
886 CYPrefix_("++", PreIncrement)
887 CYPrefix_("--", PreDecrement)
888 CYPrefix_("-", Negate)
889 CYPrefix_("~", BitwiseNot)
890 CYPrefix_("!", LogicalNot)
892 CYInfix_("*", Multiply)
893 CYInfix_("/", Divide)
894 CYInfix_("%", Modulus)
896 CYInfix_("-", Subtract)
897 CYInfix_("<<", ShiftLeft)
898 CYInfix_(">>", ShiftRightSigned)
899 CYInfix_(">>>", ShiftRightUnsigned)
901 CYInfix_(">", Greater)
902 CYInfix_("<=", LessOrEqual)
903 CYInfix_(">=", GreaterOrEqual)
904 CYInfix_("instanceof", InstanceOf)
906 CYInfix_("==", Equal)
907 CYInfix_("!=", NotEqual)
908 CYInfix_("===", Identical)
909 CYInfix_("!==", NotIdentical)
910 CYInfix_("&", BitwiseAnd)
911 CYInfix_("^", BitwiseXOr)
912 CYInfix_("|", BitwiseOr)
913 CYInfix_("&&", LogicalAnd)
914 CYInfix_("||", LogicalOr)
917 CYAssignment_("*=", Multiply)
918 CYAssignment_("/=", Divide)
919 CYAssignment_("%=", Modulus)
920 CYAssignment_("+=", Add)
921 CYAssignment_("-=", Subtract)
922 CYAssignment_("<<=", ShiftLeft)
923 CYAssignment_(">>=", ShiftRightSigned)
924 CYAssignment_(">>>=", ShiftRightUnsigned)
925 CYAssignment_("&=", BitwiseAnd)
926 CYAssignment_("^=", BitwiseXOr)
927 CYAssignment_("|=", BitwiseOr)
929 #endif/*CYPARSER_HPP*/