diff --git a/src/lexer.h b/src/lexer.h new file mode 100644 index 0000000..b5f80c4 --- /dev/null +++ b/src/lexer.h @@ -0,0 +1,51 @@ +#ifndef _LEXER_H +#define _LEXER_H + +#include "types.h" + +/* + Code parser state +*/ +typedef enum { + PSTART, + PEXPR, + PARGS, + PINSTR +} ps_t; + +/* + Lexer (and parser) structure +*/ +typedef struct { + char * input; + char * last; // input before NextToken + char * next; + index_t line; // line number + token_t token; + number_t x; + index_t ix; + token_t type; + char name[MAXNAMELEN+1]; + char *arg; + index_t arglen; + ps_t ps; + int argN; + token_t lasttoken; + token_t uptoken; // which token, e.g. CCALL, calls compileexpr +#if HAS_FUNC > 0 + char fun[MAXNAMELEN+1]; // function name + index_t fp[2]; // for local variables stored on the stack + index_t level; // scope nesting level, basically we have only 0 (top-level) and 1 (function) +#endif +#if PROFILE>0 + index_t ntoken; +#endif +} lexer_t; + +void LookAheadToken(lexer_t *lex); +void SkipToken (lexer_t *lex); +void NextToken (lexer_t *lex); +void LexerInit(lexer_t *L); +void LexerSetup(lexer_t *lex, char * input); + +#endif