Path: csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!news.misty.com!news.iecc.com!.POSTED!nerds-end From: Hans Aberg Newsgroups: comp.compilers Subject: Re: parsing function name and arguments Date: Fri, 10 May 2013 22:24:30 +0200 Organization: A noiseless patient Spider Lines: 31 Sender: johnl@iecc.com Approved: comp.compilers@iecc.com Message-ID: <13-05-007@comp.compilers> References: <13-05-005@comp.compilers> NNTP-Posting-Host: news.iecc.com Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Trace: leila.iecc.com 1368249582 80555 64.57.183.58 (11 May 2013 05:19:42 GMT) X-Complaints-To: abuse@iecc.com NNTP-Posting-Date: Sat, 11 May 2013 05:19:42 +0000 (UTC) Keywords: lex, debug Posted-Date: 11 May 2013 01:19:42 EDT X-submission-address: compilers@iecc.com X-moderator-address: compilers-request@iecc.com X-FAQ-and-archives: http://compilers.iecc.com Xref: csiph.com comp.compilers:893 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.