Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.compilers > #893

Re: parsing function name and arguments

From Hans Aberg <haberg-news@telia.com>
Newsgroups comp.compilers
Subject Re: parsing function name and arguments
Date 2013-05-10 22:24 +0200
Organization A noiseless patient Spider
Message-ID <13-05-007@comp.compilers> (permalink)
References <13-05-005@comp.compilers>

Show all headers | View raw


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.

Back to comp.compilers | Previous | Next — Previous in thread | Find similar | Unroll thread


Thread

parsing function name and arguments Lee <lchaplin13@gmail.com> - 2013-05-09 04:05 -0700
  Re: parsing function name and arguments Hans Aberg <haberg-news@telia.com> - 2013-05-10 22:24 +0200

csiph-web