X-Git-Url: https://gitweb.ps.run/toc/blobdiff_plain/5f9668526491332f62c05ad831dbf6d5fdc2b6d0..71a20a4f3d4e5f5278f7d004af710af89dfd7ebc:/src/repr.h diff --git a/src/repr.h b/src/repr.h index c745ba1..47a78d7 100644 --- a/src/repr.h +++ b/src/repr.h @@ -17,11 +17,13 @@ struct Program; struct FuncExpr; struct LitExpr; struct IdentifierExpr; +struct AccessExpr; struct BracketsExpr; struct UnaryOperatorExpr; struct BinaryOperatorExpr; struct TernaryOperatorExpr; struct DotExpr; +struct ParenExpr; struct Expr; struct IfStmt; struct SwitchStmt; @@ -31,64 +33,77 @@ struct AssignStmt; struct ReturnStmt; struct Stmt; -enum class TypeModifierType { +enum class TypeModifierType +{ Pointer, Array }; -struct TypeModifier { +struct TypeModifier +{ TypeModifierType type; + bool _staticArray; int _arraySize; }; -struct Type { +struct Type +{ std::string name; std::vector modifiers; }; -struct Variable { +struct Variable +{ std::string name; Type type; }; -struct Body { +struct Body +{ std::vector variables; std::vector statements; }; -struct Function { +struct Function +{ Type returnType; std::string name; std::vector parameters; Body body; }; -struct Struct { +struct Struct +{ std::string name; std::vector members; std::vector methods; }; -struct Program { +struct Program +{ std::vector variables; std::vector structs; std::vector functions; }; -enum class ExprType { +enum class ExprType +{ Func, Lit, Identifier, Brackets, UnaryOperator, BinaryOperator, TernaryOperator, Dot }; -struct FuncExpr { +struct FuncExpr +{ std::string functionName; std::vector arguments; }; -enum class LitType { +enum class LitType +{ Int, Decimal, String, Bool }; -struct LitExpr { +struct LitExpr +{ LitType type; int _int; @@ -97,59 +112,77 @@ struct LitExpr { bool _bool; }; -struct IdentifierExpr { +// TODO: accessExpr +struct IdentifierExpr +{ std::string name; }; -struct BracketsExpr { +struct BracketsExpr +{ std::shared_ptr lexpr; std::shared_ptr rexpr; }; -enum class UnaryOperatorType { - Plus, Minus, IncrementPre, DecrementPre, IncrementPost, DecrementPost, LogicalNot, BitwiseNot, Dereference, AddressOf +enum class UnaryOperatorType +{ + Plus, Minus, IncrementPre, DecrementPre, IncrementPost, DecrementPost, + LogicalNot, BitwiseNot, Dereference, AddressOf, + COUNT }; -enum class BinaryOperatorType { +enum class BinaryOperatorType +{ Plus, Minus, Multiply, Divide, Modulo, BitwiseAnd, BitwiseOr, BitwiseXor, LessThan, GreaterThan, LeftShift, RightShift, LogicalAnd, LogicalOr, Equals, NotEquals, LessThanEquals, GreaterThanEquals, BitwiseAndEquals, BitwiseOrEquals, BitwiseXorEquals, PlusEquals, MinusEquals, MultiplyEquals, DivideEquals, ModuloEquals, - LeftShiftEquals, RightShiftEquals + LeftShiftEquals, RightShiftEquals, + COUNT }; -static std::string UnaryOperatorTypeStrings[] = { +static std::string UnaryOperatorTypeStrings[] = +{ "+", "-", "++", "--", "++", "--", "!", "~", "*", "&" }; -static std::string BinaryOperatorTypeStrings[] = { +static std::string BinaryOperatorTypeStrings[] = +{ "+", "-", "*", "/", "%", "&", "|", "^", "<", ">", "<<",">>","&&","||","==","!=","<=",">=","&=","|=","^=", "+=","-=","*=","/=","%=", "<<=",">>=" }; -struct UnaryOperatorExpr { +struct UnaryOperatorExpr +{ UnaryOperatorType type; std::shared_ptr expr; }; -struct BinaryOperatorExpr { +struct BinaryOperatorExpr +{ BinaryOperatorType type; std::shared_ptr lexpr; std::shared_ptr rexpr; }; -struct TernaryOperatorExpr { +struct TernaryOperatorExpr +{ std::shared_ptr lexpr; std::shared_ptr rexprTrue; std::shared_ptr rexprFalse; }; -struct DotExpr { - std::shared_ptr lexpr; +struct DotExpr +{ + std::shared_ptr expr; IdentifierExpr ident; }; -struct Expr { +// TODO: paren expr +struct Expr +{ ExprType type; + bool parenthesized; + FuncExpr _func; LitExpr _lit; IdentifierExpr _identifier; @@ -160,53 +193,65 @@ struct Expr { DotExpr _dot; }; -enum class StmtType { +enum class StmtType +{ If, Switch, For, While, Assign, Return, Expr }; -struct ElseStmt { +struct ElseStmt +{ bool _if; std::shared_ptr expr; Body body; }; -struct IfStmt { +struct IfStmt +{ Expr condition; Body body; std::vector elses; }; -struct SwitchCase { +struct SwitchCase +{ std::shared_ptr expr; Body body; }; -struct SwitchStmt { +struct SwitchStmt +{ IdentifierExpr ident; std::vector cases; }; -struct ForStmt { - AssignStmt assign; +// TODO: int i = 0 (var decl) +struct ForStmt +{ + std::string varName; + std::shared_ptr initValue; std::shared_ptr condition; std::shared_ptr action; Body body; }; -struct WhileStmt { +struct WhileStmt +{ Expr condition; Body body; }; -struct AssignStmt { - Expr lexpr; - Expr rexpr; +struct AssignStmt +{ + std::string name; + Expr expr; }; -struct ReturnStmt { +struct ReturnStmt +{ Expr expr; }; -struct Stmt { +struct Stmt +{ StmtType type; IfStmt _if;