help-bison
[Top][All Lists]
Advanced

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

Re: help with parser syntax


From: Laurence Finston
Subject: Re: help with parser syntax
Date: Mon, 6 Aug 2007 14:00:04 +0200 (CEST)

On Mon, 6 Aug 2007, cwcaceres wrote:

> For each command, I had to make a new commandlist. How do I do it so that I
> make Commandlist comlist; only once, at the start of the program?

There are various ways:

1.  Declare it globally and put an `extern' declaration into a header file 
that you include in your parser input file.  I don't recommend this, 
especially if you're planning to use threads somewhere down the line.

2.  Declare it somewhere, perhaps in `main', and pass a pointer to it as a 
parameter to `yyparse' (cast to `void*').

3.  Declare it as a data member of some class or struct and pass a 
pointer to an instance of that type as the parameter to `yyparse'.  
Instead, you might declare a pointer to it as the data member and 
allocated memory for it dynamically.  Or you could use an array of 
`Commandlist' or an array of pointers to `Commandlist'.  If you're using 
C++ in your actions, you could use a `vector', a `queue', or whatever.
I would most likely use one of these variants of the basic idea.

These are just the possibilities that occur to me off the top of my head.  
There may well be others.

The important point is that `yyparse' is just a function and the file 
of C code that contains it is just an ordinary "compilation unit".  The 
same rules of scoping and linkage apply to them as to other functions and 
compilation units.

Laurence Finston




reply via email to

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