C++ Template implementation

"Bill Fahle" <bfahle@migratec.com>
21 Apr 1998 00:40:24 -0400

          From comp.compilers

Related articles
C++ Template implementation bfahle@migratec.com (Bill Fahle) (1998-04-21)
Re: C++ Template implementation leichter@smarts.com (Jerry Leichter) (1998-04-27)
Re: C++ Template implementation jrw@pobox.com (John Williams) (1998-04-27)
| List of all articles for this month |

From: "Bill Fahle" <bfahle@migratec.com>
Newsgroups: comp.compilers
Date: 21 Apr 1998 00:40:24 -0400
Organization: Compilers Central
Keywords: C++

I have a working C parser that I am currently turning into a C++ parser. I
use the Roskind grammar for C, and have an old Roskind C++ grammar that
doesn't include templates or namespaces. What I'm wondering is how to
implement templates in the grammar without causing too many conflicts.
Something I've seen in several C++ grammars is the following:

template_class_name::= template_name "<" List(template_arg) ">".

template_arg::= expression | type_name.

What I'm wondering is
a) Why is template_class_name never used anywhere else in the grammar?
Is it just coerced by the parser into a typedefname when the
template_class_name is reduced, something like the lexer hack? If so,
what state does the parser enter at that point, and what happens to
the state stack? (This is different from the lexer hack because it is
a complete nonterminal tree being turned into a typedefname, not just
a token).

b) Why are expressions necessary to the template_arg? I've never seen
this in practice, and I'm not sure of the semantics. These seem to
cause a lot of the conflicts I experience, because of the >
ambiguity. A general expression would indeed be ambiguous:

SpecificList<Specific *, a>b > m_specificList;



Post a followup to this message

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