Mail Archives: djgpp/2002/07/12/20:59:01
Hello.
maxam_80 wrote:
[snip]
> When I run Bison with standard data type, i.e int, no problem, I
> successfully compile. But when I compile it on string-oriented version
> of the same grammar, it fails.
What errors do you get?
[snip]
> /************************/
> /* Regles grammaticales ***********************************************/
>
> %%
> Entree :
> /* Epsilon */ { ; }
> | Ligne Entree { ; }
> ;
>
> Ligne :
> '\n' { $$ = memset($$, 0, LG_LIGNE); }
> | Expression '\n' { $$ = memset($$, 0, LG_LIGNE);
> printf("\t%s\n", $1);
> }
> ;
>
> Expression :
> Chiffre Expression { $$ = strcat($$, $1);
> $$ = strcat($$, $2);
> }
> | Chiffre { $$ = strcat($$, $1); }
> ;
[snip]
I think you need an empty branch, so that Expression can terminate. Also, you
should use left-recursion, so that the memory usage is bounded. I think you
should try something like this:
Expression:
| Expression Chiffre { $$ = strcat($$, $2); }
;
Ah, but then your string will be constructed in the wrong order, I think.
Hmmm.
Regards,
--
Richard Dawe [ http://www.phekda.freeserve.co.uk/richdawe/ ]
- Raw text -