Starting declarations ;/
This commit is contained in:
4
ast.c
4
ast.c
@@ -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 {
|
||||
|
||||
20
parser.c
20
parser.c
@@ -91,17 +91,21 @@ Ast *parse_expr(Parser *p, int power_of_binding_to_right) {
|
||||
return n;
|
||||
}
|
||||
|
||||
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);
|
||||
Type *parse_declspec(Parser *p) {
|
||||
if (match_token(p, TOK_int)) {
|
||||
return type_int;
|
||||
} else {
|
||||
Token *token = next_token(p);
|
||||
panicf("invalid token");
|
||||
panicf("%s:%d: error: unknown token while parsing declspec", p->at->file, p->at->line);
|
||||
}
|
||||
}
|
||||
|
||||
Ast *parse_program(Parser *p) {
|
||||
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