aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorc+12023-05-10 07:53:59 -0400
committerc+12023-05-10 07:53:59 -0400
commit8dd1bf3637c0d01816bbd48b28c02e9791243d35 (patch)
tree1ab6a623f825c884e42c705cf573b52e54aac092
parented14de35050de7b16312a7d69d5823de3fa4002a (diff)
THE halk
-rw-r--r--Makefile3
-rw-r--r--src/include/tree.h4
-rw-r--r--src/main.c4
-rw-r--r--src/parser.c20
-rw-r--r--src/tree.c27
5 files changed, 32 insertions, 26 deletions
diff --git a/Makefile b/Makefile
index 0530b06..b034809 100644
--- a/Makefile
+++ b/Makefile
@@ -1,5 +1,6 @@
exec = halk.out
-sources = $(wildcard src/*.c)
+sources := $(wildcard src/*.c)
+sources := $(filter-out src/parser.c, $(sources)) # exclude the incomplete parser for now.
objects = $(sources:.c=.o)
flags = -g
diff --git a/src/include/tree.h b/src/include/tree.h
index 1cf029c..e42f761 100644
--- a/src/include/tree.h
+++ b/src/include/tree.h
@@ -24,7 +24,7 @@ typedef struct TREE_STRUC {
struct var_def_struc {
char* name;
struct TREE_STRUC* val;
- int is_const;
+ int* is_const;
} var_def;
struct var_struc {
@@ -49,7 +49,7 @@ typedef struct TREE_STRUC {
} str;
struct subtree_struc {
- struct TREE_STRUC* val;
+ struct TREE_STRUC** val;
size_t size;
} subtree;
diff --git a/src/main.c b/src/main.c
index 6a45767..2d741e4 100644
--- a/src/main.c
+++ b/src/main.c
@@ -1,5 +1,9 @@
#include <stdio.h>
+
+
#include "include/lexer.h"
+#include "include/tree.h"
+
int main(int argc, char* argv[]) {
lexer_t* lexer = lexer_init(
diff --git a/src/parser.c b/src/parser.c
index c7f2851..4468997 100644
--- a/src/parser.c
+++ b/src/parser.c
@@ -5,7 +5,7 @@
#include <stdio.h>
#include <string.h>
-/*
+
// initialize a parser
parser_t* parser_init(lexer_t* lexer) {
parser_t* parser = calloc(1, sizeof(struct PARSER_STRUC));
@@ -21,7 +21,7 @@ void parser_check_expect(parser_t* parser, int token_type) {
if (parser->token->type == token_type) {
parser->token = lexer_get_next_token(parser->lexer);
} else {
- printf("[ERRR] PARSE ERROR at %d\n\tUnexpected token '%s' with type '%d'.",
+ printf("[ERRR] [%d]\n\tUnexpected token '%s' with type '%d'.",
parser->lexer->i, parser->token->value, parser->token->type);
exit(1);
@@ -56,25 +56,25 @@ tree_t* parser_parse_chunks(parser_t* parser) {
tree_t* subtree = tree_init(TREE_SUBTREE);
// initialize the subtree_val with unit size
- subtree->subtree_val = calloc(1, sizeof(struct TREE_STRUC));
+ subtree->data.subtree.size = calloc(1, sizeof(struct TREE_STRUC));
tree_t* tree_chunk = parser_parse_chunk(parser);
- subtree->subtree_val[0] = tree_chunk;
+ subtree->data.subtree.val[0] = tree_chunk;
while (parser->token->type == TOKEN_SEMI) {
// expect semicolon
parser_check_expect(parser, TOKEN_SEMI);
// make room for new subtree
- subtree->subtree_size ++;
- subtree->subtree_val = realloc(
- subtree->subtree_val,
- subtree->subtree_size * sizeof(struct TREE_STRUC)
+ subtree->data.subtree.size ++;
+ subtree->data.subtree.val = realloc(
+ subtree->data.subtree.val,
+ subtree->data.subtree.size * sizeof(struct TREE_STRUC)
);
// add to end of list
- subtree->subtree_val[subtree->subtree_size - 1] = tree_chunk;
+ subtree->data.subtree.val[subtree->data.subtree.size - 1] = tree_chunk;
}
return subtree;
@@ -91,4 +91,4 @@ tree_t* parser_parse_fn_call(parser_t* parser);
tree_t* parser_parse_var(parser_t* parser);
tree_t* parser_parse_str(parser_t* parser);
-*/
+
diff --git a/src/tree.c b/src/tree.c
index 338ab24..b7677d3 100644
--- a/src/tree.c
+++ b/src/tree.c
@@ -7,27 +7,28 @@ tree_t* tree_init(int type) {
switch (type) {
case TREE_VAR_DEF:
- tree->data.var_def.name = NULL;
- tree->data.var_def.val = NULL;
+ tree->data.var_def.name = NULL;
+ tree->data.var_def.val = NULL;
+ tree->data.var_def.is_const = 0;
break;
case TREE_VAR:
- tree->data.var.name = NULL;
+ tree->data.var.name = NULL;
break;
case TREE_FN_DEF:
- tree->data.fn_def.name = NULL;
- tree->data.fn_def.val = NULL;
- tree->data.fn_def.argv = NULL;
- tree->data.fn_def.argsize = 0;
+ tree->data.fn_def.name = NULL;
+ tree->data.fn_def.val = NULL;
+ tree->data.fn_def.argv = NULL;
+ tree->data.fn_def.argsize = 0;
break;
case TREE_FN_CALL:
- tree->data.fn_call.name = NULL;
- tree->data.fn_call.argv = NULL;
- tree->data.fn_call.argsize = 0;
+ tree->data.fn_call.name = NULL;
+ tree->data.fn_call.argv = NULL;
+ tree->data.fn_call.argsize = 0;
break;
case TREE_STR:
- tree->data.str.val = NULL;
- tree->data.subtree.val = NULL;
- tree->data.subtree.size = 0;
+ tree->data.str.val = NULL;
+ tree->data.subtree.val = NULL;
+ tree->data.subtree.size = 0;
break;
}