Refactor parser to C11 and update build configuration
This commit is contained in:
+1
-1
@@ -11,7 +11,7 @@ V0_TEST_OBJ := $(patsubst v0/%.c,v0/bin/%.o,$(V0_TEST))
|
|||||||
V0_SRC_DEPS := $(V0_SRC_OBJ:.o=.d)
|
V0_SRC_DEPS := $(V0_SRC_OBJ:.o=.d)
|
||||||
V0_TEST_DEPS := $(V0_TEST_OBJ:.o=.d)
|
V0_TEST_DEPS := $(V0_TEST_OBJ:.o=.d)
|
||||||
|
|
||||||
CFLAGS += -Werror -Wall -pedantic -std=c89
|
CFLAGS += -Werror -Wall -pedantic -std=c11
|
||||||
|
|
||||||
v0/bin/c2: $(V0_SRC_OBJ)
|
v0/bin/c2: $(V0_SRC_OBJ)
|
||||||
$(CC) $(CFLAGS) -o $@ $^
|
$(CC) $(CFLAGS) -o $@ $^
|
||||||
|
|||||||
+6
-16
@@ -5,13 +5,7 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
Module* parser_parse(TokenStream* ts) {
|
Module* parser_parse(TokenStream* ts) {
|
||||||
/* Declarations first for C89 */
|
Token t = tokenstream_next(ts);
|
||||||
Token t;
|
|
||||||
Module* module;
|
|
||||||
ImportDeclaration* new_imports;
|
|
||||||
int is_public;
|
|
||||||
|
|
||||||
t = tokenstream_next(ts);
|
|
||||||
if (t.token != TOKEN_MODULE) {
|
if (t.token != TOKEN_MODULE) {
|
||||||
log_on_line(&t.location, t.location.column_end, "expected 'module' keyword");
|
log_on_line(&t.location, t.location.column_end, "expected 'module' keyword");
|
||||||
return NULL;
|
return NULL;
|
||||||
@@ -23,7 +17,7 @@ Module* parser_parse(TokenStream* ts) {
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
module = (Module*)malloc(sizeof(Module));
|
Module* module = (Module*)malloc(sizeof(Module));
|
||||||
if (module == NULL) {
|
if (module == NULL) {
|
||||||
fprintf(stderr, "Out of memory\n");
|
fprintf(stderr, "Out of memory\n");
|
||||||
exit(1);
|
exit(1);
|
||||||
@@ -41,16 +35,13 @@ Module* parser_parse(TokenStream* ts) {
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
module->imports = NULL;
|
|
||||||
module->import_count = 0;
|
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
t = tokenstream_next(ts);
|
t = tokenstream_next(ts);
|
||||||
if (t.token != TOKEN_IMPORT) {
|
if (t.token != TOKEN_IMPORT) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
new_imports = realloc(module->imports, (module->import_count + 1) * sizeof(ImportDeclaration));
|
ImportDeclaration* new_imports = realloc(module->imports, (module->import_count + 1) * sizeof(ImportDeclaration));
|
||||||
if (!new_imports) {
|
if (!new_imports) {
|
||||||
fprintf(stderr, "Out of memory\n");
|
fprintf(stderr, "Out of memory\n");
|
||||||
exit(1);
|
exit(1);
|
||||||
@@ -58,9 +49,9 @@ Module* parser_parse(TokenStream* ts) {
|
|||||||
module->imports = new_imports;
|
module->imports = new_imports;
|
||||||
|
|
||||||
t = tokenstream_next(ts);
|
t = tokenstream_next(ts);
|
||||||
is_public = 0;
|
bool is_public = false;
|
||||||
if (t.token == TOKEN_IDENTIFIER && strncmp(t.text.data, "public", t.text.length) == 0) {
|
if (t.token == TOKEN_IDENTIFIER && strncmp(t.text.data, "public", t.text.length) == 0) {
|
||||||
is_public = 1;
|
is_public = true;
|
||||||
t = tokenstream_next(ts);
|
t = tokenstream_next(ts);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -70,8 +61,7 @@ Module* parser_parse(TokenStream* ts) {
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
module->imports[module->import_count].module_name = t;
|
module->imports[module->import_count] = (ImportDeclaration){ .module_name = t, .is_public = is_public };
|
||||||
module->imports[module->import_count].is_public = (bool)is_public;
|
|
||||||
module->import_count++;
|
module->import_count++;
|
||||||
|
|
||||||
t = tokenstream_next(ts);
|
t = tokenstream_next(ts);
|
||||||
|
|||||||
Reference in New Issue
Block a user