core: Add initial lexer and parser sources
Signed-off-by: Ian Moffett <ian@mirocom.org>
This commit is contained in:
51
core/parser.c
Normal file
51
core/parser.c
Normal 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;
|
||||
}
|
||||
Reference in New Issue
Block a user