Starting declarations ;/

This commit is contained in:
Krzosa Karol
2026-05-23 17:48:42 +02:00
parent b1b79abfd4
commit bd97674f50
2 changed files with 17 additions and 9 deletions

4
ast.c
View File

@@ -39,6 +39,7 @@ struct Type {
typedef enum Ast_Kind {
AST_NONE,
AST_ERROR,
AST_PROGRAM,
AST_INT,
AST_UNARY,
AST_BINARY,
@@ -53,6 +54,9 @@ struct Ast {
Ast_Kind kind;
Token *pos;
Ast *first;
Ast *last;
union {
uint64_t u;
struct {

View File

@@ -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;
}