Parser is reading variable declarations, read more

This is an incomplete process. It's supposed to be robust enough to
support the types of arrays and dictionaries, but arrays and
dictionaries aren't implemented in the literals yet, so that's my next
task.

I'll come back to variable declarations later.
This commit is contained in:
2022-08-10 11:01:32 +01:00
parent 9603baeb0a
commit 6a883bde96
9 changed files with 218 additions and 17 deletions

View File

@@ -37,6 +37,20 @@ void freeNode(Node* node) {
for (int i = 0; i < node->block.count; i++) {
freeNode(node->block.nodes + i);
}
//each sub-node gets freed individually
break;
case NODE_VAR_TYPES:
for (int i = 0; i < node->varTypes.count; i++) {
freeNode(node->varTypes.nodes + 1);
}
//each sub-node gets freed individually
break;
case NODE_VAR_DECL:
freeLiteral(node->varDecl.identifier);
freeNode(node->varDecl.varType);
freeNode(node->varDecl.expression);
break;
}
@@ -91,6 +105,29 @@ void emitNodeBlock(Node** nodeHandle) {
*nodeHandle = tmp;
}
void emitNodeVarTypes(Node** nodeHandle, unsigned char mask) {
Node* tmp = ALLOCATE(Node, 1);
tmp->type = NODE_VAR_TYPES;
tmp->varTypes.mask = mask;
tmp->varTypes.nodes = NULL;
tmp->varTypes.capacity = 0;
tmp->varTypes.count = 0;
*nodeHandle = tmp;
}
void emitNodeVarDecl(Node** nodeHandle, Literal identifier, Node* varType, Node* expression) {
Node* tmp = ALLOCATE(Node, 1);
tmp->type = NODE_VAR_DECL;
tmp->varDecl.identifier = identifier;
tmp->varDecl.varType = varType;
tmp->varDecl.expression = expression;
*nodeHandle = tmp;
}
void printNode(Node* node) {
if (node == NULL) {
return;
@@ -134,5 +171,25 @@ void printNode(Node* node) {
printf("}\n");
break;
case NODE_VAR_TYPES:
printf("[\n");
for (int i = 0; i < node->varTypes.count; i++) {
printNode(&(node->varTypes.nodes[i]));
}
printf("]\n");
break;
case NODE_VAR_DECL:
printf("vardecl(");
printLiteral(node->varDecl.identifier);
printf("; ");
printNode(node->varDecl.varType);
printf("; ");
printNode(node->varDecl.expression);
printf(")");
break;
}
}