[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: A Beginner's (probably stupid) Question
From: |
John |
Subject: |
Re: A Beginner's (probably stupid) Question |
Date: |
Wed, 9 Apr 2003 13:02:48 -0400 (EDT) |
> ABCDE=[0-9]*[A-Z]*/[,! ;] {
> yylval = (char *) strndup(
> strchr(yytext, '=') + 1,
> yyleng - 1);
> return ABCDE;
> }
> BCDEF=[0-9]*[A-Z]*/[,! ;] {
> yylval = (char *) strndup(
> strchr(yytext, '=') + 1, yyleng
> - 1);
> return BCDEF;
> }
The second argument to strndup is incorrect. More importantly, you
haven't completely tokenized the input, which is why you are resorting
to scanning the token twice (once with flex, and once with strchr).
That's a symptom of trying to parse with the scanner, instead of with
the parser. Here's another approach:
/* scanner */
%%
#define DUP yylval=strdup(yytext)
[A-Z]+ DUP; return IDENT;
[0-9]+[A-Z]* DUP; return IDENT;
= return '=';
[,! ;] return DELIM;
.|\n /* ignore anything else */
%%
/* parser */
%token IDENT DELIM
%%
exp: assignment
| exp assignment
;
assignment:
IDENT '=' IDENT DELIM
| IDENT '=' DELIM
;