|Giving yyparse() args / Yacc state? firstname.lastname@example.org (David J. Topper) (2001-07-17)|
|Re: Giving yyparse() args / Yacc state? email@example.com (2001-07-18)|
|Date:||18 Jul 2001 19:55:06 -0400|
|Organization:||BAE SYSTEMS Avionics Ltd.|
|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, firstname.lastname@example.org
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,
HA7 4LY, England.
Return to the
Search the comp.compilers archives again.