summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Phillips <david@sighup.nz>2018-08-06 01:06:51 +1200
committerDavid Phillips <david@sighup.nz>2018-08-06 01:06:51 +1200
commitb768269f91355292c7a5f5ecccdc80f6eec74634 (patch)
tree60eabd4d2388c10ee7339e30ed1f7ce334081b3b
parent5652b840200cada7686196cffc1c7c62b2b91ed9 (diff)
downloadhence-b768269f91355292c7a5f5ecccdc80f6eec74634.tar.xz
Factor token definitions out
-rw-r--r--gate.c2
-rw-r--r--gate.h2
-rw-r--r--lex.c2
-rw-r--r--lex.h34
-rw-r--r--token.h38
5 files changed, 42 insertions, 36 deletions
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 <stddef.h>
-#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 <string.h>
#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 <stdio.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;
-};
+#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