diff options
Diffstat (limited to 'src/include')
-rw-r--r-- | src/include/hlkt.h | 10 | ||||
-rw-r--r-- | src/include/lexer.h | 5 | ||||
-rw-r--r-- | src/include/pp.h | 55 | ||||
-rw-r--r-- | src/include/token.h | 3 | ||||
-rw-r--r-- | src/include/util.h | 10 |
5 files changed, 73 insertions, 10 deletions
diff --git a/src/include/hlkt.h b/src/include/hlkt.h index 4496ce1..ebcb7f6 100644 --- a/src/include/hlkt.h +++ b/src/include/hlkt.h @@ -10,17 +10,19 @@ static int hlkt_failed = 0; /* number of tests that have failed */ #define HLKT_LOG() HLKT_HIDE( \ if ((hlkt_run > 0) && (hlkt_failed > 0)) { \ - log_war("HLKT: %d/%d tests failed", hlkt_failed, hlkt_run); \ + log_err("HLKT: %d/%d tests failed", hlkt_failed, hlkt_run); \ } else { \ - log_inf("HLKT: all %d tests passed", hlkt_run); \ + log_dbg("HLKT: all %d tests passed", hlkt_run); \ } \ ) #define HLKT_ASS(pred) HLKT_HIDE( \ hlkt_run ++; \ - if (! pred) { \ + if (! (pred)) { \ hlkt_failed ++; \ - log_err("HLKT: test [%s] failed: %s:%s:%d", #pred, __FILE__, __func__, __LINE__); \ + log_war("HLKT: test failed: %s/%s/%d", __FILE__, __func__, __LINE__); \ + } else { \ + log_dbg("HLKT: test passed: %s/%s/%d", __FILE__, __func__, __LINE__); \ } \ ) diff --git a/src/include/lexer.h b/src/include/lexer.h index 173c57d..b2bf9eb 100644 --- a/src/include/lexer.h +++ b/src/include/lexer.h @@ -28,6 +28,9 @@ typedef struct LEXER_STRUC { /* the linked list of tokens generated */ token_t* tokenl; + /* pointer to the last token in tokenl */ + token_t* tokenl_last; + /* number of tokens in tokenl */ int tokenc; } lexer_t; @@ -37,7 +40,7 @@ lexer_t* lexer_init (char* src); /* destroy lexer **but not src or tokenl** */ void lexer_destroy (lexer_t* lexer); -/* add token to tokenv */ +/* add token to tokenl */ void lexer_add_token(lexer_t* lexer, token_t* token); /* add the current character as a token to tokenl -- utility function for lexer_do_reg() */ diff --git a/src/include/pp.h b/src/include/pp.h new file mode 100644 index 0000000..d82907c --- /dev/null +++ b/src/include/pp.h @@ -0,0 +1,55 @@ +#ifndef PP_H +#define PP_H + +#include <stdlib.h> +#include <string.h> + +#include "util.h" +#include "syntax.h" + +/* TODO */ +typedef struct MACRO_STRUC { + char* id; + char* val; +} macro_t; + +/* + preprocessor struct + + TODO: keep track of macros +*/ +typedef struct PP_STRUC { + /* original source */ + char* src; + + /* pre-processed source */ + char* psrc; + + /* what the preprocessor is looking at right now */ + enum PP_STATE { + PP_STATE_REG, /* regular */ + PP_STATE_STR, /* string */ + PP_STATE_COM, /* comment */ + PP_STATE_ESC, /* escaped character in string */ + /* PP_STATE_MCO, */ /* macro */ + } state; +} pp_t; + +/* creates a new preprocessor from some source code */ +pp_t* pp_init(char*); + +/* destroys the preprocessor **but not the pre-processed source** */ +void pp_destroy(pp_t*); + +/* copy over the current character from src to psrc */ +void pp_cpy_char(pp_t*); + +void pp_do_reg(pp_t*); +void pp_do_str(pp_t*); +void pp_do_com(pp_t*); + +/* run the preprocessor */ +void pp_run(pp_t*); + +#endif + diff --git a/src/include/token.h b/src/include/token.h index 802f13d..6779755 100644 --- a/src/include/token.h +++ b/src/include/token.h @@ -2,6 +2,7 @@ #define TOKEN_H #include "util.h" +#include "hlkt.h" /* token struct */ typedef struct TOKEN_STRUC { @@ -35,7 +36,7 @@ typedef struct TOKEN_STRUC { /* creates a token */ token_t* token_init(int type, char* val); -/* destroys a token **and all tokens contained in nxt** */ +/* 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 */ diff --git a/src/include/util.h b/src/include/util.h index 712af43..cfc85c2 100644 --- a/src/include/util.h +++ b/src/include/util.h @@ -7,16 +7,18 @@ #include <stdio.h> -/* die and leave message */ -void die(const char*, ...); -/* log an error */ -void log_err(const char*, ...); +/* log some debug information */ +void log_dbg(const char*, ...); /* log some information */ void log_inf(const char*, ...); /* log something with no formatting */ void log_raw(const char*, ...); /* log a warning */ void log_war(const char*, ...); +/* log an error */ +void log_err(const char*, ...); +/* die and leave message */ +void die(const char*, ...); /* if calloc() returns null, die */ void* ecalloc(size_t, size_t); |