summaryrefslogtreecommitdiff
path: root/c/token.c
diff options
context:
space:
mode:
authorThomas Bracht Laumann Jespersen <t@laumann.xyz>2025-02-02 08:59:12 +0100
committerThomas Bracht Laumann Jespersen <t@laumann.xyz>2025-02-02 08:59:12 +0100
commitd8321c1947b644888f92795a75645d0c91a6a92d (patch)
tree058d5e9e66463b9b173e513c3244a4da93c0a28c /c/token.c
parent7b72404f5ec31a29aafa6faaf9c284487c819175 (diff)
c/lex: mostly functional lexerHEADmaster
Still need to parse numbers, but otherwise the lexer looks functional. It provides location information for each token (something the OCaml impl does not do).
Diffstat (limited to 'c/token.c')
-rw-r--r--c/token.c13
1 files changed, 8 insertions, 5 deletions
diff --git a/c/token.c b/c/token.c
index 85e8e43..6acfe3a 100644
--- a/c/token.c
+++ b/c/token.c
@@ -1,5 +1,8 @@
#include <assert.h>
#include <string.h>
+#include <stddef.h>
+#include <stdint.h>
+#include "types.h"
#include "token.h"
static char *tokennames[] = {
@@ -8,11 +11,11 @@ static char *tokennames[] = {
[Treturn] = "return",
[Tident] = "identifier",
[Tconstant] = "constant",
- [Tlparen] = "lparen",
- [Trparen] = "rparen",
- [Tlbrace] = "lbrace",
- [Trbrace] = "rbrace",
- [Tsemicolon] = "semicolon",
+ [Tlparen] = "(",
+ [Trparen] = ")",
+ [Tlbrace] = "{",
+ [Trbrace] = "}",
+ [Tsemicolon] = ";",
};
static_assert(sizeof(tokennames) / sizeof(char *) == Ntok, "token name map out of sync with tokens");