Re: for loops in C style

2008-02-29 Thread lfinsto1
>> Oh, I see. I thought you were writing a C-like interpreter that >> would actually execute the loop. In that case, you're right, and my >> point is irrelevant. I suppose what ultimately gets output is >> machine-code or assembler with a branch and a goto for the loop? > > Yes! you're righ

Re: for loops in C style

2008-02-29 Thread Ilyes Gouta
Hi Laurence, > Oh, I see. I thought you were writing a C-like interpreter that > would actually execute the loop. In that case, you're right, and my > point is irrelevant. I suppose what ultimately gets output is > machine-code or assembler with a branch and a goto for the loop? Yes! you'

Re: for loops in C style

2008-02-29 Thread Laurence Finston
On Fri, 29 Feb 2008, Ilyes Gouta wrote: > > > fexpr: /* Empty */ > > { > > /* Action for empty case */ > > }; > > > > fexpr: expr > > { > > /* Action for `expr' case */ > > }; > > I wasn't aware the one could duplicate a rule so that it has two > possible bodies. But it's alright, th

Re: for loops in C style

2008-02-29 Thread Ilyes Gouta
Hi Laurence, Thanks for your comments! > fexpr: /* Empty */ > { > /* Action for empty case */ > }; > > fexpr: expr > { > /* Action for `expr' case */ > }; I wasn't aware the one could duplicate a rule so that it has two possible bodies. But it's alright, there is a second, much prett

Re: for loops in C style

2008-02-29 Thread Evan Lavelle
Ilyes Gouta wrote: Basically what it's done is enumerating all the possibilities for the construction of the for loop. Is it the only way do things clearly and properly? There's no 'clear and proper' way to do this; do whatever's best for you, try it, fix it, repeat. Here's what I do: itera

Re: for loops in C style

2008-02-29 Thread Laurence Finston
On Fri, 29 Feb 2008, Ilyes Gouta wrote: > If I setup a new fexpr (and a new fassignment) that would accept > nothing or expression, i.e: > > fexpr: > | expr; > > for_stmt: > for (fassignment; fexpr; fassignment) block > > How can I define an action that would be triggered only for the e

Re: for loops in C style

2008-02-29 Thread Ilyes Gouta
OK, got it. One has just to define fexpr as: fexpr: ';' { action1(); } | expr ';'{ action2(); } and to redefine for_stmt as: for_stmt: for (assignment expr assignment) block ; to get the right behavior. :) Thanks again, guys! Best regards, Ilyes Gouta. On Fri, Feb 29,

Re: for loops in C style

2008-02-29 Thread Ilyes Gouta
Hi! Thanks for your help. If I setup a new fexpr (and a new fassignment) that would accept nothing or expression, i.e: fexpr: | expr; for_stmt: for (fassignment; fexpr; fassignment) block How can I define an action that would be triggered only for the empty expressions? (I have to diff

Re: for loops in C style

2008-02-28 Thread Hans Aberg
On 28 Feb 2008, at 15:16, Ilyes Gouta wrote: I'm writing a small grammar for a very simplified C language. My goal is to produce an AST once a script file is parsed by the flex/bison tools. I got almost everything working nicely, except for the C style for loops. ... How one would modify the

Re: for loops in C style

2008-02-28 Thread Bob Rossi
On Thu, Feb 28, 2008 at 03:16:40PM +0100, Ilyes Gouta wrote: > Hi! > > I'm writing a small grammar for a very simplified C language. My goal > is to produce an AST once a script file is parsed by the flex/bison > tools. I got almost everything working nicely, except for the C style > for loops. >

for loops in C style

2008-02-28 Thread Ilyes Gouta
Hi! I'm writing a small grammar for a very simplified C language. My goal is to produce an AST once a script file is parsed by the flex/bison tools. I got almost everything working nicely, except for the C style for loops. Let's assume that we have a rule like this: unary: const | id ; ex