help-bison
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: for loops in C style


From: Evan Lavelle
Subject: Re: for loops in C style
Date: Fri, 29 Feb 2008 09:57:51 +0000
User-agent: Thunderbird 2.0.0.12 (Windows/20080213)

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:

iteration_statement
     ...
   | FOR '(' loop_init ';' loop_cond_opt ';' loop_term ')' loop_body {
       ...
     }
   ;

loop_init
   : /* nothing */               { ... }
   | full_expr                   { ... }
   ;

loop_cond_opt
   : /* nothing */               { ... }
   | full_expr                   { ... }
   ;

loop_term
   : /* nothing */               { ... }
   | full_expr                   { ... }
   ;

loop_body : ... ;

You can trivially change or fix the grammar; the real problem is the actions, and how you construct the AST. You'll also find that C grammars aren't much use to you, because assignments aren't expressions in your language.

Evan




reply via email to

[Prev in Thread] Current Thread [Next in Thread]