From 266d3d6af1ba8d338bb8b9ad09431483276dae46 Mon Sep 17 00:00:00 2001 From: c+1 Date: Wed, 10 May 2023 00:50:10 -0400 Subject: halk. --- src/include/lexer.h | 22 +++++++++++++--------- src/include/token.h | 6 +++++- src/include/tree.h | 48 +++++++++++++++++++++++++++++++++++------------- 3 files changed, 53 insertions(+), 23 deletions(-) (limited to 'src/include') diff --git a/src/include/lexer.h b/src/include/lexer.h index a0e40af..eb80646 100644 --- a/src/include/lexer.h +++ b/src/include/lexer.h @@ -1,28 +1,32 @@ #ifndef LEXER_H #define LEXER_H + + #include "token.h" + typedef struct LEXER_STRUC { char c; // current character in content unsigned int i; // index of c char* content; // the code itself } lexer_t; -lexer_t* lexer_init(char* content); +extern lexer_t* lexer_init(char* content); + +extern void lexer_next(lexer_t* lexer); +extern void lexer_pass(lexer_t* lexer); -void lexer_next(lexer_t* lexer); -void lexer_pass(lexer_t* lexer); +extern token_t* lexer_get_next_token(lexer_t* lexer); -token_t* lexer_get_next_token(lexer_t* lexer); +extern token_t* lexer_get_string(lexer_t* lexer); -token_t* lexer_get_string(lexer_t* lexer); +extern token_t* lexer_get_comment(lexer_t* lexer); -token_t* lexer_get_comment(lexer_t* lexer); +extern token_t* lexer_get_id(lexer_t* lexer); -token_t* lexer_get_id(lexer_t* lexer); +extern token_t* lexer_next_token(lexer_t* lexer, token_t* token); -token_t* lexer_next_token(lexer_t* lexer, token_t* token); +extern char* lexer_get_c_as_string(lexer_t* lexer); -char* lexer_get_c_as_string(lexer_t* lexer); #endif diff --git a/src/include/token.h b/src/include/token.h index 709051a..147862c 100644 --- a/src/include/token.h +++ b/src/include/token.h @@ -1,5 +1,7 @@ #ifndef TOKEN_H #define TOKEN_H + + typedef struct TOKEN_STRUC { enum { TOKEN_ID, // keyword @@ -21,5 +23,7 @@ typedef struct TOKEN_STRUC { char* value; } token_t; -token_t* token_init(int type, char* value); +extern token_t* token_init(int type, char* value); + + #endif diff --git a/src/include/tree.h b/src/include/tree.h index 34e8e4f..1cf029c 100644 --- a/src/include/tree.h +++ b/src/include/tree.h @@ -19,19 +19,41 @@ typedef struct TREE_STRUC { TREE_SUBTREE, } type; - char* var_def_name; - struct TREE_STRUC* var_def_val; - - char* var_name; - - char* fn_call_name; - struct TREE_STRUC** fn_call_argv; - size_t fn_call_argsize; - - char* str_val; - - struct TREE_STRUC* subtree_val; - size_t subtree_size; + union tree_union { + + struct var_def_struc { + char* name; + struct TREE_STRUC* val; + int is_const; + } var_def; + + struct var_struc { + char* name; + } var; + + struct fn_def_struc { + char* name; + struct TREE_STRUC** val; + struct TREE_STRUC** argv; + size_t argsize; + } fn_def; + + struct fn_call_struc { + char* name; + struct TREE_STRUC** argv; + size_t argsize; + } fn_call; + + struct str_struc { + char* val; + } str; + + struct subtree_struc { + struct TREE_STRUC* val; + size_t size; + } subtree; + + } data; } tree_t; -- cgit v1.2.3