aboutsummaryrefslogtreecommitdiff
path: root/src/include
diff options
context:
space:
mode:
authorc+12023-11-18 23:14:24 -0500
committerc+12023-11-18 23:14:24 -0500
commit000658c8405f93bf8ce1e03a9055e6944e730534 (patch)
tree9d49aefb841a413351a3c0168497a93053062000 /src/include
parent2cc68205a1c0b746ad405607940e7183c4fb09b0 (diff)
I honestly don't remember. Parser stuff. Probably.
Diffstat (limited to 'src/include')
-rw-r--r--src/include/parser.h24
-rw-r--r--src/include/token.h46
-rw-r--r--src/include/tree.h31
3 files changed, 59 insertions, 42 deletions
diff --git a/src/include/parser.h b/src/include/parser.h
index 79e1289..b39f481 100644
--- a/src/include/parser.h
+++ b/src/include/parser.h
@@ -24,6 +24,28 @@ parser_t* parser_init(token_t* token);
void parser_destroy(parser_t* parser);
/* Step the parser forward by 1 token. */
-void parser_nxt_token(parser_t* parser);
+int parser_nxt_token(parser_t* parser);
+
+/* Check whether the current token matches the given type. */
+int parser_match(parser_t* parser, token_type_t type);
+
+/*
+ parse lit: converting everything from strings to value in the tree
+ parse expr: (For now) call parse lit
+ parse blk: loop over all expressions until reaching an end block.
+
+*/
+
+/* Parse a single literal value. */
+void parser_parse_lit(parser_t* parser);
+
+/* Parse a single expression. */
+void parser_parse_expr(parser_t* parser);
+
+/* Parse a single block. */
+void parser_parse_blk(parser_t* parser);
+
+/* Parse the given tokens. */
+void parser_parse(parser_t* parser);
#endif
diff --git a/src/include/token.h b/src/include/token.h
index 08de829..f86c47f 100644
--- a/src/include/token.h
+++ b/src/include/token.h
@@ -4,35 +4,37 @@
#include "util.h"
#include "hlkt.h"
+typedef enum TOKEN_TYPE {
+ TOKEN_UNKNOWN,
+ TOKEN_CHAR,
+ TOKEN_STR,
+ TOKEN_EXPR_END,
+ TOKEN_SET,
+ TOKEN_LGROUP,
+ TOKEN_RGROUP,
+ TOKEN_APPLY,
+ TOKEN_LIST_DELIM,
+ TOKEN_TAG,
+ TOKEN_NAMESPACE_DELIM,
+ TOKEN_LBLOCK,
+ TOKEN_RBLOCK,
+ TOKEN_RLIST,
+ TOKEN_LLIST,
+ TOKEN_ESC,
+ TOKEN_KWD,
+ TOKEN_INT
+} token_type_t;
+
/* Token struct. */
-typedef struct TOKEN_STRUC {
+typedef struct TOKEN {
/* Token type. */
- enum TOKEN_TYPE {
- TOKEN_UNKNOWN,
- TOKEN_CHAR,
- TOKEN_STR,
- TOKEN_EXPR_END,
- TOKEN_SET,
- TOKEN_LGROUP,
- TOKEN_RGROUP,
- TOKEN_APPLY,
- TOKEN_LIST_DELIM,
- TOKEN_TAG,
- TOKEN_NAMESPACE_DELIM,
- TOKEN_LBLOCK,
- TOKEN_RBLOCK,
- TOKEN_RLIST,
- TOKEN_LLIST,
- TOKEN_ESC,
- TOKEN_KWD,
- TOKEN_INT
- } type;
+ token_type_t type;
/* Token value. */
char* val;
/* Next token. */
- struct TOKEN_STRUC* nxt;
+ struct TOKEN* nxt;
} token_t;
/* Creates a token. */
diff --git a/src/include/tree.h b/src/include/tree.h
index b878852..3dfb5be 100644
--- a/src/include/tree.h
+++ b/src/include/tree.h
@@ -3,9 +3,7 @@
#include "util.h"
-/* The Abstract Syntax Tree (AST) structure. */
-typedef struct TREE {
- enum TREE_TYPE {
+typedef enum TREE_TYPE {
TREE_TYPE_BLOCK,
TREE_TYPE_LINT,
TREE_TYPE_LSTR,
@@ -14,14 +12,21 @@ typedef struct TREE {
TREE_TYPE_CARG,
TREE_TYPE_DEF,
TREE_TYPE_CAL,
- } type;
+} tree_type_t;
+
+/* The Abstract Syntax Tree (AST) structure. */
+typedef struct TREE {
+ tree_type_t type;
union TREE_DATA{
/* Block. */
struct TREE_DATA_BLOCK {
/* The first expression in the block. */
struct TREE* val;
- /* The next expression in the block. If it's'nt a block, end the block. */
+ /*
+ The next block in the linked list.
+ - If it's `NULL`, it's the end of the block.
+ */
struct TREE* nxt;
} block;
@@ -75,19 +80,7 @@ tree_t* tree_init(int type);
/* Destroy the AST. */
void tree_destroy(tree_t* tree);
-/* TODO: Implement a better target organization structure that's better for searching. */
-typedef struct TREE_TARG {
- tree_t* tree;
- struct TREE_TARG* nxt;
-} tree_targ_t;
-
-/* Create a new target. */
-tree_targ_t* tree_targ_init(tree_t* tree);
-/*
- Destroy a target.
- - Frees all subsequent targets in `nxt`.
- - Does not free the `tree`.
-*/
-void tree_targ_destroy(tree_targ_t* targ);
+/* Print a tree. */
+void tree_print(tree_t* tree, int nest);
#endif