[QUERY] C++ parser -- symbol table vs AST

jlilley@empathy.com (John Lilley)
12 Jan 1997 20:24:30 -0500

          From comp.compilers

Related articles
[QUERY] C++ parser -- symbol table vs AST jlilley@empathy.com (1997-01-12)
| List of all articles for this month |

From: jlilley@empathy.com (John Lilley)
Newsgroups: comp.compilers
Date: 12 Jan 1997 20:24:30 -0500
Organization: Compilers Central
Keywords: C++, parse, question


Excuse the C++ specific nature of this -- I believe it still to be
relevant to the larger compiler community, and I don't see a
comp.compilers.c++ anywhere...

I'm working on a public-domain C++ parser, and I'm trying to make some
design decisions regarding the amount of information to be stored in
the symbol table, the AST, or both. In particular, I have found that
class template partial specialization requires that complete type
information be available so that the proper class partial
specialization can be chosen, which in turn affects the syntactic
parse because it determines whether an identifier is a type or not.
For example:

      template <class T> class A { typedef int I; };
      template <class T> class A<T*> { static int I; };
      A<char>::I // type
      A<char*>::I // identifier

My first question is this: I'm going on the assumption that there are
places in the grammar where differentiating types and identifiers is
strictly necessary to resolve ambiguity. This may not be the case --
I would like to know if it can be avoided. Even if it could be
avoided, I think that practically speaking it would be difficult to
defer expansion of the proper partial specialization until analysis of
the AST. Does anyone know of ways of deferring the choice/expansion
of partial template specialization until the semantic analysis of the

This leads to my second question: If it is true that complete type
information must be available during the syntactic parse, then where
is the best place to store it? I've found myself dumping a huge
amount of information into the symbol table (almost everything except
statements), and this bothers me -- I'd rather minimize the symbol
table, place the bulk of the information in the AST, and process it
after the syntactic parse. Failing that, I will probably build the
AST so that it contains references to types and declarations stored in
the symbol table. Any suggestions?

john lilley
[It's an entirely germane question. C++ isn't the first language with an
ineptly designed ambigous syntax, and it surely won't be the last. -John]


Post a followup to this message

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