home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!gatech!prism!emperor!mhopper
- From: mhopper@emperor.gatech.edu (Michael A. Hopper)
- Newsgroups: comp.lang.c++
- Subject: Re: yacc and C++
- Message-ID: <74121@hydra.gatech.EDU>
- Date: 9 Nov 92 04:34:44 GMT
- References: <1992Nov9.013842.28215@cs.brown.edu>
- Sender: news@prism.gatech.EDU
- Organization: Computer Engineering Research Lab, Georgia Tech.
- Lines: 58
-
- In article <1992Nov9.013842.28215@cs.brown.edu> hm@cs.brown.edu (Harry Mamaysky) writes:
- >Howdy C++ faithful,
- >
- >I have a slight problem. I am trying to use a YACC generated parser in
- >a C++ system I have. This leads to the problem of getting YACC to know
- >about my C++ objects and such. Of course, I can't include C++ header
- >files YACC (or can I?). SO I have a wrapper program whose routines are
- >called by YACC. I turn before I call yyparse() I set a global variable
- >to point to the object which is making the call. Then the wrapper
- >routines use this global pointer top call the correspondiong class
- >methods in my C++ code. So far so good.
- >
-
- ...stuff deleted
-
- >So, does any one have a better way of using YACC with C++?
- >Does a better way exist?
- >
- >Does a (free) YACC like tool exist for C++? If so, where?
- >
- >Please respond either by email or to comp.lang.c++. If any one out
- >there has a nicer solution, I am most eager to hear about it.
- >
- >Harry.
- >
- >hm@cs.brown.edu
-
- There IS an easier way. Put your c++ code in your YACC file (since
- YACC does NOT look at this code directly). Yacc this file, creating
- the file y.tab.c, and then (the easy trick) create a file called
- parse.cc (or whatever) that looks like this:
-
- // include your header files here.
- #include "class1.hxx"
- #include "class2.hxx"
-
- extern "C" {
-
- int yylex(void);
- void free(void *);
-
- // include your YACC output here.
- #include "y.tab.c"
-
- };
-
- Then compile this file (parse.cc) with your c++ compiler. This works
- with G++ and I think should work in general.
-
- -Mike
-
-
-
- --
- | mhopper@cerl.gatech.edu | ' ) ) ) o /_ ' ) /
- | Office: CRB 388 | / / / / /\_) __ /__/______ _ __ __
- | Phone: (404) 894-9111 | / / (_/\_/ \_/_/_ / / (_) /_)_/_)_/_/_/ (_
- | Home: (404) 723-1718 | / /
-