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

  1. Newsgroups: comp.lang.c++
  2. Path: sparky!uunet!brunix!cs.brown.edu!hm
  3. From: hm@cs.brown.edu (Harry Mamaysky)
  4. Subject: yacc and C++
  5. Message-ID: <1992Nov9.013842.28215@cs.brown.edu>
  6. Sender: news@cs.brown.edu
  7. Organization: Somewhere East or Somewhere West
  8. Date: Mon, 9 Nov 1992 01:38:42 GMT
  9. Lines: 43
  10.  
  11. Howdy C++ faithful,
  12.  
  13. I have a slight problem. I am trying to use a YACC generated parser in
  14. a C++ system I have. This leads to the problem of getting YACC to know
  15. about my C++ objects and such. Of course, I can't include C++ header
  16. files YACC (or can I?). SO I have a wrapper program whose routines are
  17. called by YACC. I turn before I call yyparse() I set a global variable
  18. to point to the object which is making the call. Then the wrapper
  19. routines use this global pointer top call the correspondiong class
  20. methods in my C++ code. So far so good.
  21.  
  22. BUT, the compiler I am using ( v.3.0.1 AT&T C++ ) translates C++ code
  23. into C code and in so doing tacks on type specifier codes to the end
  24. of my routines. SO, for example, a routine called foo becomes
  25. _foo__FP5 in the symbol table of the object file which results from
  26. the code. Unfortunately, this same function foo, which is called by
  27. the YACC generated parser, is _foo is\n the corresponding symbol
  28. table. So, the linker gets screwed in the head and does not know what
  29. to do. I have to actually look up the routine names in the object file
  30. from the C++ program which acts as a wrapper and tack on the weird
  31. endings to the correspondings routines which are defined in the YACC
  32. file. Not pretty.
  33.  
  34. Also, yyparse() is called by C++ code. So, the C++ translator makes
  35. yyparse() into yyparse__Fv() in its symbol table. This means that I
  36. have to call yyparse by its new name in the actual y.tab.c file.
  37. Again, not pretty.
  38.  
  39. Although, the method I described works (so you can use it too if a
  40. better one does not exist), it is incredibly ugly and hack-like. 
  41.  
  42. So, does any one have a better way of using YACC with C++?
  43.  
  44. Does a better way exist?
  45.  
  46. Does a (free) YACC like tool exist for C++? If so, where?
  47.  
  48. Please respond either by email or to comp.lang.c++. If any one out
  49. there has a nicer solution, I am most eager to hear about it.
  50.  
  51. Harry.
  52.  
  53. hm@cs.brown.edu
  54.