scc

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

commit 080e69990174ad65f1611d8169a6b1f0f03414ea
parent 285d54fa5709638cd975b5fcfc6a54bed54b9abc
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Fri, 14 Aug 2015 18:13:50 +0200

Fix cast()

Cast() is a problematic function because we need see two tokens
of the input, but the second token can be a typename, so we can
not use ahead() because it only can return the next character
of the input. The solution is to duplicate the rules.
When cast() sees a '(' it means that can be a cast, or can be a
parentheses expression, so it accepts the '(' and calls expr(),
but due to the lost of recursivity the actions of postfix were
not applied, so the solution is to call a modified version of
postfix() before returning.

Diffstat:
Mcc1/expr.c | 10++++++----
1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/cc1/expr.c b/cc1/expr.c @@ -779,11 +779,12 @@ bad_type: } static Node * -postfix(void) +postfix(Node *lp) { - Node *lp, *rp; + Node *rp; - lp = primary(); + if (!lp) + lp = primary(); for (;;) { switch (yytoken) { case '[': @@ -869,7 +870,7 @@ unary(void) case '~': op = OCPL; fun = integeruop; break; case '&': op = OADDR; fun = address; break; case '*': op = OPTR; fun = content; break; - default: return postfix(); + default: return postfix(NULL); } next(); @@ -906,6 +907,7 @@ cast(void) default: rp = expr(); expect(')'); + rp = postfix(rp); break; }