Re: Parsing C++

Graham Hughes <>
18 Nov 1996 00:35:13 -0500

          From comp.compilers

Related articles
Parsing C++ (1996-11-15)
Re: Parsing C++ (Graham Hughes) (1996-11-18)
Re: Parsing C++ (1996-11-18)
Re: Parsing C++ (Jan Gray) (1996-11-19)
Re: Parsing C++ (1996-12-03)
Re: Parsing C++ (David L Moore) (1996-12-07)
Re: Parsing C++ (1996-12-09)
Re: Parsing C++ (1996-12-09)
[2 later articles]
| List of all articles for this month |

From: Graham Hughes <>
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----- (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 ( for HTML

Version: 2.6.2


            [ Send an empty e-mail to 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.