9 template <typename Type_>
18 void SetNext(Type_ *next) {
24 virtual void Output(std::ostream &out) const = 0;
27 _finline std::ostream &operator <<(std::ostream &out, const CYThing &rhs) {
33 virtual void Part(std::ostream &out) const = 0;
40 virtual void Part(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_);
105 std::string filename_;
111 void ScannerDestroy();
114 CYDriver(const std::string &filename);
118 struct CYForInitialiser :
123 struct CYForInInitialiser :
128 struct CYExpression :
129 CYNext<CYExpression>,
133 virtual void Part(std::ostream &out) const;
134 virtual void Output(std::ostream &out) const = 0;
135 void Output(std::ostream &out, bool raw) const;
138 _finline std::ostream &operator <<(std::ostream &out, const CYExpression &rhs) {
139 rhs.Output(out, false);
155 CYString(const char *value, size_t size) :
161 CYString(const CYIdentifier *identifier) :
162 value_(identifier->Value()),
163 size_(strlen(value_))
167 const char *Value() const {
171 virtual const char *Name() const {
175 virtual void Output(std::ostream &out) const;
184 CYNumber(double value) :
189 double Value() const {
193 virtual const char *Name() const {
197 virtual void Output(std::ostream &out) const;
209 virtual void Output(std::ostream &out) const;
221 virtual void Output(std::ostream &out) const;
227 virtual bool Value() const = 0;
228 virtual void Output(std::ostream &out) const;
240 virtual bool Value() const {
254 virtual bool Value() const {
264 CYVariable(CYIdentifier *name) :
269 virtual void Output(std::ostream &out) const;
277 CYPrefix(CYExpression *rhs) :
282 virtual const char *Operator() const = 0;
284 virtual void Output(std::ostream &out) const;
293 CYInfix(CYExpression *lhs, CYExpression *rhs) :
299 virtual const char *Operator() const = 0;
301 virtual void Output(std::ostream &out) const;
309 CYPostfix(CYExpression *lhs) :
314 virtual const char *Operator() const = 0;
316 virtual void Output(std::ostream &out) const;
319 struct CYAssignment :
322 CYAssignment(CYExpression *lhs, CYExpression *rhs) :
327 virtual const char *Operator() const = 0;
332 CYExpression *value_;
335 CYArgument(CYWord *name, CYExpression *value, CYArgument *next = NULL) :
342 void Output(std::ostream &out, bool send) const;
361 CYClause(CYExpression *_case, CYStatement *code) :
367 virtual void Output(std::ostream &out) const;
373 CYExpression *value_;
376 CYElement(CYExpression *value, CYElement *next) :
382 void Output(std::ostream &out, bool raw) const;
383 virtual void Output(std::ostream &out) const;
386 struct CYDeclaration :
390 CYIdentifier *identifier_;
391 CYExpression *initialiser_;
393 CYDeclaration(CYIdentifier *identifier, CYExpression *initialiser) :
394 identifier_(identifier),
395 initialiser_(initialiser)
399 virtual void Part(std::ostream &out) const;
400 virtual void Output(std::ostream &out) const;
403 struct CYDeclarations :
407 CYDeclaration *declaration_;
408 CYDeclarations *next_;
410 CYDeclarations(CYDeclaration *declaration, CYDeclarations *next) :
411 declaration_(declaration),
416 virtual void Part(std::ostream &out) const;
417 virtual void Output(std::ostream &out) const;
426 CYParameter(CYIdentifier *name, CYParameter *next) :
432 virtual void Output(std::ostream &out) const;
438 CYForInitialiser *initialiser_;
440 CYExpression *increment_;
443 CYFor(CYForInitialiser *initialiser, CYExpression *test, CYExpression *increment, CYStatement *code) :
444 initialiser_(initialiser),
446 increment_(increment),
451 virtual void Output(std::ostream &out) const;
457 CYForInInitialiser *initialiser_;
461 CYForIn(CYForInInitialiser *initialiser, CYExpression *set, CYStatement *code) :
462 initialiser_(initialiser),
468 virtual void Output(std::ostream &out) const;
475 CYExpression *value_;
478 CYProperty(CYName *name, CYExpression *value, CYProperty *next) :
485 void Output(std::ostream &out, bool raw) const;
486 virtual void Output(std::ostream &out) const;
495 CYCatch(CYIdentifier *name, CYStatement *code) :
501 virtual void Output(std::ostream &out) const;
508 CYArgument *arguments_;
510 CYMessage(CYExpression *self, CYArgument *arguments) :
512 arguments_(arguments)
516 virtual void Output(std::ostream &out) const;
522 CYExpression *object_;
523 CYExpression *property_;
525 CYMember(CYExpression *object, CYExpression *property) :
531 virtual void Output(std::ostream &out) const;
537 CYExpression *constructor_;
538 CYArgument *arguments_;
540 CYNew(CYExpression *constructor, CYArgument *arguments) :
541 constructor_(constructor),
542 arguments_(arguments)
546 virtual void Output(std::ostream &out) const;
552 CYExpression *function_;
553 CYArgument *arguments_;
555 CYCall(CYExpression *function, CYArgument *arguments) :
557 arguments_(arguments)
561 virtual void Output(std::ostream &out) const;
571 CYIf(CYExpression *test, CYStatement *_true, CYStatement *_false) :
578 virtual void Output(std::ostream &out) const;
587 CYDoWhile(CYExpression *test, CYStatement *code) :
593 virtual void Output(std::ostream &out) const;
602 CYWhile(CYExpression *test, CYStatement *code) :
608 virtual void Output(std::ostream &out) const;
615 CYParameter *parameters_;
618 CYLambda(CYIdentifier *name, CYParameter *parameters, CYSource *body) :
620 parameters_(parameters),
625 virtual void Output(std::ostream &out) const;
632 CYFunction(CYIdentifier *name, CYParameter *parameters, CYSource *body) :
633 CYLambda(name, parameters, body)
637 virtual void Output(std::ostream &out) const;
643 CYExpression *expression_;
645 CYExpress(CYExpression *expression) :
646 expression_(expression)
650 virtual void Output(std::ostream &out) const;
656 CYIdentifier *label_;
658 CYContinue(CYIdentifier *label) :
663 virtual void Output(std::ostream &out) const;
669 CYIdentifier *label_;
671 CYBreak(CYIdentifier *label) :
676 virtual void Output(std::ostream &out) const;
682 CYExpression *value_;
684 CYReturn(CYExpression *value) :
689 virtual void Output(std::ostream &out) const;
695 virtual void Output(std::ostream &out) const;
696 virtual void Output(std::ostream &out, bool block) const;
704 CYStatement *finally_;
706 CYTry(CYStatement *_try, CYCatch *_catch, CYStatement *finally) :
713 virtual void Output(std::ostream &out) const;
719 CYExpression *value_;
721 CYThrow(CYExpression *value) :
726 virtual void Output(std::ostream &out) const;
732 CYExpression *scope_;
735 CYWith(CYExpression *scope, CYStatement *code) :
741 virtual void Output(std::ostream &out) const;
747 CYExpression *value_;
750 CYSwitch(CYExpression *value, CYClause *clauses) :
756 virtual void Output(std::ostream &out) const;
764 CYExpression *false_;
766 CYCondition(CYExpression *test, CYExpression *_true, CYExpression *_false) :
772 virtual void Output(std::ostream &out) const;
778 CYAddressOf(CYExpression *rhs) :
783 virtual const char *Operator() const {
787 virtual void Output(std::ostream &out) const;
793 CYIndirect(CYExpression *rhs) :
798 virtual const char *Operator() const {
802 virtual void Output(std::ostream &out) const;
805 #define CYPostfix_(op, name) \
806 struct CY ## name : \
809 CY ## name(CYExpression *lhs) : \
814 virtual const char *Operator() const { \
819 #define CYPrefix_(op, name) \
820 struct CY ## name : \
823 CY ## name(CYExpression *rhs) : \
828 virtual const char *Operator() const { \
833 #define CYInfix_(op, name) \
834 struct CY ## name : \
837 CY ## name(CYExpression *lhs, CYExpression *rhs) : \
842 virtual const char *Operator() const { \
847 #define CYAssignment_(op, name) \
848 struct CY ## name ## Assign : \
851 CY ## name ## Assign(CYExpression *lhs, CYExpression *rhs) : \
852 CYAssignment(lhs, rhs) \
856 virtual const char *Operator() const { \
861 CYPostfix_("++", PostIncrement)
862 CYPostfix_("--", PostDecrement)
864 CYPrefix_("delete", Delete)
865 CYPrefix_("void", Void)
866 CYPrefix_("typeof", TypeOf)
867 CYPrefix_("++", PreIncrement)
868 CYPrefix_("--", PreDecrement)
869 CYPrefix_("-", Negate)
870 CYPrefix_("~", BitwiseNot)
871 CYPrefix_("!", LogicalNot)
873 CYInfix_("*", Multiply)
874 CYInfix_("/", Divide)
875 CYInfix_("%", Modulus)
877 CYInfix_("-", Subtract)
878 CYInfix_("<<", ShiftLeft)
879 CYInfix_(">>", ShiftRightSigned)
880 CYInfix_(">>>", ShiftRightUnsigned)
882 CYInfix_(">", Greater)
883 CYInfix_("<=", LessOrEqual)
884 CYInfix_(">=", GreaterOrEqual)
885 CYInfix_("instanceof", InstanceOf)
887 CYInfix_("==", Equal)
888 CYInfix_("!=", NotEqual)
889 CYInfix_("===", Identical)
890 CYInfix_("!==", NotIdentical)
891 CYInfix_("&", BitwiseAnd)
892 CYInfix_("^", BitwiseXOr)
893 CYInfix_("|", BitwiseOr)
894 CYInfix_("&&", LogicalAnd)
895 CYInfix_("||", LogicalOr)
898 CYAssignment_("*=", Multiply)
899 CYAssignment_("/=", Divide)
900 CYAssignment_("%=", Modulus)
901 CYAssignment_("+=", Add)
902 CYAssignment_("-=", Subtract)
903 CYAssignment_("<<=", ShiftLeft)
904 CYAssignment_(">>=", ShiftRightSigned)
905 CYAssignment_(">>>=", ShiftRightUnsigned)
906 CYAssignment_("&=", BitwiseAnd)
907 CYAssignment_("^=", BitwiseXOr)
908 CYAssignment_("|=", BitwiseOr)
910 #endif/*CYPARSER_HPP*/