[antlr-interest] C++ grammar - namespaces

David Wigg wiggjd at sbu.ac.uk
Wed Mar 5 05:44:00 PST 2003


Thanks for loading my updated version of a C++ grammar onto 
http://www.antlr.org/grammars.

However, I only found it there by an act of serendipty. I can't 
see how to get there from http://www.antlr.org or anywhere else 
for that matter, or am I missing something?

I am still working on this grammar making significant 
improvements to bring it up to date.

In particular I hope I have now accounted for "namespaces" as 
described on pages 634-638 in the Second Edition of Bjarne 
Stroustrup's book, The C++ Programming Language, as follows,

decl_namespace   // alternative in external-declaration
     :	
         "namespace"
         (
             (ns:ID{_sc = scTYPEDEF;
                    declaratorID((ns->getText()).data());}
             )?
             LCURLY (external_declaration)* RCURLY
         |
             ASSIGNEQUAL qualified_id SEMICOLON {end_of_stmt();}
         )
     ;

using_statement   // alternative in declaration
     :
         "using"
         (
             "namespace" qualified_id  // Using-directive
         |
             qualified_id              // Using-declaration
         )
         SEMICOLON {end_of_stmt();}
     ;

However, I still have a problem about the correct type for a 
namespace. The parser works on my test data by using 
declaratorId to set it as a 'typedef' but I think it would be 
better classed as 'class' since it introduces a new scope. What 
do you think?

What type should I use Terence?

David.



 

Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/ 



More information about the antlr-interest mailing list