lexer.h (965B)
1 #ifndef __LEXER_H_ 2 #define __LEXER_H_ 3 #include <stdint.h> 4 #include <string.h> 5 6 #define SAVE(lexer) lex __SAVE_LEX = *lexer; 7 #define RESTORE(lexer) memcpy(lexer, &__SAVE_LEX, sizeof(lex)); 8 9 enum lex_ops { 10 NOP = 0, 11 ADD = '+', 12 SUB = '-', 13 MUL = '*', 14 DIV = '/', 15 OBRACE = '(', 16 CBRACE = ')', 17 OCBRACE = '{', 18 CCBRACE = '}', 19 OSBRACE = '[', 20 CSBRACE = ']', 21 DQUOTE = '\"', 22 LEOF = '$', 23 ASSIGN = '=', 24 SEMI = ';', 25 COMMA = ',', 26 ADDROF = '&', 27 FUNC = 256, 28 INT, 29 FLOAT, 30 NAME, 31 WALRUS, 32 RETURN, 33 34 /* used by the parser, wont be assigned by the lexer */ 35 FUNCALL, 36 CAST, 37 NEGATE, 38 DEREF, 39 }; 40 41 typedef struct lex { 42 char *input, *ptr, *prev, *name; 43 } lex; 44 45 typedef struct tok { 46 enum lex_ops op; 47 lex l; 48 union { 49 int64_t n; 50 double f; 51 char *name; 52 }; 53 } tok; 54 55 typedef struct loc { 56 int line, col; 57 } loc; 58 59 loc findloc(lex l); 60 loc findloctok(tok t); 61 void lexErr(lex *l); 62 char *unlex(lex *l); 63 tok next(lex *l); 64 void printTok(tok *t); 65 lex mklexer(char *input); 66 67 #endif