scc

simple C compiler
git clone git://git.2f30.org/scc
Log | Files | Refs | README | LICENSE

commit a0796b4c04fdb332658a59a571897a4db17a3bbe
parent f971c72c570d9836184ee6beca0757fd87498b37
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Thu,  9 Oct 2014 18:03:21 +0200

Fix cast()
This function has a problem because a '(' can means a expression
between parentheses or may be a cast. If we read the '(' then
we cannot call to unary(), because then primary() will not read
the parenthesis needed for calling expr(). The solution of course
is to call expr() directly in cast().

This function is called when

Diffstat:
Mcc1/expr.c | 19++++++++-----------
1 file changed, 8 insertions(+), 11 deletions(-)

diff --git a/cc1/expr.c b/cc1/expr.c @@ -559,15 +559,17 @@ unary(void) } static Node * -cast2(void) +cast(void) { register Node *np1, *np2; register Type *tp; - switch(yytoken) { + if (!accept('(')) + return unary(); + + switch (yytoken) { case TQUALIFIER: case TYPE: tp = typename(); - expect(')'); switch (tp->op) { case ARY: error("cast specify an array type"); @@ -582,17 +584,12 @@ cast2(void) } break; default: - np2 = unary(); - expect(')'); + np2 = expr(); break; } - return np2; -} + expect(')'); -static Node * -cast(void) -{ - return (accept('(')) ? cast2() : unary(); + return np2; } static Node *