Re: Parsing C++

Graham Hughes <graham.hughes@resnet.ucsb.edu>
18 Nov 1996 00:35:13 -0500

          From comp.compilers

Related articles
Parsing C++ manowar@sauropod.engin.umich.edu (1996-11-15)
Re: Parsing C++ graham.hughes@resnet.ucsb.edu (Graham Hughes) (1996-11-18)
Re: Parsing C++ nagle@netcom.com (1996-11-18)
Re: Parsing C++ jsgray@acm.org (Jan Gray) (1996-11-19)
Re: Parsing C++ jlilley@empathy.com (1996-12-03)
Re: Parsing C++ dlmoore@ix.netcom.com (David L Moore) (1996-12-07)
Re: Parsing C++ jlilley@empathy.com (1996-12-09)
Re: Parsing C++ jlilley@empathy.com (1996-12-09)
[2 later articles]
| List of all articles for this month |

From: Graham Hughes <graham.hughes@resnet.ucsb.edu>
Newsgroups: comp.lang.c++.moderated,comp.compilers
Date: 18 Nov 1996 00:35:13 -0500
Organization: University of California, Santa Barbara
References: 96-11-102
Keywords: C++, parse

-----BEGIN PGP SIGNED MESSAGE-----


manowar@sauropod.engin.umich.edu (Krisztian Flautner) writes:


>Could someone give me some examples of language features that cause
>problems ? Has anyone made an analysis of what kind of grammar could
>be used to parse C++ without problems ?


This guy is from C:


Imagine the following code:


        typedef int Foo;
        int Foo;


        int main() {
                Foo * bar;
        }


Now, in the main function: is that a multiplication, or a type
declaration? It's actually a type declaration, but there's no way an
LALR grammar is going to know that. Traditionally, you solve this
problem by passing symbol table information to the lexer.


Or how about


        typedef float T;


        void foo (const T) {
        }


Is the T in foo a `const int' named T, or is it a `const float' with no
argument name (so we throw away the argument when we're called)? It's
actually the latter, but ...


Now, there exists a public ANSI C lexer/grammar pair. I haven't looked
at it, but extending it to support the profusion of similar C++
constructs would be a pain in the neck.


If you really want to parse C++, PCCTS (another free
lexer/compiler-compiler pair) actually has a C++ grammar written for it.
Warning: I've gone back to lex/yacc from PCCTS because the << >> syntax
for actions tends to get lost in the underflow... I wish vim could
highlight syntax, just so I could nail that one pair down.
- --
Graham Hughes (graham.hughes@resnet.ucsb.edu)
http://A-abe.resnet.ucsb.edu/~graham/ for HTML


-----BEGIN PGP SIGNATURE-----
Version: 2.6.2


iQCVAwUBMozVSSqNPSINiVE5AQFV/wP/UTuCjWWQOsBaU8VdMYvNHuuY/UEjirNl
t/dd2+WYkCqiYwQfr3p2oD60LFLAXr50umJLcO6a9sG+KSiD1YDezE13EMB3vVdp
oehiIBiXDzlE1ozZwlb3a+uE9CvnKP5jlsvbAL9I+LAOR2R34SCaXvCsFYQp/PzP
u7Vyoj0vqQw=
=uvIH
-----END PGP SIGNATURE-----


            [ Send an empty e-mail to c++-help@netlab.cs.rpi.edu for info ]
            [ about comp.lang.c++.moderated. First time posters: do this! ]




--


Post a followup to this message

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