Update {parser,tokenize}.h
This commit is contained in:
parent
60115b9e3d
commit
e889be9f34
@ -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();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
@ -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 {
|
||||
|
@ -2,6 +2,7 @@
|
||||
using namespace std;
|
||||
|
||||
#include "include/input.h"
|
||||
#include "include/parser.h"
|
||||
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
|
Loading…
Reference in New Issue
Block a user