Re: Parsing C++ (John Lilley)
9 Dec 1996 00:07:03 -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)
Re: Parsing C++ (1996-12-10)
Re: Parsing C++ (1996-12-18)
| List of all articles for this month |

From: (John Lilley)
Newsgroups: comp.lang.c++.moderated,comp.compilers
Date: 9 Dec 1996 00:07:03 -0500
Organization: Empathy Software
References: 96-11-102 96-12-029 96-12-052
Keywords: C++, parse says...
>One interesting thing about C++ is the "injection" rule which says that
>a method defined in a class is compiled as if it immediately followed
> int foo;
> class A {
> void bar()
> {
> foo x;
> }
> enum foo {bar,bletch};
> };

This is not entirely correct. You are not allowed to change the
meaning of an identifier to a type after usage of the identifier has
been encountered. I think you can count on being able to parser
(recognize) the code in one pass, but at least some additional symbol
table management must be done after the entire class is seen. I don't
know what most compilers do, but it seems that the easiest approach is
to collect the list of tokens for a method body, and then reparse it

On a slightly different subject, I know that the MSVC++ compiler, when
processing a template definition, simply squirrels away the token
list. For example:

template <class T> class A { foo bar blat adksljas 234 };

Will compile, but an instantiation of the template will produce

John Lilley

Post a followup to this message

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