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


_______________________________________________
help-bison@gnu.org http://lists.gnu.org/mailman/listinfo/help-bison

Reply via email to