help-bison
[Top][All Lists]
Advanced

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

RE: C++ and Bison (Christoph B.)


From: Chad Bradley
Subject: RE: C++ and Bison (Christoph B.)
Date: Wed, 22 Mar 2006 19:10:47 -0800

Hi Christoph,

Check out Frank Brokken's site on C++ annotations.
He has a great section on using bisonc++ and flex together to create a
parser that is class-compatible.
I am not remembering the address, google for C++ annotations.


Regards,
Chad


-----Original Message-----
From: address@hidden
[mailto:address@hidden On Behalf Of
address@hidden
Sent: Wednesday, March 22, 2006 11:00 AM
To: address@hidden
Subject: Help-bison Digest, Vol 29, Issue 11

Send Help-bison mailing list submissions to
        address@hidden

To subscribe or unsubscribe via the World Wide Web, visit
        http://lists.gnu.org/mailman/listinfo/help-bison
or, via email, send a message with subject or body 'help' to
        address@hidden

You can reach the person managing the list at
        address@hidden

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Help-bison digest..."


Today's Topics:

   1. C++ and Bison (Christoph B.)


----------------------------------------------------------------------

Message: 1
Date: Wed, 22 Mar 2006 12:45:28 +0100
From: "Christoph B." <address@hidden>
Subject: C++ and Bison
To: address@hidden
Message-ID: <address@hidden>
Content-Type: text/plain; charset=ISO-8859-1

Hi everybody!

Although I'm completely new to building parsers I successfully created a
lexer file and a bison grammar file. Finally my parser worked as
expected but now I'd like to put the parsed content into internal data
structures.
Unfortunately I soon discovered that bison and lex cannot handle C++
class types in the YYSTYPE union defnition and I did not find a way to
get this working.

Does anyone have a clue what to do in this case?

My first idea was to replace bison with bison++, but apart from much
more warnings the error message that said that my classes could't be
used in the union still remains.

g++ -c  lex.yy.c -o lex.yy.o
mof.y:71: error: 'Entry' does not name a type

I also read something about flex++, I am using Debian sid and I only
found packages flex and flex-old, so I am not quite sure if one of these
packages really is flex++ but as I am in doubt about that I will soon
install flex++ from source.

Unfortunately I did not find any good tutorials based on flex++/bison++,
so what I'd basically like to know is what changes to my lex/yacc files
are necessary to get them working with bison++ (and maybe flex++).
Can I use the exactly same files (I fear that won't work...)? And how do

This is what my lexer file looks like:
================================
%{
#define YY_SKIP_YYWRAP
#include <stdio.h>
#include <string.h>
#include "y.tab.h"
#include "entry.h" //class that I would like to use in the union
int yywrap()
{
        return 1;
}
;
%}
%%
token                yylval.string=strdup(yytext);return TOKEN;
[...]
%%
================================


My bison grammar file:
================================
%{
#define YY_SKIP_YYWRAP
#include <iostream>
#include <stdio.h>
#include "entry.h"
[...]
int yylex(void);
int yyparse(void);
void yyerror(const char *str) {fprintf(stderr,"error: %s\n",str);}
int main(void) { yyparse();}
%}
%union
{
        int number;
        char *string;
        Entry foobar;   //does not work for some bison reason.
}
%token <string> TOKEN
[...]
%type <string> nonterminals
%%
//description of grammar
================================

I'm a complete newbie to lex and yacc and started a few days ago with
this [1] tutorial. Unfortunately it is designed for C developers and
there is only a very short section for C++ that does not fit my needs.

Any help is gladly appreciated, thanks very much in advance!
Yours,
Christoph

[1] http://ds9a.nl/lex-yacc/cvs/lex-yacc-howto.html




------------------------------

_______________________________________________
Help-bison mailing list
address@hidden
http://lists.gnu.org/mailman/listinfo/help-bison

End of Help-bison Digest, Vol 29, Issue 11
******************************************




reply via email to

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