#include <iostream>
+#include <stack>
#include <string>
#include <vector>
#include <map>
};
struct CYExpression;
+struct CYAssignment;
enum CYNeeded {
CYNever = -1,
void Single(CYOutput &out, CYFlags flags) const;
void Multiple(CYOutput &out, CYFlags flags = CYNoFlags) const;
- virtual CYStatement *Collapse(CYContext &context);
virtual CYStatement *Replace(CYContext &context) = 0;
private:
typedef std::vector<CYIdentifierUsage> CYIdentifierUsageVector;
-// XXX: strategy pattern, maybe subclass
-enum CYScopeType {
- CYScopeCatch,
- CYScopeFunction,
- CYScopeProgram,
-};
-
struct CYScope {
- CYScopeType type_;
+ bool transparent_;
CYContext &context_;
CYStatement *&statements_;
CYIdentifierAddressFlagsMap internal_;
CYIdentifierValueSet identifiers_;
- CYScope(CYScopeType type, CYContext &context, CYStatement *&statements);
+ CYScope(bool transparent, CYContext &context, CYStatement *&statements);
virtual ~CYScope();
void Close();
Type_ **last(&values);
CYForEach (next, values) {
Replace(*last = next);
- last = &(*last)->next_;
+ if (*last != NULL)
+ last = &(*last)->next_;
}
}
class CYDriver {
public:
- CYState state_;
void *scanner_;
+ CYState state_;
+ bool statement_;
+ std::stack<bool> in_;
+
const char *data_;
size_t size_;
FILE *file_;
virtual ~CYForInitialiser() {
}
- virtual void For(CYOutput &out) const = 0;
virtual CYExpression *Replace(CYContext &context) = 0;
+ virtual void Output(CYOutput &out, CYFlags flags) const = 0;
};
struct CYForInInitialiser {
}
virtual void ForIn(CYOutput &out, CYFlags flags) const = 0;
- virtual const char *ForEachIn() const = 0;
virtual CYStatement *ForEachIn(CYContext &out, CYExpression *value) = 0;
+
virtual CYExpression *Replace(CYContext &context) = 0;
+ virtual CYAssignment *Assignment(CYContext &context) = 0;
+
+ virtual void Output(CYOutput &out, CYFlags flags) const = 0;
};
struct CYNumber;
return true;
}
- virtual void For(CYOutput &out) const;
virtual void ForIn(CYOutput &out, CYFlags flags) const;
-
- virtual const char *ForEachIn() const;
virtual CYStatement *ForEachIn(CYContext &out, CYExpression *value);
virtual CYExpression *AddArgument(CYContext &context, CYExpression *value);
virtual void ClassName(CYOutput &out, bool object) const;
virtual CYExpression *Replace(CYContext &context) = 0;
+ virtual CYAssignment *Assignment(CYContext &context);
virtual CYExpression *Primitive(CYContext &context) {
return this;
void Output(CYOutput &out, CYFlags flags) const;
};
+struct CYDeclaration;
+
struct CYFunctionParameter :
CYNext<CYFunctionParameter>,
CYThing
{
- CYIdentifier *name_;
+ CYForInInitialiser *initialiser_;
- CYFunctionParameter(CYIdentifier *name, CYFunctionParameter *next = NULL) :
+ CYFunctionParameter(CYForInInitialiser *initialiser, CYFunctionParameter *next = NULL) :
CYNext<CYFunctionParameter>(next),
- name_(name)
- {
- }
-
- virtual CYFunctionParameter *Replace(CYContext &context, CYBlock &code);
- virtual void Output(CYOutput &out) const;
-};
-
-struct CYOptionalFunctionParameter :
- CYFunctionParameter
-{
- CYExpression *initializer_;
-
- CYOptionalFunctionParameter(CYIdentifier *name, CYExpression *initializer, CYFunctionParameter *next = NULL) :
- CYFunctionParameter(name, next),
- initializer_(initializer)
+ initialiser_(initialiser)
{
}
- virtual CYFunctionParameter *Replace(CYContext &context, CYBlock &code);
- virtual void Output(CYOutput &out) const;
+ void Replace(CYContext &context, CYBlock &code);
+ void Output(CYOutput &out) const;
};
struct CYComprehension :
{
}
- void Replace(CYContext &context);
+ CYArgument *Replace(CYContext &context);
void Output(CYOutput &out) const;
};
}
virtual void ForIn(CYOutput &out, CYFlags flags) const;
-
- virtual const char *ForEachIn() const;
virtual CYStatement *ForEachIn(CYContext &out, CYExpression *value);
virtual CYExpression *Replace(CYContext &context);
+
virtual CYAssignment *Assignment(CYContext &context);
+ CYVariable *Variable(CYContext &context);
virtual void Output(CYOutput &out, CYFlags flags) const;
};
struct CYDeclarations :
CYNext<CYDeclarations>,
- CYThing,
- CYForInitialiser
+ CYThing
{
CYDeclaration *declaration_;
{
}
- virtual void For(CYOutput &out) const;
+ void Replace(CYContext &context);
- virtual CYCompound *Replace(CYContext &context);
+ CYCompound *Compound(CYContext &context);
CYProperty *Property(CYContext &context);
+ CYArgument *Argument(CYContext &context);
+ CYFunctionParameter *Parameter(CYContext &context);
virtual void Output(CYOutput &out) const;
virtual void Output(CYOutput &out, CYFlags flags) const;
};
+struct CYForDeclarations :
+ CYForInitialiser
+{
+ CYDeclarations *declarations_;
+
+ CYForDeclarations(CYDeclarations *declarations) :
+ declarations_(declarations)
+ {
+ }
+
+ virtual CYCompound *Replace(CYContext &context);
+ virtual void Output(CYOutput &out, CYFlags flags) const;
+};
+
struct CYVar :
CYStatement
{
virtual void Output(CYOutput &out, CYFlags flags) const;
};
-struct CYLet :
+struct CYLetStatement :
CYStatement
{
CYDeclarations *declarations_;
- CYBlock code_;
+ CYStatement *code_;
- CYLet(CYDeclarations *declarations, CYStatement *statements) :
+ CYLetStatement(CYDeclarations *declarations, CYStatement *code) :
declarations_(declarations),
- code_(statements)
+ code_(code)
{
}
void SetLeft(CYExpression *object) {
object_ = object;
}
-
- void Replace_(CYContext &context);
};
struct CYDirectMember :
throw;
}
- virtual CYStatement *Collapse(CYContext &context);
virtual CYStatement *Replace(CYContext &context);
virtual void Output(CYOutput &out, CYFlags flags) const;
};
struct CYEmpty :
CYStatement
{
- virtual CYStatement *Collapse(CYContext &context);
virtual CYStatement *Replace(CYContext &context);
virtual void Output(CYOutput &out, CYFlags flags) const;
};
virtual void Output(CYOutput &out, CYFlags flags) const;
};
+struct CYDebugger :
+ CYStatement
+{
+ CYDebugger()
+ {
+ }
+
+ virtual CYStatement *Replace(CYContext &context);
+ virtual void Output(CYOutput &out, CYFlags flags) const;
+};
+
struct CYCondition :
CYExpression
{