<commit_before>#include "parser.h"

/** List of token names */
static const char* TOKEN_NAMES[] = {
	"END_OF_FILE", "IDENTIFIER", "NUMBER",
	"OPERATOR", "SEPARATOR", "ERRORNEOUS",
	"STRING", "CHARACTER", "UNKNOWN"
};

/** List of data types */
static const char* DATA_TYPES[] = {
	"int", "str", "double", "float", "bool",
	"void"
};

/** UTILITY FOR NODES */

ExpressionNode *createExpressionNode() {
	return malloc(sizeof(ExpressionNode));
}

VariableDefineNode *createVariableDefineNode() {
	return malloc(sizeof(VariableDefineNode));
}

VariableDeclareNode *createVariableDeclareNode() {
	return malloc(sizeof(VariableDeclareNode));
}

FunctionArgumentNode *createFunctionArgumentNode() {
	return malloc(sizeof(FunctionArgumentNode));
}

FunctionNode *createFunctionNode() {
	return malloc(sizeof(FunctionNode));
}

BlockNode *createBlockNode() {
	return malloc(sizeof(BlockNode));
}

FunctionPrototypeNode *createFunctionPrototypeNode() {
	return malloc(sizeof(FunctionPrototypeNode));
}

void destroyExpressionNode(ExpressionNode *expr) {
	if (expr->leftHand != NULL) {
		destroyExpressionNode(expr->leftHand);
	}
	if (expr->rightHand != NULL) {
		destroyExpressionNode(expr->rightHand);
	}
	free(expr);
}

void destroyVariableDefineNode(VariableDefineNode *vdn) {
	free(vdn);
}

void destroyVariableDeclareNode(VariableDeclareNode *vdn) {
	if (vdn->vdn != NULL) {
		destroyVariableDefineNode(vdn->vdn);
	}
	if (vdn->expr != NULL) {
		destroyExpressionNode(vdn->expr);
	}
	free(vdn);
}<commit_msg>malloc checks for nodes, also fixed #5 and fixed #6<commit_after>#include "parser.h"

/** List of token names */
static const char* TOKEN_NAMES[] = {
	"END_OF_FILE", "IDENTIFIER", "NUMBER",
	"OPERATOR", "SEPARATOR", "ERRORNEOUS",
	"STRING", "CHARACTER", "UNKNOWN"
};

/** List of data types */
static const char* DATA_TYPES[] = {
	"int", "str", "double", "float", "bool",
	"void"
};

/** UTILITY FOR NODES */

ExpressionNode *createExpressionNode() {
	ExpressionNode *expr = malloc(sizeof(*expr));
	if (!expr) {
		perror("malloc: failed to allocate memory for ExpressionNode");
		exit(1);
	}
	return expr;
}

VariableDefineNode *createVariableDefineNode() {
	VariableDefineNode *vdn = malloc(sizeof(*vdn));
	if (!vdn) {
		perror("malloc: failed to allocate memory for VariableDefineNode");
		exit(1);
	}
	return vdn;
}

VariableDeclareNode *createVariableDeclareNode() {
	VariableDeclareNode *vdn = malloc(sizeof(*vdn));
	if (!vdn) {
		perror("malloc: failed to allocate memory for VariableDeclareNode");
		exit(1);
	}
	return vdn;
}

FunctionArgumentNode *createFunctionArgumentNode() {
	FunctionArgumentNode *fan = malloc(sizeof(*fan));
	if (!fan) {
		perror("malloc: failed to allocate memory for FunctionArgumentNode");
		exit(1);
	}
	return fan;
}

FunctionNode *createFunctionNode() {
	FunctionNode *fn = malloc(sizeof(*fn));
	if (!fn) {
		perror("malloc: failed to allocate memory for FunctionNode");
		exit(1);
	}
	return fn;
}

BlockNode *createBlockNode() {
	BlockNode *bn = malloc(sizeof(*bn));
	if (!bn) {
		perror("malloc: failed to allocate memory for BlockNode");
		exit(1);
	}
	return bn;
}

FunctionPrototypeNode *createFunctionPrototypeNode() {
	FunctionPrototypeNode *fpn = malloc(sizeof(*fpn));
	if (!fpn) {
		perror("malloc: failed to allocate memory for FunctionPrototypeNode");
		exit(1);
	}
	return fpn;
}

void destroyExpressionNode(ExpressionNode *expr) {
	if (expr->leftHand != NULL) {
		destroyExpressionNode(expr->leftHand);
	}
	if (expr->rightHand != NULL) {
		destroyExpressionNode(expr->rightHand);
	}
	free(expr);
}

void destroyVariableDefineNode(VariableDefineNode *vdn) {
	free(vdn);
}

void destroyVariableDeclareNode(VariableDeclareNode *vdn) {
	if (vdn->vdn != NULL) {
		destroyVariableDefineNode(vdn->vdn);
	}
	if (vdn->expr != NULL) {
		destroyExpressionNode(vdn->expr);
	}
	free(vdn);
}
{'fraction_non_alphanumeric': 0.15117493472584856, 'fraction_numerical': 0.002349869451697128, 'mean_word_length': 5.853309481216458, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6761230', 'n_tokens_mistral': 1335, 'n_tokens_neox': 1285, 'n_words': 284}