Re: C++ grammar for Java?

John Lilley <jlilley@empathy.com>
8 Oct 1997 00:47:10 -0400

          From comp.compilers

Related articles
C++ grammar for Java? cristofo@irst.itc.it (Luca Cristoforetti) (1997-10-03)
Re: C++ grammar for Java? sreeni@csc.albany.edu (1997-10-08)
Re: C++ grammar for Java? rob@aimnet.com (Rob Duncan) (1997-10-08)
Re: C++ grammar for Java? jlilley@empathy.com (John Lilley) (1997-10-08)
| List of all articles for this month |
From: John Lilley <jlilley@empathy.com>
Newsgroups: comp.compilers,comp.compilers.tools.pccts
Date: 8 Oct 1997 00:47:10 -0400
Organization: Nerds for Hire, Inc.
References: 97-10-025
Keywords: C++, parse

Luca Cristoforetti wrote:


> I'm a student and I'm looking for a C++ grammar written in CUP and
> JLex or ANTLR 2.xx. I have to do an AST for a C++ program so I wonder if
> something similar is already done.
>
> Could anyone help me please?


Hmmm, not to put a damper on your noble efforts, but this incredibly
hard. I've put about eight person-months into developing a C++ parser
using PCCTS 1.33, and it still has some noticable gaps in
functionality, especially for templates nad function overload
resolution.


C++ is a truly awful language to parse. This is in no small part
because of the need to perform complete semantic analysis in the
middle of the syntactic parse. More complexity is added due to the
convoluted name-lookup rules when templates, classes, base classes,
and namespaces are all involved.


If you want a place to start, check out my site. The parser does not
produce AST's, but it populates a fairly complete symbol table:


        http://www.empathy.com/pccts


You should look at Jim Roskind's YACC work (can be found in
comp.compilers archives). It is good because it details many of the
LALR(1) ambiguities that arise in C++. But it is a grammar, not a
parser, because it lacks, well, everything except the grammar.


I also suggest getting the GNU G++ source. It's a difficult read but
it is a functional C++ compiler which counts for a lot these days. If
you're interested in a Win32 port, start at:


        http://www.cygnus.com/misc/gnu-win32


For a truly industrial-grade C++ front-end, check out Edison Design
Group. They're priced *way* out of student range, but they are worth
checking out because they do most everything right. If you are
associated with a bona-fide University research project they may cut
you a deal but I don't know the details.


      http://www.edg.com


There is also a YACC-based C++ grammar from Brown University. It
generates ASTs, but last time I checked it was quite primitive:


      http://www.cs.brown.edu/software/catalog.html


Finally, you *must* get the (CD2 draft) standard:


      http://www.setech.com/c++access.html


Good luck!


john lilley
--


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.