From 4176dea8503cc8eebfa24b14aaefc3a8dc643230 Mon Sep 17 00:00:00 2001
From: s-over-4
Date: Tue, 29 Aug 2023 10:17:27 -0400
Subject: g
---
README.md | 2 +-
resources/HALK_FINAL.svg | 59 ------------------------------------------------
src/include/parser.h | 7 +++---
src/include/tree.h | 6 +++--
src/lexer.c | 16 +++++++------
src/parser.c | 43 ++++++++++++++++-------------------
src/token.c | 1 -
src/tree.c | 25 ++++++++++++--------
8 files changed, 52 insertions(+), 107 deletions(-)
delete mode 100644 resources/HALK_FINAL.svg
diff --git a/README.md b/README.md
index cb46cfe..400abab 100644
--- a/README.md
+++ b/README.md
@@ -1,6 +1,6 @@
# HALK
-
+
*HALK* seeks to be a language.
diff --git a/resources/HALK_FINAL.svg b/resources/HALK_FINAL.svg
deleted file mode 100644
index 01f1c1b..0000000
--- a/resources/HALK_FINAL.svg
+++ /dev/null
@@ -1,59 +0,0 @@
-
-
diff --git a/src/include/parser.h b/src/include/parser.h
index 0ba2038..deb6c7c 100644
--- a/src/include/parser.h
+++ b/src/include/parser.h
@@ -4,6 +4,8 @@
#include "lexer.h"
#include "tree.h"
+#include
+
typedef struct PARSER_STRUC {
lexer_t* lexer; // lexer used by the parser
token_t* token; // current token
@@ -12,9 +14,8 @@ typedef struct PARSER_STRUC {
parser_t* parser_init(lexer_t* lexer);
void parser_destroy(parser_t* parser);
-// expect token, or die
-void parser_token_expect(parser_t* parser, int token);
-void parser_token_expectf(parser_t* parser, int (*expected_token)(token_t*));
+// expect token(s), or die
+void parser_token_expect(parser_t* parser, int token, ...);
// do the parse
tree_t* parser_parse(parser_t* parser);
diff --git a/src/include/tree.h b/src/include/tree.h
index fde66ea..a2b71da 100644
--- a/src/include/tree.h
+++ b/src/include/tree.h
@@ -21,15 +21,17 @@ typedef struct TREE_STRUC {
struct { // === DEFINITIONS ===
char* type; // the definition type
char** tags; // the definition tags
+ size_t tags_size; // the number of tags
char* name; // the definition name
+ struct TREE_STRUC** args; // the arguments the definition will accept
+ size_t args_size; // the number of arguments
struct TREE_STRUC* value; // value of definition
- // :D lines line up :D
} def;
struct { // === CALLS ===
char* target; // name of definition being called
struct TREE_STRUC** args; // arguments passed to definition
- size_t args_size; // size of arguments
+ size_t args_size; // the number of arguments
} call;
// === TYPES ===
diff --git a/src/lexer.c b/src/lexer.c
index a5ed31b..09831bb 100644
--- a/src/lexer.c
+++ b/src/lexer.c
@@ -104,9 +104,9 @@ token_t* lexer_next_token(lexer_t* lexer, int token_type) {
return token;
}
-// get the current character as a string
+/* get the current character as a string */
char* lexer_get_c_as_string(lexer_t* lexer) {
- char* str; // the string to return
+ char* str; /* the string to return */
str = calloc(2, sizeof(char));
str[0] = lexer->c;
@@ -115,11 +115,13 @@ char* lexer_get_c_as_string(lexer_t* lexer) {
return str;
}
-// fskip: skip first char?
-// lskip: skip last char?
+/*
+ fskip: skip first char?
+ lskip: skip last char?
+*/
token_t* lexer_collect(lexer_t* lexer, int (*end_char)(char), int fskip, int lskip, int type) {
- size_t len; // length of collected token so far
- char* token; // collected token so far
+ size_t len; /* length of collected token so far */
+ char* token; /* collected token so far */
len = 0;
token = calloc(len, sizeof(char));
@@ -144,7 +146,7 @@ token_t* lexer_collect(lexer_t* lexer, int (*end_char)(char), int fskip, int lsk
if (lskip) { lexer_next(lexer); }
- token[len] = '\0'; // null terminate
+ token[len] = '\0'; /* null terminate */
return token_init(type, token);
}
diff --git a/src/parser.c b/src/parser.c
index 4233138..c32202e 100644
--- a/src/parser.c
+++ b/src/parser.c
@@ -20,24 +20,19 @@ parser_t* parser_init(lexer_t* lexer) {
void parser_destroy(parser_t* parser) { free(parser); }
-void parser_token_expect(parser_t* parser, int token) {
- token == parser->token->type?
- parser->token = lexer_get_next_token(parser->lexer):
- die(
- "unexpected token\n\ttype: [%s]\n\tvalue: [%s]",
- token_get_type(parser->token->type),
- parser->token->value
- );
-}
-
-void parser_token_expectf(parser_t* parser, int (*expected_token)(token_t*)) {
- expected_token(parser->token)?
- parser->token = lexer_get_next_token(parser->lexer):
- die(
- "unexpected token\n\ttype: [%s]\n\tvalue: [%s]",
- token_get_type(parser->token->type),
- parser->token->value
- );
+void parser_token_expect(parser_t* parser, int tokens, ...) {
+ va_list ap;
+ va_start(ap, tokens);
+ for (int i = 0; i < tokens; ++i) {
+ va_arg(ap, int) == parser->token->type?
+ parser->token = lexer_get_next_token(parser->lexer):
+ die(
+ "unexpected token\n\ttype: [%s]\n\tvalue: [%s]",
+ token_get_type(parser->token->type),
+ parser->token->value
+ );
+ }
+ va_end(ap);
}
tree_t* parser_parse(parser_t* parser) { return parser_parse_exprs(parser); }
@@ -73,7 +68,7 @@ tree_t* parser_parse_exprs(parser_t* parser) {
parser_token_expect(parser, TOKEN_STMNT_END);
statement = parser_parse_expr(parser);
- comp->data.comp.size += 1;
+ comp->data.comp.size ++;
comp->data.comp.value = realloc(
comp->data.comp.value,
comp->data.comp.size * sizeof(struct TREE_STRUC)
@@ -97,12 +92,12 @@ tree_t* parser_parse_def(parser_t* parser) {
def->type = TREE_DEF;
- def->data.def.name = parser->token->value;
-
-// def->data.def.
-
while (parser->token->type == TOKEN_DEF_TAG) {
-
+ def->data.def.tags_size ++;
+ def->data.def.tags = realloc(
+ def->data.def.args,
+ def->data.def.args_size + sizeof(parser->token->value)
+ );
}
}
diff --git a/src/token.c b/src/token.c
index 41e7e0c..355a6dd 100644
--- a/src/token.c
+++ b/src/token.c
@@ -2,7 +2,6 @@
#include "include/token.h"
-// token constructor
token_t* token_init(int type, char* val) {
token_t* token = calloc(1, sizeof(struct TOKEN_STRUC));
token->type = type;
diff --git a/src/tree.c b/src/tree.c
index 0ed0697..235d0e6 100644
--- a/src/tree.c
+++ b/src/tree.c
@@ -8,23 +8,28 @@ tree_t* tree_init(int type) {
switch (type) {
case TREE_COMP:
- tree->data.comp.value = (void*) 0;
+ tree->data.comp.value = NULL;
tree->data.comp.size = 0;
break;
case TREE_DEF:
- tree->data.def.name = (void*) 0;
- tree->data.def.value = (void*) 0;
+ tree->data.def.type = NULL;
+ tree->data.def.tags = NULL;
+ tree->data.def.tags_size = 0;
+ tree->data.def.name = NULL;
+ tree->data.def.args = NULL;
+ tree->data.def.tags_size = 0;
+ tree->data.def.value = NULL;
break;
case TREE_CALL:
- tree->data.call.args = (void*) 0;
+ tree->data.call.target = NULL;
+ tree->data.call.args = NULL;
tree->data.call.args_size = 0;
- tree->data.call.target = (void*) 0;
break;
- case TREE_TYPE_STR:
- tree->data.type_str.value = (void*) 0;
- break;
- case TREE_TYPE_INT:
- tree->data.type_int.value = (void*) 0;
+ case TREE_TYPE_STR:
+ tree->data.type_str.value = NULL;
+ break;
+ case TREE_TYPE_INT:
+ tree->data.type_int.value = 0;
break;
}
--
cgit v1.2.3