Consider the following grammar rule:
forstmt: for openparentheses nexpr semicolon expr semicolon nexpr closeparentheses stmt {}
nexpr: expr { }
| %empty { }
expr: .
.
.
// something huge
.
.
.
It is a parser rul for a for loop like below (a usual C like for loop):
for(i=0; i<10; i++){
Print("hello world");
}
I got to generate IR for this C like for loop (forstmt).
The IR for expr is already written.
The point is that the last nexpr's IR should go after the stmt.
I know about mid-rule actions and I thought that somehow I could solve this using a stack, but my thoughts didn't lead to any conclusions.
Precisely is there a way to stop bison from generating IR for the last nexpr and make it generate after the stmt ?
In other words, how to make all action of the last nexpr go after the stmt ?
Has anyone had a problem like this ?
It must be done by hand!
Bison doesn't have or even it shouldn't have anything for that!
My solution was to some how set a bit somewhere to hold the generated IR in code generator and the release it after the for loop's
stmt.