X-Git-Url: https://gitweb.ps.run/toc/blobdiff_plain/b64d16088b29615d222d33450cf0315467400e59..9f5457a18f551d261e4bd380ea16a52dc5b04cf9:/src/repr.h diff --git a/src/repr.h b/src/repr.h index 6737ef4..cc28746 100644 --- a/src/repr.h +++ b/src/repr.h @@ -14,22 +14,36 @@ struct Body; struct Function; struct Struct; struct Program; -struct CallExpr; -struct LiteralExpr; -struct VariableExpr; +struct FuncExpr; +struct LitExpr; +struct IdentifierExpr; struct BracketsExpr; -struct OperatorExpr; +struct UnaryOperatorExpr; +struct BinaryOperatorExpr; +struct TernaryOperatorExpr; struct DotExpr; struct Expr; struct IfStmt; +struct SwitchStmt; +struct ForStmt; struct WhileStmt; -struct ReturnStmt; struct AssignStmt; +struct ReturnStmt; struct Stmt; +enum class TypeModifierType { + Pointer, Array +}; + +struct TypeModifier { + TypeModifierType type; + + int _arraySize; +}; struct Type { std::string name; + std::vector modifiers; }; struct Variable { @@ -62,19 +76,29 @@ struct Program { }; enum class ExprType { - Call, Literal, Variable, Brackets, Operator, Dot + Func, Lit, Identifier, Brackets, UnaryOperator, BinaryOperator, TernaryOperator, Dot }; -struct CallExpr { +struct FuncExpr { std::string functionName; std::vector arguments; }; -struct LiteralExpr { - int i; +enum class LitType { + Int, Decimal, String, Bool +}; + +struct LitExpr { + LitType type; + + int _int; + double _decimal; + std::string _string; + bool _bool; }; -struct VariableExpr { +// TODO: accessExpr +struct IdentifierExpr { std::string name; }; @@ -83,41 +107,96 @@ struct BracketsExpr { std::shared_ptr rexpr; }; -enum class OperatorType { - Plus, Minus, Multiply, Divide, - Equals, NotEquals, - LessThan, GreaterThan +enum class UnaryOperatorType { + Plus, Minus, IncrementPre, DecrementPre, IncrementPost, DecrementPost, + LogicalNot, BitwiseNot, Dereference, AddressOf, + COUNT }; -struct OperatorExpr { +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, + COUNT +}; +static std::string UnaryOperatorTypeStrings[] = { + "+", "-", "++", "--", "++", "--", "!", "~", "*", "&" }; + +static std::string BinaryOperatorTypeStrings[] = { + "+", "-", "*", "/", "%", "&", "|", "^", "<", ">", + "<<",">>","&&","||","==","!=","<=",">=","&=","|=","^=", + "+=","-=","*=","/=","%=", + "<<=",">>=" }; + +struct UnaryOperatorExpr { + UnaryOperatorType type; + std::shared_ptr expr; +}; + +struct BinaryOperatorExpr { + BinaryOperatorType type; std::shared_ptr lexpr; std::shared_ptr rexpr; - OperatorType type; }; -struct DotExpr { +struct TernaryOperatorExpr { std::shared_ptr lexpr; - std::string name; + std::shared_ptr rexprTrue; + std::shared_ptr rexprFalse; }; +struct DotExpr { + std::shared_ptr expr; + IdentifierExpr ident; +}; + +// TODO: paren expr struct Expr { ExprType type; - CallExpr _call; - LiteralExpr _literal; - VariableExpr _variable; - BracketsExpr _brackets; - OperatorExpr _operator; - DotExpr _dot; + FuncExpr _func; + LitExpr _lit; + IdentifierExpr _identifier; + BracketsExpr _brackets; + UnaryOperatorExpr _unaryOperator; + BinaryOperatorExpr _binaryOperator; + TernaryOperatorExpr _ternaryOperator; + DotExpr _dot; }; enum class StmtType { - If, While, Return, Assign, Expr + If, Switch, For, While, Assign, Return, Expr }; +struct ElseStmt { + bool _if; + std::shared_ptr expr; + Body body; +}; struct IfStmt { Expr condition; Body body; + std::vector elses; +}; + +struct SwitchCase { + std::shared_ptr expr; + Body body; +}; + +struct SwitchStmt { + IdentifierExpr ident; + std::vector cases; +}; + +// 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 { @@ -125,23 +204,25 @@ struct WhileStmt { Body body; }; -struct ReturnStmt { +struct AssignStmt { + std::string name; Expr expr; }; -struct AssignStmt { - Expr lexpr; - Expr rexpr; +struct ReturnStmt { + Expr expr; }; struct Stmt { StmtType type; - IfStmt _if; - WhileStmt _while; - ReturnStmt _return; - AssignStmt _assign; - Expr _expr; + IfStmt _if; + SwitchStmt _switch; + ForStmt _for; + WhileStmt _while; + AssignStmt _assign; + ReturnStmt _return; + Expr _expr; };