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
;

expr:
    unary
|   expr + expr
|   expr - expr
|   expr * expr
|   expr / expr
;

assignment:
    id '=' expr ';'
;

for_stmt:
    for (assignment; expr; assignment) block
;

My problem is that I'd like to support loops with empty assignment and
expr parts (i.e, always true loops and the likes) such as:

int a, b, c;

for (;;) {
    c = a + b;
}

but I couldn't find a way to identify an empty assignment (or
expression) and to define the action associated (to push/construct a
new node within my AST). How one would modify the grammar to take into
account such a scenario?

Any ideas?

Best regards,
Ilyes Gouta.


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

Reply via email to