tinyvm/include/tvm/tvm_lexer.h
Payton Turnage e99a0428f3 Implement defines using the htab structure.
The htab_structure has been modified in two ways, which should not break
compatability with any of its uses.

It includes a void pointer, which is in this commit used to point to a
string for defines, and will in the future be used to point to the address
space for words, bytes, and double words.

It now includes a function htab_add_str specifically for storing strings.
It calls htab_add so as not to be redundant, but makes the node's value
their index for the lexer to fetch using htab_find, and assigns their
void pointer.

The lexer will now use htab_find on all tokens to see if they are a define
string, and if so, substitute them with the appropriate token.

The defines htab is destroyed after lexing, because that memory is done.
2014-01-13 10:20:21 -05:00

21 lines
396 B
C

#ifndef TVM_LEXER_H_
#define TVM_LEXER_H_
#define MAX_ARGS 2
#define MAX_TOKENS 4
#include "tvm_htab.h"
typedef struct tvm_lexer_s
{
char **source_lines;
char ***tokens;
} tvm_lexer_t;
tvm_lexer_t *lexer_create();
void lexer_destroy(tvm_lexer_t *l);
/* Tokenize the character array "source" into lines and tokens */
void lex(tvm_lexer_t *lexer, char *source, tvm_htab_t *defines);
#endif