help-bison
[Top][All Lists]
Advanced

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

Re: C++, %glr-parser and non-POD semantic values


From: Tim Van Holder
Subject: Re: C++, %glr-parser and non-POD semantic values
Date: Tue, 29 May 2007 12:02:40 +0200
User-agent: Thunderbird 1.5.0.10 (Windows/20070221)

Frans Englich wrote:
> Hello,
> 
> What direction do you recommend me to take?
> 
> I like the C skeleton because it's simple and it doesn't have dependencies on 
> the STL, which is a no go for me, unfortunately. So, I simply need a 
> parser(GLR, or non GLR, if necessary) that can have non-POD semantic values, 
> in a safe manner.

The easiest is to simply use a pointer to your class as YYSTYPE; the
lexer can then construct an object if there is a relevant semantic
value, or set it to 0 to indicate there isn't (a distinction that can
be useful in some cases).
This way, you can use the C skeleton without problems, and the GLR
skeleton should work too.
Of course, without the use of bison destructors and/or error handling
code you can have leaks using this approach (in my case, my YYSTYPE is
a pointer to an AST node, and the constructor of such nodes adds the
node to a global 'orphaned_nodes' list, from which it is removed when
it's added to a tree, so it's easy to detect & clean up 'leaked' nodes).




reply via email to

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