struct Body;\r
struct Function;\r
struct Struct;\r
+struct Namespace;\r
struct Program;\r
+\r
struct FuncExpr;\r
+struct MethodExpr;\r
struct LitExpr;\r
-struct IdentifierExpr;\r
-struct AccessExpr;\r
-struct BracketsExpr;\r
-struct UnaryOperatorExpr;\r
+struct ParenExpr;\r
+struct DotExpr;\r
+struct PrefixOperatorExpr;\r
+struct PostfixOperatorExpr;\r
struct BinaryOperatorExpr;\r
struct TernaryOperatorExpr;\r
-struct DotExpr;\r
-struct ParenExpr;\r
+struct BracketsExpr;\r
+struct IdentifierExpr;\r
struct Expr;\r
+\r
struct IfStmt;\r
struct SwitchStmt;\r
struct ForStmt;\r
struct ReturnStmt;\r
struct Stmt;\r
\r
+struct Context\r
+{\r
+ std::shared_ptr<Context> parent;\r
+ std::vector<Variable> variables;\r
+};\r
+\r
enum class TypeModifierType\r
{\r
Pointer, Array\r
\r
struct Type\r
{\r
+ std::vector<std::string> namespacePrefixes;\r
std::string name;\r
std::vector<TypeModifier> modifiers;\r
};\r
\r
struct Body\r
{\r
- std::vector<Variable> variables;\r
+ std::shared_ptr<Context> ctx;\r
std::vector<Stmt> statements;\r
};\r
\r
Type returnType;\r
std::string name;\r
std::vector<Variable> parameters;\r
+ bool defined;\r
Body body;\r
};\r
\r
+template<typename T>\r
+struct StructMember\r
+{\r
+ T t;\r
+ bool isPublic;\r
+ operator T() { return t; }\r
+};\r
+\r
struct Struct\r
{\r
std::string name;\r
- std::vector<Variable> members;\r
- std::vector<Function> methods;\r
+ std::vector<StructMember<Variable>> members;\r
+ std::vector<StructMember<Function>> methods;\r
+};\r
+\r
+struct Namespace\r
+{\r
+ std::string name;\r
+ std::shared_ptr<Context> ctx;\r
+ std::vector<Struct> structs;\r
+ std::vector<Function> functions;\r
+ std::vector<Namespace> namespaces;\r
};\r
\r
struct Program\r
{\r
- std::vector<Variable> variables;\r
+ std::shared_ptr<Context> ctx;\r
std::vector<Struct> structs;\r
std::vector<Function> functions;\r
+ std::vector<Namespace> namespaces;\r
};\r
\r
enum class ExprType\r
{\r
- Func, Lit, Identifier, Brackets, UnaryOperator, BinaryOperator, TernaryOperator, Dot\r
+ Func, Method, Lit, Paren, Dot, PrefixOp, PostfixOp, BinaryOp, TernaryOp, Bracket, Identifier\r
};\r
\r
struct FuncExpr\r
{\r
+ std::vector<std::string> namespacePrefixes;\r
std::string functionName;\r
std::vector<Expr> arguments;\r
};\r
\r
+struct MethodExpr\r
+{\r
+ std::shared_ptr<Expr> expr;\r
+ std::string methodName;\r
+ std::vector<Expr> arguments;\r
+};\r
+\r
enum class LitType\r
{\r
Int, Decimal, String, Bool\r
bool _bool;\r
};\r
\r
-// TODO: accessExpr\r
-struct IdentifierExpr\r
+struct ParenExpr\r
{\r
- std::string name;\r
+ std::shared_ptr<Expr> expr;\r
};\r
\r
-struct BracketsExpr\r
+struct DotExpr\r
{\r
- std::shared_ptr<Expr> lexpr;\r
- std::shared_ptr<Expr> rexpr;\r
+ std::shared_ptr<Expr> expr;\r
+ std::string identifier;\r
};\r
\r
-enum class UnaryOperatorType\r
+enum class PrefixOperatorType\r
{\r
- Plus, Minus, IncrementPre, DecrementPre, IncrementPost, DecrementPost,\r
+ Plus, Minus, Increment, Decrement,\r
LogicalNot, BitwiseNot, Dereference, AddressOf,\r
COUNT\r
};\r
+static std::string PrefixOperatorTypeStrings[] =\r
+{\r
+ "+", "-", "++", "--", "!", "~", "*", "&" };\r
+\r
+struct PrefixOperatorExpr\r
+{\r
+ PrefixOperatorType type;\r
+ std::shared_ptr<Expr> expr;\r
+};\r
+\r
+enum class PostfixOperatorType\r
+{\r
+ Increment, Decrement,\r
+ COUNT\r
+};\r
+static std::string PostfixOperatorTypeStrings[] =\r
+{\r
+ "++", "--" };\r
+\r
+struct PostfixOperatorExpr\r
+{\r
+ PostfixOperatorType type;\r
+ std::shared_ptr<Expr> expr;\r
+};\r
\r
enum class BinaryOperatorType\r
{\r
LeftShiftEquals, RightShiftEquals,\r
COUNT\r
};\r
-static std::string UnaryOperatorTypeStrings[] =\r
-{\r
- "+", "-", "++", "--", "++", "--", "!", "~", "*", "&" };\r
-\r
static std::string BinaryOperatorTypeStrings[] =\r
{\r
"+", "-", "*", "/", "%", "&", "|", "^", "<", ">",\r
"+=","-=","*=","/=","%=",\r
"<<=",">>=" };\r
\r
-struct UnaryOperatorExpr\r
-{\r
- UnaryOperatorType type;\r
- std::shared_ptr<Expr> expr;\r
-};\r
-\r
struct BinaryOperatorExpr\r
{\r
BinaryOperatorType type;\r
std::shared_ptr<Expr> rexprFalse;\r
};\r
\r
-struct DotExpr\r
+struct BracketsExpr\r
{\r
- std::shared_ptr<Expr> expr;\r
- IdentifierExpr ident;\r
+ std::shared_ptr<Expr> lexpr;\r
+ std::shared_ptr<Expr> rexpr;\r
+};\r
+\r
+struct IdentifierExpr\r
+{\r
+ std::vector<std::string> namespacePrefixes;\r
+ std::string identifier;\r
};\r
\r
-// TODO: paren expr\r
struct Expr\r
{\r
ExprType type;\r
\r
- bool parenthesized;\r
-\r
FuncExpr _func;\r
+ MethodExpr _method;\r
LitExpr _lit;\r
- IdentifierExpr _identifier;\r
- BracketsExpr _brackets;\r
- UnaryOperatorExpr _unaryOperator;\r
- BinaryOperatorExpr _binaryOperator;\r
- TernaryOperatorExpr _ternaryOperator;\r
+ ParenExpr _paren;\r
DotExpr _dot;\r
+ PrefixOperatorExpr _prefixOp;\r
+ PostfixOperatorExpr _postfixOp;\r
+ BinaryOperatorExpr _binaryOp;\r
+ TernaryOperatorExpr _ternaryOp;\r
+ BracketsExpr _brackets;\r
+ IdentifierExpr _identifier;\r
};\r
\r
enum class StmtType\r
\r
struct SwitchStmt\r
{\r
- IdentifierExpr ident;\r
+ std::shared_ptr<Expr> ident;\r
std::vector<SwitchCase> cases;\r
};\r
\r
// TODO: int i = 0 (var decl)\r
struct ForStmt\r
{\r
- std::string varName;\r
- std::shared_ptr<Expr> initValue;\r
+ std::shared_ptr<AssignStmt> init;\r
std::shared_ptr<Expr> condition;\r
std::shared_ptr<Expr> action;\r
Body body;\r
\r
struct AssignStmt\r
{\r
- std::string name;\r
- Expr expr;\r
+ Expr lexpr, rexpr;\r
};\r
\r
struct ReturnStmt\r