Path: utzoo!utgpu!watmath!att!tut.cis.ohio-state.edu!cs.utexas.edu!uunet!yale!smith-josh From: smith-josh@CS.YALE.EDU (Josh Smith) Newsgroups: comp.lang.c++ Subject: Using LEX & YACC with c++ Summary: You can use LEX & YACC with c++ Keywords: LEX, YACC, C++ Message-ID: <68916@yale-celray.yale.UUCP> Date: 7 Aug 89 18:55:57 GMT Sender: root@yale.UUCP Reply-To: smith-josh@CS.YALE.EDU (Josh Smith) Organization: Yale University Computer Science Dept, New Haven CT 06520-2158 Lines: 49 Here is a summary of the responses to my question about whether it is possible to use lex and yacc with C++. The consensus seems to be that it can be done without much difficulty. smb@ulysses.att.com says > Yes, but the stack cannot be of a type that contains any constructors. I'm not sure which stack he means, but it doesn't sound like a problem one runs into often. Leo Breebart (leo@duttnph.tudelft.nl) warns that > [Lex] throws spurious "#include " into your code, which > screws up an inclusion of you're almost certain to want. and recommends flex&bison (bison is from GNU) instead of lex&yacc. I have found that lex.yy.c (the lex output file) contains one "#include "; it worked fine when I changed this to "#include ". There may be other circumstances in which more references to are included, but I imagine that one could put a call to awk or sed in the makefile to automatically change from to in any case. Breebart also points out that it's easy to keep the analyzer in C, which is what he has done. C. K. Tan (tan@cs.wisc.edu) points out that you get a lot of warnings during compilation (and believe me, he's right) because of the differences in the way arguments to functions are declared. I suppose Dan Schonfeld's suggestion (below) would clear them up. Dan Schonfeld (dbs@mtunk.att.com until August 18; schonfeld-dan@cs.yale.edu thereafter) says that > The only modification that I had to make was with the > function definitions. I'm using AT&T's cfront 2.0 which is based off Ansi C, > and the yacc function definitions are non-Ansi C, so I had to put in a couple > of prototypes here and there. Also, I had to change some of the external names > that yacc produces because of conflicts with C++ libraries (I believe the > conflict arose from the Strings library, but I'm not positive). I just use > sed and change every occurence of 'yy' to 'YY' and 'U' to 'YyYyU' and have > no problems. With other versions of C++ you probably will have to make similar > patches. Bill Gibbons (bgibbons@apple.com) warns that > [Y]ou have to avoid the // comment style, since YACC doesn't understand it. I got other messages saying "yes," "proceed with confidence," etc.. Josh Smith smith-josh@cs.yale.edu