home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #26 / NN_1992_26.iso / spool / comp / lang / cplus / 15951 < prev    next >
Encoding:
Text File  |  1992-11-09  |  2.2 KB  |  70 lines

  1. Path: sparky!uunet!gatech!prism!emperor!mhopper
  2. From: mhopper@emperor.gatech.edu (Michael A. Hopper)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: yacc and C++
  5. Message-ID: <74121@hydra.gatech.EDU>
  6. Date: 9 Nov 92 04:34:44 GMT
  7. References: <1992Nov9.013842.28215@cs.brown.edu>
  8. Sender: news@prism.gatech.EDU
  9. Organization: Computer Engineering Research Lab, Georgia Tech.
  10. Lines: 58
  11.  
  12. In article <1992Nov9.013842.28215@cs.brown.edu> hm@cs.brown.edu (Harry Mamaysky) writes:
  13. >Howdy C++ faithful,
  14. >
  15. >I have a slight problem. I am trying to use a YACC generated parser in
  16. >a C++ system I have. This leads to the problem of getting YACC to know
  17. >about my C++ objects and such. Of course, I can't include C++ header
  18. >files YACC (or can I?). SO I have a wrapper program whose routines are
  19. >called by YACC. I turn before I call yyparse() I set a global variable
  20. >to point to the object which is making the call. Then the wrapper
  21. >routines use this global pointer top call the correspondiong class
  22. >methods in my C++ code. So far so good.
  23. >
  24.  
  25. ...stuff deleted
  26.  
  27. >So, does any one have a better way of using YACC with C++?
  28. >Does a better way exist?
  29. >
  30. >Does a (free) YACC like tool exist for C++? If so, where?
  31. >
  32. >Please respond either by email or to comp.lang.c++. If any one out
  33. >there has a nicer solution, I am most eager to hear about it.
  34. >
  35. >Harry.
  36. >
  37. >hm@cs.brown.edu
  38.  
  39. There IS an easier way.  Put your c++ code in your YACC file (since
  40. YACC does NOT look at this code directly).  Yacc this file, creating
  41. the file y.tab.c, and then (the easy trick) create a file called
  42. parse.cc (or whatever) that looks like this:
  43.  
  44.     // include your header files here.
  45.     #include "class1.hxx"
  46.     #include "class2.hxx"
  47.  
  48.     extern "C" {
  49.  
  50.     int yylex(void);
  51.     void free(void *);
  52.  
  53.     // include your YACC output here.
  54.     #include "y.tab.c"
  55.  
  56.     };
  57.  
  58. Then compile this file (parse.cc) with your c++ compiler.  This works
  59. with G++ and I think should work in general.
  60.  
  61. -Mike
  62.  
  63.  
  64.  
  65. -- 
  66. | mhopper@cerl.gatech.edu |   ' ) ) ) o  /_       ' )  /                
  67. | Office: CRB 388         |    / / / /  /\_) __    /__/______   _   __  __
  68. | Phone: (404) 894-9111   |   / / (_/\_/  \_/_/_  /  / (_) /_)_/_)_/_/_/ (_
  69. | Home:  (404) 723-1718   |                               /   /      
  70.