Any in-depth documents of how to implement template semantics in a parser?

"Jiang Bin" <>
13 Sep 2004 12:33:49 -0400

          From comp.compilers

Related articles
Any in-depth documents of how to implement template semantics in a par (Jiang Bin) (2004-09-13)
Re: Any in-depth documents of how to implement template semantics in a (2004-10-02)
| List of all articles for this month |

From: "Jiang Bin" <>
Newsgroups: comp.compilers
Date: 13 Sep 2004 12:33:49 -0400
Organization: Bentium Ltd. (CN99)
Keywords: C++, parse, question
Posted-Date: 13 Sep 2004 12:33:49 EDT

        I am developing a C++ parser based on John's PCCTS-based C++ Parser, and
have encountered some difficulty in implementing the template semantics.
Currently the parser can do some basically template parsing, but the method
used will fail when more complicated template semantics are concerned, for
template<class _E>
struct char_traits {
      typedef int pos_type;

template<class _E, class _Tr = char_traits<_E> >
class basic_ostream;

template<class _E, class _Tr = char_traits<_E> >
class basic_ios {
      typedef basic_ostream<_E, _Tr> _Myos;
      typedef _Tr::pos_type pos_type;

template<class _E, class _Tr = char_traits<_E> >
class basic_ostream : virtual public basic_ios<_E, _Tr> {
        pos_type tellp() {}

typedef basic_ios<char, char_traits<char> > xxx;

this code is grab from VC6.0 STL headers.
  the main template parsing method used in the parser is save the token list
of a template defintion, and when the template is used, a sub parser will
invoked to reparse of the saved token list. That should be OK for many
cases, but in the example above, when the last basic_ios<char,
char_traits<char> > is instantiated, template "basic_ios" will be reparsed,
consequently template "basic_ostream" will be repared, because basic_ios<_E,
_Tr> is a base of "basic_ostream", then again
"basic_ios" will be reparsed, thus leading to a infinite recursive
Yet I can do something to stop this, such as stop reparsing a template when
it is already instantiated or when it is being instantiated. I find there is
still a problem, "pos_type" is used in the body of "basic_ostream", and it
is defined in the base "basic_ios"....
I only get some basic knowledge about template parsing from books, so I ask
is there any in-depth references about implementing template senmantics in a
C++ compiler or front end?

Thank you!

Jiang Bin

Post a followup to this message

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