On 2013/05/09 13:05, Lee wrote:
> I have the flex file defined as:
...
> SYMBOL_ID [a-zA-Z]+[a-zA-Z0-9_]*
...
> %%
...
> {SYMBOL_ID} { printf("2.yylval = %s\n", yytext);
> yylval.all_str = yytext;
> return (SYMBOLID);
> }
...
> %%
You have forgotten to copy the string pointed at by yytext...
> and the grammar as:
...
> %%
> program
> : FUNCTION SYMBOLID '(' SYMBOLID ')'
> { printf("FUNCTION SYMBOL = %s\n", $2);
> printf("func name and args: '%s' '%s'\n", $2, $4);
> }
...so here, the action will only be executed after all grammar
components have been pointed at, and then yytext of the first SYMBOLID
points at something else. If you are using C, then you must also clean
up allocated strings no longer in use. In C++, this can be done using
the std::string class.