diff options
author | c+1 | 2023-10-21 09:10:58 -0400 |
---|---|---|
committer | c+1 | 2023-10-21 09:10:58 -0400 |
commit | 6fc8f91e0d96ae4b4ee59ea562574cc04fdf8abf (patch) | |
tree | f7e1a8041f2808eecc60cae54f5dda3f85850c32 /src/include | |
parent | cc7bb40ae5e7f8f345195547b2c5044efc4d61ba (diff) |
⬣
Diffstat (limited to 'src/include')
-rw-r--r-- | src/include/lexer.h | 11 | ||||
-rw-r--r-- | src/include/token.h | 7 | ||||
-rw-r--r-- | src/include/tree.h | 46 |
3 files changed, 29 insertions, 35 deletions
diff --git a/src/include/lexer.h b/src/include/lexer.h index b2bf9eb..83ace59 100644 --- a/src/include/lexer.h +++ b/src/include/lexer.h @@ -16,8 +16,10 @@ typedef struct LEXER_STRUC { enum LEXER_STATE { /* normal 1-character token */ LEXER_STATE_REG, - /* character */ - LEXER_STATE_CHR, + /* definition tag */ + LEXER_STATE_TAG, + /* escaped character in string */ + LEXER_STATE_ESC, /* string */ LEXER_STATE_STR, /* definition */ @@ -46,8 +48,13 @@ void lexer_add_token(lexer_t* lexer, token_t* token); lexer_do_reg() */ void lexer_add_current_char(lexer_t* lexer, int type); +/* add first character of lexer's src to the value of the last token in tokenl, if it exists. otherwise, create new token and add it */ +void lexer_add_current_char_to_last_token(lexer_t* lexer, int type); + /* handle regular state */ void lexer_do_reg(lexer_t*); +/* handle definition tag state*/ +void lexer_do_tag(lexer_t*); /* handle character state */ void lexer_do_chr(lexer_t*); /* handle string state */ diff --git a/src/include/token.h b/src/include/token.h index 5a3a36c..a186fa9 100644 --- a/src/include/token.h +++ b/src/include/token.h @@ -34,11 +34,16 @@ typedef struct TOKEN_STRUC { } token_t; /* creates a token */ -token_t* token_init(int type, char* val); +token_t* token_init(int type, char val); /* destroys a token **and all tokens contained in nxt** **Make sure to set the nxt of any parent tokens to NULL** */ void token_destroy(token_t* token); /* return pointer to the last token */ token_t* token_last(token_t* token); +/* add a character to the token value */ +void token_add_char(token_t*, char); + +/* print a token -- for debugging purposes */ +void token_print(token_t* token); #endif diff --git a/src/include/tree.h b/src/include/tree.h index a2b71da..88287a4 100644 --- a/src/include/tree.h +++ b/src/include/tree.h @@ -4,44 +4,26 @@ #include <stdlib.h> typedef struct TREE_STRUC { - enum { - TREE_COMP, - TREE_DEF, - TREE_CALL, - TREE_TYPE_STR, + enum TREE_TYPE { TREE_TYPE_INT, + TREE_TYPE_STR, + TREE_TYPE_DEF, + TREE_TYPE_CAL, + TREE_TYPE_COND, } type; union { - struct { // === "COMPOUND" === - struct TREE_STRUC** value; - size_t size; - } comp; - - 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 - } def; - - struct { // === CALLS === - char* target; // name of definition being called - struct TREE_STRUC** args; // arguments passed to definition - size_t args_size; // the number of arguments - } call; + struct { + int val; + } tree_int_t; - // === TYPES === - struct { // strings - char* value; - } type_str; + struct { + char* val; + } tree_str_t; - struct { // integers - int value; - } type_int; + struct { + char* id; + } tree_def_t; } data; } tree_t; |