struct CYSource :
CYNext<CYSource>
{
+ virtual bool IsBlock() const {
+ return next_ != NULL;
+ }
+
virtual void Show(std::ostream &out) const;
virtual void Output(std::ostream &out) const = 0;
virtual void Output(std::ostream &out, bool block) const;
+ virtual void Output_(std::ostream &out) const;
};
-struct CYName :
- CYThing
-{
- virtual const char *Name() const = 0;
+struct CYPropertyName {
+ virtual void PropertyName(std::ostream &out) const = 0;
+};
+
+struct CYClassName {
+ virtual void ClassName(std::ostream &out, bool object) const = 0;
};
struct CYWord :
- CYName
+ CYThing,
+ CYPropertyName,
+ CYClassName
{
const char *word_;
return word_;
}
- virtual const char *Name() const {
- return Value();
- }
-
virtual void Output(std::ostream &out) const;
+
+ virtual void ClassName(std::ostream &out, bool object) const;
+ virtual void PropertyName(std::ostream &out) const;
};
struct CYIdentifier :
struct CYLabel :
CYNext<CYLabel>
{
- CYIdentifier *identifier_;
+ CYIdentifier *name_;
- CYLabel(CYIdentifier *identifier, CYLabel *next) :
+ CYLabel(CYIdentifier *name, CYLabel *next) :
CYNext<CYLabel>(next),
- identifier_(identifier)
+ name_(name)
{
}
};
struct CYStatement :
CYSource
{
- CYLabel *label_;
+ CYLabel *labels_;
+
+ CYStatement() :
+ labels_(NULL)
+ {
+ }
void AddLabel(CYIdentifier *identifier) {
- label_ = new CYLabel(identifier, label_);
+ labels_ = new CYLabel(identifier, labels_);
+ }
+
+ virtual void Output_(std::ostream &out) const;
+};
+
+struct CYBlock :
+ CYStatement
+{
+ CYStatement *statements_;
+
+ CYBlock(CYStatement *statements) :
+ statements_(statements)
+ {
}
+
+ virtual bool IsBlock() const {
+ return true;
+ }
+
+ virtual void Output(std::ostream &out) const;
};
enum CYState {
const char *data_;
size_t size_;
+ FILE *file_;
std::string filename_;
~CYDriver();
};
-struct CYPart {
- virtual void Part(std::ostream &out) const = 0;
-};
-
-struct CYForInitialiser :
- CYPart
-{
-};
-
-struct CYForInInitialiser :
- CYPart
-{
-};
-
enum CYFlags {
CYNoFlags = 0,
CYNoBrace = (1 << 0),
CYNoLeader = (1 << 2),
CYNoTrailer = (1 << 3),
CYNoIn = (1 << 4),
+ CYNoHyphen = (1 << 5),
+ CYNoBF = (CYNoBrace | CYNoFunction),
+};
+
+struct CYForInitialiser {
+ virtual void For(std::ostream &out) const = 0;
+};
+
+struct CYForInInitialiser {
+ virtual void ForIn(std::ostream &out, CYFlags flags) const = 0;
+ virtual const char *ForEachIn() const = 0;
+ virtual void ForEachIn(std::ostream &out) const = 0;
};
struct CYExpression :
CYNext<CYExpression>,
CYForInitialiser,
- CYForInInitialiser
+ CYForInInitialiser,
+ CYClassName
{
virtual unsigned Precedence() const = 0;
- virtual void Part(std::ostream &out) const;
+
+ virtual void For(std::ostream &out) const;
+ virtual void ForIn(std::ostream &out, CYFlags flags) const;
+
+ virtual const char *ForEachIn() const;
+ virtual void ForEachIn(std::ostream &out) const;
+
virtual void Output(std::ostream &out, CYFlags flags) const = 0;
void Output(std::ostream &out, unsigned precedence, CYFlags flags) const;
+ virtual void ClassName(std::ostream &out, bool object) const;
+
virtual const char *Word() const {
return NULL;
}
void Output(std::ostream &out, CYFlags flags) const;
};
+struct CYComprehension :
+ CYNext<CYComprehension>
+{
+ void Output(std::ostream &out) const;
+ virtual const char *Name() const = 0;
+
+ virtual void Begin_(std::ostream &out) const = 0;
+
+ virtual void End_(std::ostream &out) const {
+ }
+};
+
+struct CYForInComprehension :
+ CYComprehension
+{
+ CYIdentifier *name_;
+ CYExpression *set_;
+
+ CYForInComprehension(CYIdentifier *name, CYExpression *set) :
+ name_(name),
+ set_(set)
+ {
+ }
+
+ virtual const char *Name() const {
+ return name_->Value();
+ }
+
+ virtual void Begin_(std::ostream &out) const;
+};
+
+struct CYForEachInComprehension :
+ CYComprehension
+{
+ CYIdentifier *name_;
+ CYExpression *set_;
+
+ CYForEachInComprehension(CYIdentifier *name, CYExpression *set) :
+ name_(name),
+ set_(set)
+ {
+ }
+
+ virtual const char *Name() const {
+ return name_->Value();
+ }
+
+ virtual void Begin_(std::ostream &out) const;
+ virtual void End_(std::ostream &out) const;
+};
+
+struct CYIfComprehension :
+ CYComprehension
+{
+ CYExpression *test_;
+
+ CYIfComprehension(CYExpression *test) :
+ test_(test)
+ {
+ }
+
+ virtual const char *Name() const {
+ return NULL;
+ }
+
+ virtual void Begin_(std::ostream &out) const;
+};
+
+struct CYArrayComprehension :
+ CYExpression
+{
+ CYExpression *expression_;
+ CYComprehension *comprehensions_;
+
+ CYArrayComprehension(CYExpression *expression, CYComprehension *comprehensions) :
+ expression_(expression),
+ comprehensions_(comprehensions)
+ {
+ }
+
+ CYPrecedence(0)
+
+ virtual void Output(std::ostream &out, CYFlags flags) const;
+};
+
struct CYLiteral :
CYExpression
{
struct CYString :
CYLiteral,
- CYName
+ CYPropertyName
{
const char *value_;
size_t size_;
return value_;
}
- virtual const char *Name() const {
- return Value();
- }
-
virtual const char *Word() const {
if (size_ == 0 || !WordStartRange_[value_[0]])
return NULL;
}
virtual void Output(std::ostream &out, CYFlags flags) const;
+ virtual void PropertyName(std::ostream &out) const;
};
struct CYNumber :
CYLiteral,
- CYName
+ CYPropertyName
{
double value_;
return value_;
}
- virtual const char *Name() const {
- throw;
- }
-
virtual void Output(std::ostream &out) const {
return Output(out, CYNoFlags);
}
virtual void Output(std::ostream &out, CYFlags flags) const;
+ virtual void PropertyName(std::ostream &out) const;
};
struct CYNull :
{
}
+ void SetLeft(CYExpression *lhs) {
+ lhs_ = lhs;
+ }
+
virtual bool Alphabetic() const = 0;
virtual const char *Operator() const = 0;
{
}
+ void SetLeft(CYExpression *lhs) {
+ lhs_ = lhs;
+ }
+
virtual const char *Operator() const = 0;
virtual void Output(std::ostream &out, CYFlags flags) const;
};
struct CYDeclaration :
- CYThing,
CYForInInitialiser
{
CYIdentifier *identifier_;
{
}
- virtual void Part(std::ostream &out) const;
- virtual void Output(std::ostream &out) const;
+ virtual void ForIn(std::ostream &out, CYFlags flags) const;
+
+ virtual const char *ForEachIn() const;
+ virtual void ForEachIn(std::ostream &out) const;
+
+ virtual void Output(std::ostream &out, CYFlags flags) const;
};
struct CYDeclarations :
- CYStatement,
+ CYNext<CYDeclarations>,
CYForInitialiser
{
CYDeclaration *declaration_;
- CYDeclarations *next_;
CYDeclarations(CYDeclaration *declaration, CYDeclarations *next) :
- declaration_(declaration),
- next_(next)
+ CYNext<CYDeclarations>(next),
+ declaration_(declaration)
+ {
+ }
+
+ virtual void For(std::ostream &out) const;
+ virtual void Output(std::ostream &out, CYFlags flags) const;
+};
+
+struct CYVar :
+ CYStatement
+{
+ CYDeclarations *declarations_;
+
+ CYVar(CYDeclarations *declarations) :
+ declarations_(declarations)
+ {
+ }
+
+ virtual void Output(std::ostream &out) const;
+};
+
+struct CYLet :
+ CYStatement
+{
+ CYDeclarations *declarations_;
+ CYStatement *statements_;
+
+ CYLet(CYDeclarations *declarations, CYStatement *statements) :
+ declarations_(declarations),
+ statements_(statements)
{
}
- virtual void Part(std::ostream &out) const;
virtual void Output(std::ostream &out) const;
};
};
struct CYMessage :
- CYSource
+ CYNext<CYMessage>
{
bool instance_;
CYExpression *type_;
{
}
- virtual void Output(std::ostream &out) const;
+ virtual void Output(std::ostream &out, bool replace) const;
};
struct CYClass :
- CYSource
+ CYExpression,
+ CYStatement
{
- CYIdentifier *name_;
+ CYClassName *name_;
CYExpression *super_;
CYField *fields_;
CYMessage *messages_;
- CYClass(CYIdentifier *name, CYExpression *super, CYField *fields, CYMessage *messages) :
+ CYClass(CYClassName *name, CYExpression *super, CYField *fields, CYMessage *messages) :
name_(name),
super_(super),
fields_(fields),
{
}
+ CYPrecedence(0)
+
+ virtual void Output(std::ostream &out) const;
+ virtual void Output(std::ostream &out, CYFlags flags) const;
+};
+
+struct CYCategory :
+ CYStatement
+{
+ CYClassName *name_;
+ CYMessage *messages_;
+
+ CYCategory(CYClassName *name, CYMessage *messages) :
+ name_(name),
+ messages_(messages)
+ {
+ }
+
virtual void Output(std::ostream &out) const;
};
virtual void Output(std::ostream &out) const;
};
+struct CYForEachIn :
+ CYStatement
+{
+ CYForInInitialiser *initialiser_;
+ CYExpression *set_;
+ CYStatement *code_;
+
+ CYForEachIn(CYForInInitialiser *initialiser, CYExpression *set, CYStatement *code) :
+ initialiser_(initialiser),
+ set_(set),
+ code_(code)
+ {
+ }
+
+ virtual void Output(std::ostream &out) const;
+};
+
struct CYProperty :
CYNext<CYProperty>
{
- CYName *name_;
+ CYPropertyName *name_;
CYExpression *value_;
- CYProperty(CYName *name, CYExpression *value, CYProperty *next) :
+ CYProperty(CYPropertyName *name, CYExpression *value, CYProperty *next) :
CYNext<CYProperty>(next),
name_(name),
value_(value)
{
}
+ void SetLeft(CYExpression *object) {
+ object_ = object;
+ }
+};
+
+struct CYDirectMember :
+ CYMember
+{
+ CYDirectMember(CYExpression *object, CYExpression *property) :
+ CYMember(object, property)
+ {
+ }
+
+ CYPrecedence(1)
+
+ virtual void Output(std::ostream &out, CYFlags flags) const;
+};
+
+struct CYIndirectMember :
+ CYMember
+{
+ CYIndirectMember(CYExpression *object, CYExpression *property) :
+ CYMember(object, property)
+ {
+ }
+
CYPrecedence(1)
virtual void Output(std::ostream &out, CYFlags flags) const;