diff options
| author | Ian M. <ian@aptel.org> | 2026-10-03 06:25:43 +0000 |
|---|---|---|
| committer | Ian M. <ian@aptel.org> | 2026-10-03 06:25:43 +0000 |
| commit | 34fc6119714b999bae5aaf08697453dca500f705 (patch) | |
| tree | 0c03967204996f943d903b47f7b201ad73d6e817 /core/parser.c | |
| parent | 8e838a73368d5f26fee796d6ddb065e21449e989 (diff) | |
frontend: Add lexer+parser groundwork
Signed-off-by: Ian M. <ian@aptel.org>
Diffstat (limited to 'core/parser.c')
| -rw-r--r-- | core/parser.c | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/core/parser.c b/core/parser.c new file mode 100644 index 0000000..6cf0a4e --- /dev/null +++ b/core/parser.c @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2026, Apollo Telephone Laboratories. + * Provided under the BSD-3 clause. + */ + +#include <stdint.h> +#include <stddef.h> +#include <atas/lexer.h> + +/* Symbolic token */ +#define SYMTOK(TOK) \ + "[" TOK "]" + +/* Literal token */ +#define LITTOK(TOK) \ + "'" TOK "'" + +/* + * Safe macro to index toktab + */ +#define TOK_STR(TT) \ + ((TT) >= TT_MAX) \ + ? "bad" \ + : toktab[(TT)] + +/* + * Lookup table to convert token constants into + * strings. + */ +static const char *toktab[] = { + [TT_NONE] = SYMTOK("NONE"), + [TT_COMMA] = LITTOK(",") +}; + +int +atas_parse(struct atas_state *state) +{ + int error; + struct atas_token tok; + + if (state == NULL) { + return -1; + } + + for (;;) { + error = atas_lexer_scan(state, &tok); + if (error < 0) { + break; + } + + printf("got token %s\n", TOK_STR(tok.type)); + } + + return 0; +} |
