help-bison
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Top Dowm Variable Communication


From: lfinsto1
Subject: Re: Top Dowm Variable Communication
Date: Wed, 22 Aug 2007 19:28:27 +0200 (CEST)
User-agent: SquirrelMail/1.4.9a

> Even though Bison is a bottom up parser, if I need to pass a variable's
> content top-down, what are the possible ways (except using global
> variable)?

One way is to use the optional parameter that you can pass to `yyparse'.
It is a `void*' that can point to an object of whatever type you like. 
You'll need to cast it to the correct type in each rule in which you want
to access the structure, unless you're just passing it further to a
function (which takes a `void*' argument, obviously).

You can use this object to store whatever information you like.  My parser
(for GNU 3DLDF) needs to be thread-safe, so global variables wouldn't be a
good idea.  There's a `Scanner_Type' object (this is the type pointed to
by my `void* parameter') for each instance of `yyparse', each of which is
in a separate thread.

It works great for me.  If you want to see lots of examples, you could
look in the files with the suffix `.w' here:
http://cvs.savannah.gnu.org/viewvc/3dldf/3dldf/Group/CWEB/

`grep' for `parameter' and/or `Scanner_Node' (a `typedef' for
`Scanner_Type*').

Laurence Finston





reply via email to

[Prev in Thread] Current Thread [Next in Thread]