Related articles |
---|
recursive pasrer, arithmetic expansion matthieu.tourne@gmail.com (Matthieu Tourne) (2006-03-22) |
Re: recursive pasrer, arithmetic expansion clint@0lsen.net (Clint Olsen) (2006-03-27) |
From: | Matthieu Tourne <matthieu.tourne@gmail.com> |
Newsgroups: | comp.compilers |
Date: | 22 Mar 2006 23:42:44 -0500 |
Organization: | Guest of ProXad - France |
Keywords: | parse, question |
Posted-Date: | 22 Mar 2006 23:42:44 EST |
Hi,
I'm currently doing a parser for arithmetic expansions in a shell.
but I'm experiencing some troubles making my parser recursive.
My problem is :
the variable foo can contain the string "2 + 2"
the evaluation of $((foo + 3)) should be "7"
I need to do parse(parse(foo) + 7), but I can't achieve it.
this is a piece of my scanner (flex) :
{var} { /* get the value of the var in the hash table */
const char *varval = var_value (g_vars, yytext);
/* save the current contex */
yypush_buffer_state (yy_scan_string (varval));
yylval->varname = strdup(varval);
return VAR;
}
<<<EOF>> {
/* restore previous context */
yypop_buffer_state ();
if (!YY_CURRENT_BUFFER)
yyterminate();
}
and this is the corresponding piece of grammar using bison :
exp:
...
| VAR { $$ = yyparse($1, nerrs) }
...
I don't know what's wrong, but it seems to parse only whats contained in the
variable and nothing more. If you've experienced a recursive parser, I
expect your comments.
I think this kind of problem is resolved in the same way the #include is
solved in C compilers.
thanks.
--
Matthieu Tourne
Return to the
comp.compilers page.
Search the
comp.compilers archives again.