parser: implement subexpressions with parentheses
LOL I forgot to implement this before.
This commit is contained in:
parent
db91cf09fc
commit
ac6cc2154d
1 changed files with 4 additions and 0 deletions
|
@ -448,6 +448,8 @@ atom(ParserState *ps)
|
|||
tree->ident = t.ident;
|
||||
}
|
||||
return tree;
|
||||
case T_LPAREN:
|
||||
return expr(ps, EXPR_INIT_PREC);
|
||||
default:
|
||||
parse_error(ps, "expected a number, identifier or expression, not '%s'", TokenIdStr[t.id]);
|
||||
free(tree);
|
||||
|
@ -482,6 +484,8 @@ expr(ParserState *ps, int minprec)
|
|||
Ast *tree = unary(ps);
|
||||
for (;;) {
|
||||
LexToken t = lex_scan(ps->lexer);
|
||||
if (t.id == T_RPAREN)
|
||||
break;
|
||||
if (!token_is_binop(t.id)
|
||||
|| t.id == T_END
|
||||
|| OperatorTable[t.id].pred < minprec) {
|
||||
|
|
Loading…
Add table
Reference in a new issue