[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re[2]: bison %union and C++
From: |
Oleg Smolsky |
Subject: |
Re[2]: bison %union and C++ |
Date: |
Wed, 25 Sep 2002 14:12:06 +1200 |
Hello Hans,
Hans Aberg wrote on Wednesday, September 25, 2002:
OS>> here is a question that is probably asked for a millionth
OS>> time....
HA> So you have figured it out. :-)
I tried :) But there are no samples that I could find....
OS>> Anyway, with bison 1.49b and C++ skeleton, how do I include a C++
OS>> class into the bison's types? In theory, I would like to add
OS>> std::string into the %union section, but this is prohibited by
OS>> ANSI C++.
HA> Just define your own class and YYSTYPE, and don't use unions in
HA> any form.
this is great - thanks! This is exactly what I needed :)
I defined YYSTYPE, typedefed yystype and yyltype, and added a couple
of integer members to the class - everything works great.
I don't need any unions, everything is of one type, and I can do the
following things inside flex:
pObject->m_sData = yytext;
pObject->m_iData = atoi(yytext);
return T_INTEGER;
Thanks a lot - I think this design is much cleaner than the original
union thing. (and guess what - these objects can be stored in c++
containers :)))
Best regards,
Oleg Smolsky
Software Design Authority
Allied Telesyn Research