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 Assignment // -> Identifier = Expr
}; };
struct Node;
struct InnerNode { struct InnerNode {
NodeType type; NodeType type;
vector<Node> children; vector<Node> children;
@ -67,6 +68,13 @@ struct Node {
InnerNode node; InnerNode node;
Token leaf; 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 #define TOKENIZE_H
#include <vector> #include <vector>
#include <string>
using namespace std; using namespace std;
enum class TokenType { Type, Identifier, Number, Plus, Minus, Star, Slash, Percent, Equal, Semicolon, LParenthese, RParenthese }; 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 { union TokenData {
double number; double number;
Type type; Type type;
char* identifier; string identifier;
TokenData() : number(0.0) {}
// Explicitly define the destructor
~TokenData() {}
}; };
struct Token { struct Token {

View File

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