Starting declarations ;/
This commit is contained in:
4
ast.c
4
ast.c
@@ -39,6 +39,7 @@ struct Type {
|
|||||||
typedef enum Ast_Kind {
|
typedef enum Ast_Kind {
|
||||||
AST_NONE,
|
AST_NONE,
|
||||||
AST_ERROR,
|
AST_ERROR,
|
||||||
|
AST_PROGRAM,
|
||||||
AST_INT,
|
AST_INT,
|
||||||
AST_UNARY,
|
AST_UNARY,
|
||||||
AST_BINARY,
|
AST_BINARY,
|
||||||
@@ -53,6 +54,9 @@ struct Ast {
|
|||||||
Ast_Kind kind;
|
Ast_Kind kind;
|
||||||
Token *pos;
|
Token *pos;
|
||||||
|
|
||||||
|
Ast *first;
|
||||||
|
Ast *last;
|
||||||
|
|
||||||
union {
|
union {
|
||||||
uint64_t u;
|
uint64_t u;
|
||||||
struct {
|
struct {
|
||||||
|
|||||||
22
parser.c
22
parser.c
@@ -91,16 +91,20 @@ Ast *parse_expr(Parser *p, int power_of_binding_to_right) {
|
|||||||
return n;
|
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) {
|
Ast *parse_program(Parser *p) {
|
||||||
for (;;) {
|
Ast *result = create_ast(p->at, AST_PROGRAM);
|
||||||
if (match_keyword(p, keyword_int)) {
|
while (p->at->kind != TOK_EOF) {
|
||||||
Token *ident = expect_token(p, TOK_IDENT);
|
Type *type = parse_declspec(p);
|
||||||
expect_token(p, TOK_LPAREN);
|
|
||||||
expect_token(p, TOK_RPAREN);
|
|
||||||
} else {
|
|
||||||
Token *token = next_token(p);
|
|
||||||
panicf("invalid token");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user