move parse open parens out of parse_function
This commit is contained in:
parent
49329273d3
commit
a44abe5e73
1 changed files with 8 additions and 4 deletions
|
|
@ -43,7 +43,6 @@ char* parse_identifier(TokenArray tokens, unsigned* tokens_index) {
|
||||||
|
|
||||||
Expr parse_expr(TokenArray tokens, unsigned* tokens_index);
|
Expr parse_expr(TokenArray tokens, unsigned* tokens_index);
|
||||||
Expr parse_function(TokenArray tokens, unsigned* tokens_index, char* name) {
|
Expr parse_function(TokenArray tokens, unsigned* tokens_index, char* name) {
|
||||||
parse_token(tokens, tokens_index, OPENPAREN);
|
|
||||||
Expr* exprs = (Expr*)malloc((tokens.length - *tokens_index) * sizeof(Expr));
|
Expr* exprs = (Expr*)malloc((tokens.length - *tokens_index) * sizeof(Expr));
|
||||||
unsigned expr_index = 0;
|
unsigned expr_index = 0;
|
||||||
while (*tokens_index < tokens.length && tokens.tokens[*tokens_index].tag != CLOSEPAREN) {
|
while (*tokens_index < tokens.length && tokens.tokens[*tokens_index].tag != CLOSEPAREN) {
|
||||||
|
|
@ -79,7 +78,7 @@ Expr parse_expr(TokenArray tokens, unsigned* tokens_index) {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
case IDENTIFIER: {
|
case IDENTIFIER: {
|
||||||
if (*tokens_index < tokens.length && tokens.tokens[*tokens_index].tag == OPENPAREN) {
|
if (maybe_parse_token(tokens, tokens_index, OPENPAREN)) {
|
||||||
return parse_function(tokens, tokens_index, token.data.identifier);
|
return parse_function(tokens, tokens_index, token.data.identifier);
|
||||||
} else {
|
} else {
|
||||||
return (Expr) {
|
return (Expr) {
|
||||||
|
|
@ -132,8 +131,8 @@ Stmt parse_stmt(TokenArray tokens, unsigned* tokens_index) {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
// Expression
|
// Expression
|
||||||
else {
|
else if (maybe_parse_token(tokens, tokens_index, OPENPAREN)) {
|
||||||
Expr expr = parse_function(tokens, tokens_index, identifier);
|
Expr expr = parse_function(tokens, tokens_index, identifier);
|
||||||
|
|
||||||
return (Stmt) {
|
return (Stmt) {
|
||||||
.tag = EXPR,
|
.tag = EXPR,
|
||||||
|
|
@ -142,6 +141,11 @@ Stmt parse_stmt(TokenArray tokens, unsigned* tokens_index) {
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
// Error
|
||||||
|
else {
|
||||||
|
fprintf(stderr, "Parse error: Unexpected token. Expected '(' or '='");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
StmtArray parse_block(TokenArray tokens, unsigned* tokens_index) {
|
StmtArray parse_block(TokenArray tokens, unsigned* tokens_index) {
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue