From b768269f91355292c7a5f5ecccdc80f6eec74634 Mon Sep 17 00:00:00 2001 From: David Phillips Date: Mon, 6 Aug 2018 01:06:51 +1200 Subject: Factor token definitions out --- gate.c | 2 +- gate.h | 2 +- lex.c | 2 +- lex.h | 34 +--------------------------------- token.h | 38 ++++++++++++++++++++++++++++++++++++++ 5 files changed, 42 insertions(+), 36 deletions(-) create mode 100644 token.h diff --git a/gate.c b/gate.c index a657194..c44cade 100644 --- a/gate.c +++ b/gate.c @@ -47,7 +47,7 @@ gate_add_generic(struct gate *array, size_t array_index, char *name, enum BINARY int gate_add(enum TOKEN_TYPE op, char *name, char *left, char *right) { /* FIXME */ - fprintf(stderr, "bop on %s and %s for gate %s not implemented", left, right, name); + fprintf(stderr, "bop on %s and %s for gate %s not implemented\n", left, right, name); return 1; } diff --git a/gate.h b/gate.h index 8be32a6..535e3b2 100644 --- a/gate.h +++ b/gate.h @@ -3,7 +3,7 @@ #include -#include "lex.h" +#include "token.h" #include "logic.h" enum NODE_TYPE { diff --git a/lex.c b/lex.c index 9e82175..a209a6c 100644 --- a/lex.c +++ b/lex.c @@ -4,7 +4,7 @@ #include #include "common.h" -#include "lex.h" +#include "token.h" #define emit_error(...) fprintf(stderr, "Error (%zd,%zd): ", line_number, 1 + column_number);\ fprintf(stderr, __VA_ARGS__) diff --git a/lex.h b/lex.h index 4c6662b..9a1be52 100644 --- a/lex.h +++ b/lex.h @@ -3,39 +3,7 @@ #include -#define MAX_IDENT_LENGTH 128 - -enum TOKEN_TYPE { - /* Keywords */ - TOK_MODULE, - TOK_INPUT, - TOK_EXPR, - TOK_COLON, - TOK_EOL, - TOK_OR, - TOK_AND, - TOK_XOR, - TOK_NOT, - TOK_NAND, - TOK_NOR, - - /* Etc */ - TOK_IDENT -}; - -struct location { - size_t line; - size_t column; - size_t leading_whitespace_len; -}; - -struct token { - enum TOKEN_TYPE type; - struct location loc; - char value[MAX_IDENT_LENGTH]; - size_t span; - struct token *next; -}; +#include "token.h" struct token* lex_file(FILE*); const char *get_token_description(enum TOKEN_TYPE); diff --git a/token.h b/token.h new file mode 100644 index 0000000..c00c870 --- /dev/null +++ b/token.h @@ -0,0 +1,38 @@ +#ifndef HENCE_TOKEN_H +#define HENCE_TOKEN_H + +#define MAX_IDENT_LENGTH 128 + +enum TOKEN_TYPE { + /* Keywords */ + TOK_MODULE, + TOK_INPUT, + TOK_EXPR, + TOK_COLON, + TOK_EOL, + TOK_OR, + TOK_AND, + TOK_XOR, + TOK_NOT, + TOK_NAND, + TOK_NOR, + + /* Etc */ + TOK_IDENT +}; + +struct location { + size_t line; + size_t column; + size_t leading_whitespace_len; +}; + +struct token { + enum TOKEN_TYPE type; + struct location loc; + char value[MAX_IDENT_LENGTH]; + size_t span; + struct token *next; +}; + +#endif -- cgit v1.1