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_);
107 std::string filename_;
108 std::vector<CYSource *> source_;
113 void ScannerDestroy();
116 CYDriver(const std::string &filename);
122 struct CYForInitialiser :
127 struct CYForInInitialiser :
132 struct CYExpression :
133 CYNext<CYExpression>,
137 virtual void Part(std::ostream &out) const;
138 virtual void Output(std::ostream &out) const = 0;
139 void Output(std::ostream &out, bool raw) const;
142 _finline std::ostream &operator <<(std::ostream &out, const CYExpression &rhs) {
143 rhs.Output(out, false);
159 CYString(const char *value, size_t size) :
165 CYString(const CYIdentifier *identifier) :
166 value_(identifier->Value()),
167 size_(strlen(value_))
171 const char *Value() const {
175 virtual const char *Name() const {
179 virtual void Output(std::ostream &out) const;
188 CYNumber(double value) :
193 double Value() const {
197 virtual const char *Name() const {
201 virtual void Output(std::ostream &out) const;
213 virtual void Output(std::ostream &out) const;
225 virtual void Output(std::ostream &out) const;
231 virtual bool Value() const = 0;
232 virtual void Output(std::ostream &out) const;
244 virtual bool Value() const {
258 virtual bool Value() const {
268 CYVariable(CYIdentifier *name) :
273 virtual void Output(std::ostream &out) const;
281 CYPrefix(CYExpression *rhs) :
286 virtual const char *Operator() const = 0;
288 virtual void Output(std::ostream &out) const;
297 CYInfix(CYExpression *lhs, CYExpression *rhs) :
303 virtual const char *Operator() const = 0;
305 virtual void Output(std::ostream &out) const;
313 CYPostfix(CYExpression *lhs) :
318 virtual const char *Operator() const = 0;
320 virtual void Output(std::ostream &out) const;
323 struct CYAssignment :
326 CYAssignment(CYExpression *lhs, CYExpression *rhs) :
331 virtual const char *Operator() const = 0;
336 CYExpression *value_;
339 CYArgument(CYWord *name, CYExpression *value, CYArgument *next = NULL) :
346 void Output(std::ostream &out, bool send) const;
365 CYClause(CYExpression *_case, CYStatement *code) :
371 virtual void Output(std::ostream &out) const;
377 CYExpression *value_;
380 CYElement(CYExpression *value, CYElement *next) :
386 void Output(std::ostream &out, bool raw) const;
387 virtual void Output(std::ostream &out) const;
390 struct CYDeclaration :
394 CYIdentifier *identifier_;
395 CYExpression *initialiser_;
397 CYDeclaration(CYIdentifier *identifier, CYExpression *initialiser) :
398 identifier_(identifier),
399 initialiser_(initialiser)
403 virtual void Part(std::ostream &out) const;
404 virtual void Output(std::ostream &out) const;
407 struct CYDeclarations :
411 CYDeclaration *declaration_;
412 CYDeclarations *next_;
414 CYDeclarations(CYDeclaration *declaration, CYDeclarations *next) :
415 declaration_(declaration),
420 virtual void Part(std::ostream &out) const;
421 virtual void Output(std::ostream &out) const;
430 CYParameter(CYIdentifier *name, CYParameter *next) :
436 virtual void Output(std::ostream &out) const;
442 CYForInitialiser *initialiser_;
444 CYExpression *increment_;
447 CYFor(CYForInitialiser *initialiser, CYExpression *test, CYExpression *increment, CYStatement *code) :
448 initialiser_(initialiser),
450 increment_(increment),
455 virtual void Output(std::ostream &out) const;
461 CYForInInitialiser *initialiser_;
465 CYForIn(CYForInInitialiser *initialiser, CYExpression *set, CYStatement *code) :
466 initialiser_(initialiser),
472 virtual void Output(std::ostream &out) const;
479 CYExpression *value_;
482 CYProperty(CYName *name, CYExpression *value, CYProperty *next) :
489 void Output(std::ostream &out, bool raw) const;
490 virtual void Output(std::ostream &out) const;
499 CYCatch(CYIdentifier *name, CYStatement *code) :
505 virtual void Output(std::ostream &out) const;
512 CYArgument *arguments_;
514 CYMessage(CYExpression *self, CYArgument *arguments) :
516 arguments_(arguments)
520 virtual void Output(std::ostream &out) const;
526 CYExpression *object_;
527 CYExpression *property_;
529 CYMember(CYExpression *object, CYExpression *property) :
535 virtual void Output(std::ostream &out) const;
541 CYExpression *constructor_;
542 CYArgument *arguments_;
544 CYNew(CYExpression *constructor, CYArgument *arguments) :
545 constructor_(constructor),
546 arguments_(arguments)
550 virtual void Output(std::ostream &out) const;
556 CYExpression *function_;
557 CYArgument *arguments_;
559 CYCall(CYExpression *function, CYArgument *arguments) :
561 arguments_(arguments)
565 virtual void Output(std::ostream &out) const;
575 CYIf(CYExpression *test, CYStatement *_true, CYStatement *_false) :
582 virtual void Output(std::ostream &out) const;
591 CYDoWhile(CYExpression *test, CYStatement *code) :
597 virtual void Output(std::ostream &out) const;
606 CYWhile(CYExpression *test, CYStatement *code) :
612 virtual void Output(std::ostream &out) const;
619 CYParameter *parameters_;
622 CYLambda(CYIdentifier *name, CYParameter *parameters, CYSource *body) :
624 parameters_(parameters),
629 virtual void Output(std::ostream &out) const;
636 CYFunction(CYIdentifier *name, CYParameter *parameters, CYSource *body) :
637 CYLambda(name, parameters, body)
641 virtual void Output(std::ostream &out) const;
647 CYExpression *expression_;
649 CYExpress(CYExpression *expression) :
650 expression_(expression)
654 virtual void Output(std::ostream &out) const;
660 CYIdentifier *label_;
662 CYContinue(CYIdentifier *label) :
667 virtual void Output(std::ostream &out) const;
673 CYIdentifier *label_;
675 CYBreak(CYIdentifier *label) :
680 virtual void Output(std::ostream &out) const;
686 CYExpression *value_;
688 CYReturn(CYExpression *value) :
693 virtual void Output(std::ostream &out) const;
699 virtual void Output(std::ostream &out) const;
700 virtual void Output(std::ostream &out, bool block) const;
708 CYStatement *finally_;
710 CYTry(CYStatement *_try, CYCatch *_catch, CYStatement *finally) :
717 virtual void Output(std::ostream &out) const;
723 CYExpression *value_;
725 CYThrow(CYExpression *value) :
730 virtual void Output(std::ostream &out) const;
736 CYExpression *scope_;
739 CYWith(CYExpression *scope, CYStatement *code) :
745 virtual void Output(std::ostream &out) const;
751 CYExpression *value_;
754 CYSwitch(CYExpression *value, CYClause *clauses) :
760 virtual void Output(std::ostream &out) const;
768 CYExpression *false_;
770 CYCondition(CYExpression *test, CYExpression *_true, CYExpression *_false) :
776 virtual void Output(std::ostream &out) const;
782 CYAddressOf(CYExpression *rhs) :
787 virtual const char *Operator() const {
791 virtual void Output(std::ostream &out) const;
797 CYIndirect(CYExpression *rhs) :
802 virtual const char *Operator() const {
806 virtual void Output(std::ostream &out) const;
809 #define CYPostfix_(op, name) \
810 struct CY ## name : \
813 CY ## name(CYExpression *lhs) : \
818 virtual const char *Operator() const { \
823 #define CYPrefix_(op, name) \
824 struct CY ## name : \
827 CY ## name(CYExpression *rhs) : \
832 virtual const char *Operator() const { \
837 #define CYInfix_(op, name) \
838 struct CY ## name : \
841 CY ## name(CYExpression *lhs, CYExpression *rhs) : \
846 virtual const char *Operator() const { \
851 #define CYAssignment_(op, name) \
852 struct CY ## name ## Assign : \
855 CY ## name ## Assign(CYExpression *lhs, CYExpression *rhs) : \
856 CYAssignment(lhs, rhs) \
860 virtual const char *Operator() const { \
865 CYPostfix_("++", PostIncrement)
866 CYPostfix_("--", PostDecrement)
868 CYPrefix_("delete", Delete)
869 CYPrefix_("void", Void)
870 CYPrefix_("typeof", TypeOf)
871 CYPrefix_("++", PreIncrement)
872 CYPrefix_("--", PreDecrement)
873 CYPrefix_("-", Negate)
874 CYPrefix_("~", BitwiseNot)
875 CYPrefix_("!", LogicalNot)
877 CYInfix_("*", Multiply)
878 CYInfix_("/", Divide)
879 CYInfix_("%", Modulus)
881 CYInfix_("-", Subtract)
882 CYInfix_("<<", ShiftLeft)
883 CYInfix_(">>", ShiftRightSigned)
884 CYInfix_(">>>", ShiftRightUnsigned)
886 CYInfix_(">", Greater)
887 CYInfix_("<=", LessOrEqual)
888 CYInfix_(">=", GreaterOrEqual)
889 CYInfix_("instanceof", InstanceOf)
891 CYInfix_("==", Equal)
892 CYInfix_("!=", NotEqual)
893 CYInfix_("===", Identical)
894 CYInfix_("!==", NotIdentical)
895 CYInfix_("&", BitwiseAnd)
896 CYInfix_("^", BitwiseXOr)
897 CYInfix_("|", BitwiseOr)
898 CYInfix_("&&", LogicalAnd)
899 CYInfix_("||", LogicalOr)
902 CYAssignment_("*=", Multiply)
903 CYAssignment_("/=", Divide)
904 CYAssignment_("%=", Modulus)
905 CYAssignment_("+=", Add)
906 CYAssignment_("-=", Subtract)
907 CYAssignment_("<<=", ShiftLeft)
908 CYAssignment_(">>=", ShiftRightSigned)
909 CYAssignment_(">>>=", ShiftRightUnsigned)
910 CYAssignment_("&=", BitwiseAnd)
911 CYAssignment_("^=", BitwiseXOr)
912 CYAssignment_("|=", BitwiseOr)
914 #endif/*CYPARSER_HPP*/