Related articles |
---|
parsing function name and arguments lchaplin13@gmail.com (Lee) (2013-05-09) |
Re: parsing function name and arguments haberg-news@telia.com (Hans Aberg) (2013-05-10) |
From: | Hans Aberg <haberg-news@telia.com> |
Newsgroups: | comp.compilers |
Date: | Fri, 10 May 2013 22:24:30 +0200 |
Organization: | A noiseless patient Spider |
References: | 13-05-005 |
Keywords: | lex, debug |
Posted-Date: | 11 May 2013 01:19:42 EDT |
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.
Return to the
comp.compilers page.
Search the
comp.compilers archives again.