From 45409c781a9e35df68c43b1e2f028d30bf90c0a0 Mon Sep 17 00:00:00 2001 From: Patrick Schönberger Date: Wed, 28 Jul 2021 09:07:53 +0200 Subject: Initial commit --- src/repr.h | 155 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 155 insertions(+) create mode 100644 src/repr.h (limited to 'src/repr.h') diff --git a/src/repr.h b/src/repr.h new file mode 100644 index 0000000..ce176ef --- /dev/null +++ b/src/repr.h @@ -0,0 +1,155 @@ +#pragma once + +#include +#include +#include + +#include "TocParser.h" + +using namespace std; + +struct Type; +struct Variable; +struct Body; +struct Function; +struct Struct; +struct Program; +struct CallExpr; +struct LiteralExpr; +struct VariableExpr; +struct BracketsExpr; +struct OperatorExpr; +struct DotExpr; +struct Expr; +struct IfStmt; +struct WhileStmt; +struct ReturnStmt; +struct AssignStmt; +struct Stmt; + + +struct Type { + std::string name; +}; + +struct Variable { + std::string name; + Type type; +}; + +struct Body { + std::vector variables; + std::vector statements; +}; + +struct Function { + std::string name; + std::vector parameters; + Body body; +}; + +struct Struct { + std::string name; + std::vector members; + std::vector methods; +}; + +struct Program { + std::vector variables; + std::vector structs; + std::vector functions; +}; + +enum class ExprType { + Call, Literal, Variable, Brackets, Operator, Dot +}; + +struct CallExpr { + Function function; + std::vector arguments; +}; + +struct LiteralExpr { + int i; +}; + +struct VariableExpr { + std::string name; +}; + +struct BracketsExpr { + BracketsExpr() {} + BracketsExpr(const BracketsExpr &) {} + BracketsExpr & operator=(const BracketsExpr &) {return *this;}; + std::unique_ptr lexpr; + std::unique_ptr rexpr; +}; + +enum class OperatorType { + Plus, Minus, Multiply, Divide, + Equals, NotEquals, + LessThan, GreaterThan +}; + +struct OperatorExpr { + OperatorExpr() {} + OperatorExpr(const OperatorExpr &) {} + OperatorExpr & operator=(const OperatorExpr &) {return *this;}; + std::unique_ptr lexpr; + std::unique_ptr rexpr; + OperatorType type; +}; + +struct DotExpr { + DotExpr() {} + DotExpr(const DotExpr &) {} + DotExpr & operator=(const DotExpr &) {return *this;}; + std::unique_ptr lexpr; + std::string name; +}; + +struct Expr { + ExprType type; + + CallExpr _call; + LiteralExpr _literal; + VariableExpr _variable; + BracketsExpr _brackets; + OperatorExpr _operator; + DotExpr _dot; +}; + +enum class StmtType { + If, While, Return, Assign, Expr +}; + +struct IfStmt { + Expr condition; + Body body; +}; + +struct WhileStmt { + Expr condition; + Body body; +}; + +struct ReturnStmt { + Expr expr; +}; + +struct AssignStmt { + Expr lexpr; + Expr rexpr; +}; + +struct Stmt { + StmtType type; + + IfStmt _if; + WhileStmt _while; + ReturnStmt _return; + AssignStmt _assign; + Expr _expr; +}; + + -- cgit v1.2.3