Skip to content

Commit 8057112

Browse files
authored
Update parser.c
1 parent 8c956ce commit 8057112

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

parser.c

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,18 @@ static void consume(TokenType type, const char* message) {
4545
error_at(&parser.current, message);
4646
}
4747

48+
static bool match(TokenType type) {
49+
if (parser.current.type == type) {
50+
advance();
51+
return true;
52+
}
53+
return false;
54+
}
55+
4856
static Expr* expression();
4957
static Stmt* statement();
5058
static Stmt* declaration();
59+
static Expr* unary();
5160

5261
static Expr* binary() {
5362
Expr* expr = unary();
@@ -93,5 +102,9 @@ void init_parser() {
93102
Stmt* parse() {
94103
init_parser();
95104
advance();
96-
return declaration();
105+
Stmt* stmt = NULL;
106+
while (!match(TOKEN_EOF)) {
107+
stmt = declaration();
108+
}
109+
return stmt;
97110
}

0 commit comments

Comments
 (0)