core: Add initial lexer and parser sources

Signed-off-by: Ian Moffett <ian@mirocom.org>
This commit is contained in:
2026-02-14 00:11:26 -05:00
parent f249a12b5a
commit 9e22c31a2f
5 changed files with 182 additions and 0 deletions

51
core/parser.c Normal file
View File

@@ -0,0 +1,51 @@
#include <stdint.h>
#include <stddef.h>
#include "rifle/parser.h"
#include "rifle/token.h"
#include "rifle/trace.h"
#include "rifle/lexer.h"
#include "rifle/state.h"
/* Symbolic token */
#define symtok(tok) \
"[" tok "]"
/* Quoted token */
#define qtok(tok) \
"'" tok "'"
/* Convert token to string */
#define tokstr1(tt) \
toktab[(tt)]
/* Convert token to string */
#define tokstr(tok) \
tokstr1((tok)->type)
/*
* Table used to convert token constants into human
* readable strings
*/
static const char *toktab[] = {
[TT_NONE] = symtok("none"),
[TT_PLUS] = qtok("+"),
[TT_MINUS] = qtok("-"),
[TT_STAR] = qtok("*"),
[TT_SLASH] = qtok("/")
};
int
parser_parse(struct rifle_state *state)
{
struct token tok;
if (state == NULL) {
return 0;
}
while (lexer_scan(state, &tok) == 0) {
trace_debug("got %s\n", tokstr(&tok));
}
return 0;
}