#include <string>
#include <vector>
+#include "location.hh"
#include "Pooling.hpp"
template <typename Type_>
{
}
+ CYNext(Type_ *next) :
+ next_(next)
+ {
+ }
+
void SetNext(Type_ *next) {
next_ = next;
}
}
};
-struct CYLabel {
+struct CYLabel :
+ CYNext<CYLabel>
+{
CYIdentifier *identifier_;
- CYLabel *next_;
CYLabel(CYIdentifier *identifier, CYLabel *next) :
- identifier_(identifier),
- next_(next)
+ CYNext<CYLabel>(next),
+ identifier_(identifier)
{
}
};
class CYDriver {
public:
CYPool pool_;
+
CYState state_;
- std::string filename_;
- std::vector<CYSource *> source_;
void *scanner_;
+ const char *data_;
+ size_t size_;
+
+ std::string filename_;
+
+ struct Error {
+ cy::location location_;
+ std::string message_;
+ };
+
+ typedef std::vector<Error> Errors;
+
+ CYSource *source_;
+ Errors errors_;
+
private:
void ScannerInit();
void ScannerDestroy();
public:
CYDriver(const std::string &filename);
~CYDriver();
-
- void Clear();
};
struct CYForInitialiser :
CYForInitialiser,
CYForInInitialiser
{
+ virtual unsigned Precedence() const = 0;
virtual void Part(std::ostream &out) const;
virtual void Output(std::ostream &out) const = 0;
- void Output(std::ostream &out, bool raw) const;
+ void Output(std::ostream &out, unsigned precedence) const;
};
-_finline std::ostream &operator <<(std::ostream &out, const CYExpression &rhs) {
- rhs.Output(out, false);
- return out;
-}
+#define CYPrecedence(value) \
+ virtual unsigned Precedence() const { \
+ return value; \
+ }
+
+struct CYCompound :
+ CYExpression
+{
+ CYExpression *expressions_;
+
+ CYCompound(CYExpression *expressions) :
+ expressions_(expressions)
+ {
+ }
+
+ void AddPrev(CYExpression *expression) {
+ CYExpression *last(expression);
+ while (last->next_ != NULL)
+ last = last->next_;
+ last->SetNext(expressions_);
+ expressions_ = expression;
+ }
+
+ CYPrecedence(17)
+
+ void Output(std::ostream &out) const;
+};
struct CYLiteral :
CYExpression
{
+ CYPrecedence(0)
+};
+
+struct CYSelectorPart :
+ CYNext<CYSelectorPart>
+{
+ CYWord *name_;
+ bool value_;
+
+ CYSelectorPart(CYWord *name, bool value, CYSelectorPart *next) :
+ CYNext<CYSelectorPart>(next),
+ name_(name),
+ value_(value)
+ {
+ }
+
+ virtual void Output(std::ostream &out) const;
+};
+
+struct CYSelector :
+ CYLiteral
+{
+ CYSelectorPart *name_;
+
+ CYSelector(CYSelectorPart *name) :
+ name_(name)
+ {
+ }
+
+ virtual void Output(std::ostream &out) const;
};
struct CYString :
{
}
+ CYPrecedence(0)
+
virtual void Output(std::ostream &out) const;
};
{
}
+ CYPrecedence(0)
+
virtual void Output(std::ostream &out) const;
};
};
struct CYAssignment :
- CYInfix
+ CYExpression
{
+ CYExpression *lhs_;
+ CYExpression *rhs_;
+
CYAssignment(CYExpression *lhs, CYExpression *rhs) :
- CYInfix(lhs, rhs)
+ lhs_(lhs),
+ rhs_(rhs)
{
}
virtual const char *Operator() const = 0;
+
+ virtual void Output(std::ostream &out) const;
};
-struct CYArgument {
+struct CYArgument :
+ CYNext<CYArgument>
+{
CYWord *name_;
CYExpression *value_;
- CYArgument *next_;
CYArgument(CYWord *name, CYExpression *value, CYArgument *next = NULL) :
+ CYNext<CYArgument>(next),
name_(name),
- value_(value),
- next_(next)
+ value_(value)
{
}
- void Output(std::ostream &out, bool send) const;
+ void Output(std::ostream &out) const;
};
struct CYBlank :
};
struct CYElement :
- CYLiteral
+ CYNext<CYElement>
{
CYExpression *value_;
- CYElement *next_;
CYElement(CYExpression *value, CYElement *next) :
- value_(value),
- next_(next)
+ CYNext<CYElement>(next),
+ value_(value)
+ {
+ }
+
+ void Output(std::ostream &out) const;
+};
+
+struct CYArray :
+ CYLiteral
+{
+ CYElement *elements_;
+
+ CYArray(CYElement *elements) :
+ elements_(elements)
{
}
- void Output(std::ostream &out, bool raw) const;
virtual void Output(std::ostream &out) const;
};
};
struct CYParameter :
+ CYNext<CYParameter>,
CYThing
{
CYIdentifier *name_;
- CYParameter *next_;
CYParameter(CYIdentifier *name, CYParameter *next) :
- name_(name),
- next_(next)
+ CYNext<CYParameter>(next),
+ name_(name)
{
}
virtual void Output(std::ostream &out) const;
};
-struct CYProperty {
+struct CYProperty :
+ CYNext<CYProperty>
+{
CYName *name_;
CYExpression *value_;
- CYProperty *next_;
CYProperty(CYName *name, CYExpression *value, CYProperty *next) :
+ CYNext<CYProperty>(next),
name_(name),
- value_(value),
- next_(next)
+ value_(value)
{
}
{
}
+ CYPrecedence(0)
+
virtual void Output(std::ostream &out) const;
};
{
}
+ CYPrecedence(1)
+
virtual void Output(std::ostream &out) const;
};
{
}
+ CYPrecedence(1)
+
virtual void Output(std::ostream &out) const;
};
{
}
+ CYPrecedence(2)
+
virtual void Output(std::ostream &out) const;
};
{
}
+ CYPrecedence(0)
+
virtual void Output(std::ostream &out) const;
};
CYExpression *false_;
CYCondition(CYExpression *test, CYExpression *_true, CYExpression *_false) :
+ test_(test),
true_(_true),
false_(_false)
{
}
+ CYPrecedence(15)
+
virtual void Output(std::ostream &out) const;
};
return "&";
}
+ CYPrecedence(2)
+
virtual void Output(std::ostream &out) const;
};
return "*";
}
+ CYPrecedence(1)
+
virtual void Output(std::ostream &out) const;
};
CYPostfix(lhs) \
{ \
} \
+ \
+ CYPrecedence(3) \
\
virtual const char *Operator() const { \
return op; \
CYPrefix(rhs) \
{ \
} \
+ \
+ CYPrecedence(4) \
\
virtual const char *Operator() const { \
return op; \
} \
};
-#define CYInfix_(op, name) \
+#define CYInfix_(precedence, op, name) \
struct CY ## name : \
CYInfix \
{ \
CYInfix(lhs, rhs) \
{ \
} \
+ \
+ CYPrecedence(precedence) \
\
virtual const char *Operator() const { \
return op; \
CYAssignment(lhs, rhs) \
{ \
} \
+ \
+ CYPrecedence(16) \
\
virtual const char *Operator() const { \
return op; \
CYPrefix_("~", BitwiseNot)
CYPrefix_("!", LogicalNot)
-CYInfix_("*", Multiply)
-CYInfix_("/", Divide)
-CYInfix_("%", Modulus)
-CYInfix_("+", Add)
-CYInfix_("-", Subtract)
-CYInfix_("<<", ShiftLeft)
-CYInfix_(">>", ShiftRightSigned)
-CYInfix_(">>>", ShiftRightUnsigned)
-CYInfix_("<", Less)
-CYInfix_(">", Greater)
-CYInfix_("<=", LessOrEqual)
-CYInfix_(">=", GreaterOrEqual)
-CYInfix_("instanceof", InstanceOf)
-CYInfix_("in", In)
-CYInfix_("==", Equal)
-CYInfix_("!=", NotEqual)
-CYInfix_("===", Identical)
-CYInfix_("!==", NotIdentical)
-CYInfix_("&", BitwiseAnd)
-CYInfix_("^", BitwiseXOr)
-CYInfix_("|", BitwiseOr)
-CYInfix_("&&", LogicalAnd)
-CYInfix_("||", LogicalOr)
+CYInfix_(5, "*", Multiply)
+CYInfix_(5, "/", Divide)
+CYInfix_(5, "%", Modulus)
+CYInfix_(6, "+", Add)
+CYInfix_(6, "-", Subtract)
+CYInfix_(7, "<<", ShiftLeft)
+CYInfix_(7, ">>", ShiftRightSigned)
+CYInfix_(7, ">>>", ShiftRightUnsigned)
+CYInfix_(8, "<", Less)
+CYInfix_(8, ">", Greater)
+CYInfix_(8, "<=", LessOrEqual)
+CYInfix_(8, ">=", GreaterOrEqual)
+CYInfix_(8, "instanceof", InstanceOf)
+CYInfix_(8, "in", In)
+CYInfix_(9, "==", Equal)
+CYInfix_(9, "!=", NotEqual)
+CYInfix_(9, "===", Identical)
+CYInfix_(9, "!==", NotIdentical)
+CYInfix_(10, "&", BitwiseAnd)
+CYInfix_(11, "^", BitwiseXOr)
+CYInfix_(12, "|", BitwiseOr)
+CYInfix_(13, "&&", LogicalAnd)
+CYInfix_(14, "||", LogicalOr)
CYAssignment_("=", )
CYAssignment_("*=", Multiply)