Re: Giving yyparse() args / Yacc state?
18 Jul 2001 19:55:06 -0400

          From comp.compilers

Related articles
Giving yyparse() args / Yacc state? (David J. Topper) (2001-07-17)
Re: Giving yyparse() args / Yacc state? (2001-07-18)
| List of all articles for this month |

Newsgroups: comp.compilers
Date: 18 Jul 2001 19:55:06 -0400
Organization: BAE SYSTEMS Avionics Ltd.
References: 01-07-081
Keywords: parse, yacc
Posted-Date: 18 Jul 2001 19:55:06 EDT

"David J. Topper" wrote:
> ... I want each object to be able to call yyparse() and have access to
> its respective data. So I can have a little parser say things like:
> (val1 > val2) | (va1 = val2)
> and so on. But I don't want to have to mess with global variables if I
> don't have to. One hack would be to reset a global "active_obj" to
> point to the currently active object, but I'm wondering if I can set
> things up like:
> yyparse(obj *)
> so that it can get passed in?

I'm not sure I really understand what you are after. If you mean you
want multiple parsers, then Bison encapsulates its data far better than
yacc and provides more flexibility. I have successfully used it to
parse two languages in the same program.

The other possible interpretation I see is that you want to evaluate a
single equation several times with different sets of input values. In
this case, parsing the equation and evaluating it are two separate
tasks and yyparse() doesn't need to know about the input objects at
all. It is the evaluation/execution engine that you would pass the
various objects to.

There is a fairly extensive example of creating a scripting language in
the back of "The UNIX programming environment" by Kernighan and Pike,
which demonstrates using yyparse() to build up an array of instructions
which can then be efficiently executed many times. The example is for C
and unfortunately illustrates many of the programming practices that
gave C a poor reputation. If you want to compile it as C++ for
instance, you will have your work cut out. I think it still illustrates
the ideas involved quite well though.


Joe Hotchkiss,
Systems and Processing Group, Tel: +44-20-8420-3523
Sensor Systems Division, Fax: +44-20-8420-3960
BAE SYSTEMS Avionics Limited,
The Grove, Warren Lane,
Stanmore, Middlesex.
HA7 4LY, England.

Post a followup to this message

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