Starting declarations ;/
This commit is contained in:
22
parser.c
22
parser.c
@@ -91,16 +91,20 @@ Ast *parse_expr(Parser *p, int power_of_binding_to_right) {
|
||||
return n;
|
||||
}
|
||||
|
||||
Type *parse_declspec(Parser *p) {
|
||||
if (match_token(p, TOK_int)) {
|
||||
return type_int;
|
||||
} else {
|
||||
panicf("%s:%d: error: unknown token while parsing declspec", p->at->file, p->at->line);
|
||||
}
|
||||
}
|
||||
|
||||
Ast *parse_program(Parser *p) {
|
||||
for (;;) {
|
||||
if (match_keyword(p, keyword_int)) {
|
||||
Token *ident = expect_token(p, TOK_IDENT);
|
||||
expect_token(p, TOK_LPAREN);
|
||||
expect_token(p, TOK_RPAREN);
|
||||
} else {
|
||||
Token *token = next_token(p);
|
||||
panicf("invalid token");
|
||||
}
|
||||
Ast *result = create_ast(p->at, AST_PROGRAM);
|
||||
while (p->at->kind != TOK_EOF) {
|
||||
Type *type = parse_declspec(p);
|
||||
|
||||
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user