New approach, new lexer
This commit is contained in:
53
new_parse.c
Normal file
53
new_parse.c
Normal file
@@ -0,0 +1,53 @@
|
||||
|
||||
typedef struct Parser{
|
||||
Token_Array array;
|
||||
Arena *arena;
|
||||
}Parser;
|
||||
|
||||
function Token *
|
||||
token_get(Parser *p){
|
||||
Token *result = p->array.iter_bucket->data + p->array.iter_len;
|
||||
return result;
|
||||
}
|
||||
|
||||
function Token *
|
||||
token_next(Parser *p){
|
||||
Token *result = token_array_iter_next(&p->array);
|
||||
return result;
|
||||
}
|
||||
|
||||
function Token *
|
||||
token_match(Parser *p, Token_Kind kind){
|
||||
Token *token = token_get(p);
|
||||
if(token->kind == kind){
|
||||
token = token_next(p);
|
||||
return token;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
|
||||
*/
|
||||
|
||||
function Expr *
|
||||
parse_expr_atom(Parser *p){
|
||||
Token *token = 0;
|
||||
if((token = token_match(p, TK_StringLit))){
|
||||
Expr *result = expr_str(p->arena, token);
|
||||
return result;
|
||||
}
|
||||
else if((token = token_match(p, TK_Int))){
|
||||
Expr *result = expr_int(p->arena, token);
|
||||
return result;
|
||||
}
|
||||
|
||||
invalid_codepath;
|
||||
return 0;
|
||||
}
|
||||
|
||||
function Expr *
|
||||
parse_expr(Parser *p){
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user