diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/include/lexer.h | 32 | ||||
-rw-r--r-- | src/include/token.h | 3 | ||||
-rw-r--r-- | src/lexer.c | 19 |
3 files changed, 36 insertions, 18 deletions
diff --git a/src/include/lexer.h b/src/include/lexer.h index 83ace59..d83e35f 100644 --- a/src/include/lexer.h +++ b/src/include/lexer.h @@ -18,14 +18,14 @@ typedef struct LEXER_STRUC { LEXER_STATE_REG, /* definition tag */ LEXER_STATE_TAG, - /* escaped character in string */ - LEXER_STATE_ESC, /* string */ LEXER_STATE_STR, - /* definition */ - LEXER_STATE_DEF, - /* call */ - LEXER_STATE_CAL + /* escaped character in string */ + LEXER_STATE_STR_ESC, + /* integer */ + LEXER_STATE_INT, + /* keyword */ + LEXER_STATE_KWD, } state; /* the linked list of tokens generated */ @@ -52,19 +52,19 @@ void lexer_add_current_char(lexer_t* lexer, int type); void lexer_add_current_char_to_last_token(lexer_t* lexer, int type); /* handle regular state */ -void lexer_do_reg(lexer_t*); +void lexer_do_reg(lexer_t* lexer); /* handle definition tag state*/ -void lexer_do_tag(lexer_t*); -/* handle character state */ -void lexer_do_chr(lexer_t*); +void lexer_do_tag(lexer_t* lexer); +/* TODO: handle character state */ +void lexer_do_chr(lexer_t* lexer); /* handle string state */ -void lexer_do_str(lexer_t*); -/* handle definition state */ -void lexer_do_def(lexer_t*); -/* handle call state */ -void lexer_do_cal(lexer_t*); +void lexer_do_str(lexer_t* lexer); +/* handle integer */ +void lexer_do_int(lexer_t* lexer); +/* handle keywords */ +void lexer_do_kwd(lexer_t* lexer); /* run lexer */ -void lexer_run(lexer_t*); +void lexer_run(lexer_t* lexer); #endif diff --git a/src/include/token.h b/src/include/token.h index a186fa9..129ed76 100644 --- a/src/include/token.h +++ b/src/include/token.h @@ -23,7 +23,8 @@ typedef struct TOKEN_STRUC { TOKEN_RBLOCK, TOKEN_RLIST, TOKEN_LLIST, - TOKEN_ESC + TOKEN_ESC, + TOKEN_INT } type; /* token value */ diff --git a/src/lexer.c b/src/lexer.c index 7f36b98..d52029c 100644 --- a/src/lexer.c +++ b/src/lexer.c @@ -92,7 +92,14 @@ void lexer_do_reg(lexer_t* lexer) { lexer->state = LEXER_STATE_STR; break; default: - lexer_add_current_char(lexer, TOKEN_UNKNOWN); + if (isdigit(*lexer->src)) { + lexer_add_current_char(lexer, TOKEN_INT); + lexer->state = LEXER_STATE_INT; + } else { + lexer_add_current_char(lexer, TOKEN_UNKNOWN); + lexer->state = LEXER_STATE_REG; + } + } } @@ -121,11 +128,21 @@ void lexer_do_str(lexer_t* lexer) { } } +void lexer_do_int(lexer_t* lexer) { + if (isdigit(*lexer->src)) { + lexer_add_current_char_to_last_token(lexer, TOKEN_INT); + if (! isdigit(*(lexer->src + 1))) { lexer->state = LEXER_STATE_REG; } + } else { + log_err("???"); + } +} + void lexer_run(lexer_t* lexer) { while (*lexer->src) { if (lexer->state == LEXER_STATE_REG) { lexer_do_reg(lexer); } else if (lexer->state == LEXER_STATE_TAG) { lexer_do_tag(lexer); } else if (lexer->state == LEXER_STATE_STR) { lexer_do_str(lexer); } + else if (lexer->state == LEXER_STATE_INT) { lexer_do_int(lexer); } lexer->src ++; } |