recursive pasrer, arithmetic expansion

Matthieu Tourne <>
22 Mar 2006 23:42:44 -0500

          From comp.compilers

Related articles
recursive pasrer, arithmetic expansion (Matthieu Tourne) (2006-03-22)
Re: recursive pasrer, arithmetic expansion (Clint Olsen) (2006-03-27)
| List of all articles for this month |

From: Matthieu Tourne <>
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


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)

and this is the corresponding piece of grammar using bison :

| 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.

Matthieu Tourne

Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.