From 722c7f08e409d1f6f3a26bda666c15d7082f52e3 Mon Sep 17 00:00:00 2001 From: mrb0nk500 Date: Tue, 15 Feb 2022 18:49:29 -0400 Subject: igen: Start work on a better lexer. The other one I was about to do would've been harder to read, and understand. So, I've decided to write a more readable version. --- igen/lexer.h | 82 +++++++++++++++++++++++++++++++++--------------------------- 1 file changed, 45 insertions(+), 37 deletions(-) (limited to 'igen/lexer.h') diff --git a/igen/lexer.h b/igen/lexer.h index ba81cb1..454d2e1 100644 --- a/igen/lexer.h +++ b/igen/lexer.h @@ -1,45 +1,53 @@ #ifndef LEXER_H #define LEXER_H -typedef enum atom atom; -typedef struct lexeme lexeme; - -enum atom { - ATOM_LBRACK, - ATOM_RBRACK, - ATOM_SLASH, - ATOM_PLUS, - ATOM_MINUS, - ATOM_ASTR, - ATOM_PRCNT, - ATOM_AMPR, - ATOM_PIPE, - ATOM_CARROT, - ATOM_HASH, - ATOM_COL, - ATOM_SCOL, - ATOM_SPACE, - ATOM_USCORE, - ATOM_EQUAL, - ATOM_DOT, - ATOM_QMARK, - ATOM_BANG, - ATOM_LT, - ATOM_GT, - ATOM_PERCENT, - ATOM_COMMA, - ATOM_BSLASH, - ATOM_QUOTE, - ATOM_SQUOTE, - ATOM_TAB, - ATOM_NLINE, - ATOM_ALPHA, - ATOM_NUM, - ATOM_NONE, - NUM_ATOMS +#include + +typedef enum stmt_type stmt_type; +typedef enum cond_type cond_type; +typedef struct alt_stmt alt_stmt; +typedef struct cond_stmt cond_stmt; +typedef struct stmt stmt; + +enum stmt_type { + STMT_DIR, + STMT_FUNC, + STMT_EXPR, + STMT_COND, + STMT_COMP, + NUM_STMTS +}; + +enum cond_type { + COND_IF, + COND_FOR, + COND_WHILE, + COND_DO_WHILE, + NUM_CONDS +}; + +struct alt_stmt { + int type; + size_t offset; + void *(*lex)(char **str, int dbg); +}; + +struct cond_stmt { + cond_type type; + expr *expr; + stmt *stmt; }; -struct lexeme { +struct stmt { + stmt_type type; + union { + dir *dir; + func *func; + expr *expr; + cond_stmt *cond_stmt; + stmt *down; + }; + stmt *next; }; extern int lex(char *str, int dbg); -- cgit v1.2.3-13-gbd6f