Update {parser,tokenize}.h

This commit is contained in:
augustin64 2023-10-27 17:53:58 +02:00
parent 60115b9e3d
commit e889be9f34
3 changed files with 16 additions and 1 deletions

View File

@ -54,6 +54,7 @@ enum class NodeType {
Assignment // -> Identifier = Expr
};
struct Node;
struct InnerNode {
NodeType type;
vector<Node> 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();
}
};

View File

@ -2,6 +2,7 @@
#define TOKENIZE_H
#include <vector>
#include <string>
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 {

View File

@ -2,6 +2,7 @@
using namespace std;
#include "include/input.h"
#include "include/parser.h"
int main(int argc, char* argv[]) {