aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorc2023-11-26 18:03:55 -0500
committerc2023-11-26 18:03:55 -0500
commit4719af8e829493d4fee2782ce8870b0cc902638f (patch)
tree2f77b4132ec9c5f5a93756c3f74d354c1917f606
parentb66334d81324a76a76da6578c5b095f3f02696e5 (diff)
Prepare for definition parsing.
-rw-r--r--src/include/parser.h6
-rw-r--r--src/include/tree.h6
-rw-r--r--src/parser.c25
-rw-r--r--src/tree.c2
4 files changed, 29 insertions, 10 deletions
diff --git a/src/include/parser.h b/src/include/parser.h
index acf6438..59cd0ae 100644
--- a/src/include/parser.h
+++ b/src/include/parser.h
@@ -49,6 +49,12 @@ tree_t* parser_parse_expr(parser_t* parser);
/* Return the tree for an expression. */
tree_t* parser_parse_block(parser_t* parser);
+/* Return the tree for a definition's arguments. */
+tree_t* parser_parse_darg(parser_t* parser);
+
+/* Return the tree for a definition. */
+tree_t* parser_parse_def(parser_t* parser);
+
/* Return the tree for a call's arguments. */
tree_t* parser_parse_carg(parser_t* parser);
diff --git a/src/include/tree.h b/src/include/tree.h
index 8954ef8..1976773 100644
--- a/src/include/tree.h
+++ b/src/include/tree.h
@@ -51,18 +51,18 @@ typedef struct TREE {
/* Tags. */
struct TREE_DATA_TAG {
char* val;
- struct TREE* nxt; /* TAG* */
+ struct TREE* nxt; /* TAG */
} tag;
/* Definition arguments. */
struct TREE_DATA_DARG {
- struct TREE* tag; /* TAG* */
+ struct TREE* val; /* DEF */
struct TREE* nxt; /* DARG */
} darg;
/* Call arguments. */
struct TREE_DATA_CARG {
- struct TREE* val;
+ struct TREE* val; /* EXPR */
struct TREE* nxt; /* CARG */
} carg;
diff --git a/src/parser.c b/src/parser.c
index a6ed3f4..040ef0d 100644
--- a/src/parser.c
+++ b/src/parser.c
@@ -26,12 +26,7 @@ int parser_nxt_token(parser_t* parser) {
}
int parser_match(parser_t* parser, token_type_t type) {
- if (parser->token->type == type) {
- return 1;
- } else {
- log_err("Unexpected token.");
- return 0;
- }
+ return parser->token->type == type;
}
int parser_nxt_token_match(parser_t* parser, token_type_t type) {
@@ -119,6 +114,24 @@ tree_t* parser_parse_block(parser_t* parser) {
return block;
}
+tree_t* parser_parse_darg(parser_t* parser) {
+ tree_t* darg;
+
+ darg = tree_init(TREE_TYPE_DARG);
+
+ darg->data.darg.tag
+
+ return darg;
+}
+
+tree_t* parser_parse_def(parser_t* parser) {
+ tree_t* def;
+
+ def = tree_init(TREE_TYPE_DEF);
+
+ return def;
+}
+
tree_t* parser_parse_carg(parser_t* parser) {
tree_t* carg;
diff --git a/src/tree.c b/src/tree.c
index 4cd0263..cea6fcd 100644
--- a/src/tree.c
+++ b/src/tree.c
@@ -69,7 +69,7 @@ void tree_destroy(tree_t* tree) {
tree_destroy(tree->data.tag.nxt);
break;
case TREE_TYPE_DARG:
- free(tree->data.darg.tag);
+ tree_destroy(tree->data.darg.val);
tree_destroy(tree->data.darg.nxt);
break;
case TREE_TYPE_CARG: