diff --git a/src/include/parser.h b/src/include/parser.h index f14c6db..83a1c10 100644 --- a/src/include/parser.h +++ b/src/include/parser.h @@ -54,6 +54,7 @@ enum class NodeType { Assignment // -> Identifier = Expr }; +struct Node; struct InnerNode { NodeType type; vector children; @@ -67,6 +68,13 @@ struct Node { InnerNode node; Token leaf; }; + + Node() : is_leaf(true), leaf{} {} + + // Explicitly define the destructor + ~Node() { + if (!is_leaf) node.~InnerNode(); + } }; diff --git a/src/include/tokenize.h b/src/include/tokenize.h index e06fd88..f8e1acd 100644 --- a/src/include/tokenize.h +++ b/src/include/tokenize.h @@ -2,6 +2,7 @@ #define TOKENIZE_H #include +#include using namespace std; enum class TokenType { Type, Identifier, Number, Plus, Minus, Star, Slash, Percent, Equal, Semicolon, LParenthese, RParenthese }; @@ -10,7 +11,12 @@ enum class Type { Int }; union TokenData { double number; Type type; - char* identifier; + string identifier; + + TokenData() : number(0.0) {} + + // Explicitly define the destructor + ~TokenData() {} }; struct Token { diff --git a/src/main.cpp b/src/main.cpp index 51068a6..fea2f16 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -2,6 +2,7 @@ using namespace std; #include "include/input.h" +#include "include/parser.h" int main(int argc, char* argv[]) {