Re: why use flex?

Dmitri Katchalov <dmitrik@my-dejanews.com>
16 Feb 1999 23:24:34 -0500

          From comp.compilers

Related articles
[4 earlier articles]
Re: why use flex? colas@aye.inria.fr (1999-02-03)
Re: why use flex? Marko.Makela@HUT.FI (Marko =?ISO-8859-1?Q?M=E4kel=E4?=) (1999-02-03)
Re: why use flex? tnaran@direct.ca (1999-02-05)
Re: why use flex? Theodore.Papadopoulo@sophia.inria.fr (Theodore.Papadopoulo) (1999-02-05)
Re: why use flex? Marko.Makela@HUT.FI (Marko =?ISO-8859-1?Q?M=E4kel=E4?=) (1999-02-10)
Re: why use flex? wvenable_net@iname.com (1999-02-15)
Re: why use flex? dmitrik@my-dejanews.com (Dmitri Katchalov) (1999-02-16)
| List of all articles for this month |

From: Dmitri Katchalov <dmitrik@my-dejanews.com>
Newsgroups: comp.compilers
Date: 16 Feb 1999 23:24:34 -0500
Organization: Deja News - The Leader in Internet Discussion
References: 99-01-111 99-02-004 99-02-015 99-02-022 99-02-061
Keywords: yacc, C++

> >C++ forbids putting objects into unions. ...
> Actually you can put C++ objects into Unions as long as they don't
> have copy-constructors or some nonsense like that. My solution was to
> create a class called SemanticValue which could contain objects of
> different types (a class that acts like a Union). A bit messy, but on
> the plus side, I used assignment operator overloading for simple types
> like boolean, string, etc which makes the lexer code look real nice.


A much better solution is to define semantic value as a pointer to
some base C++ class. This gives you type-safety, polymorphism etc. I
did that once. The only problem was to arrange for some sort of
garbage collection which I did simply by keeping a list of all
nodes. It worked (and I hope it still works) and it wasn't messy at
all.




Dmitri


Post a followup to this message

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