From: Baptiste L. <gai...@fr...> - 2002-12-23 20:31:00
|
----- Original Message ----- From: "Andre Baresel" <and...@gm...> To: "Baptiste Lepilleur" <gai...@fr...> Sent: Sunday, December 22, 2002 3:35 PM Subject: Re: [Cpptool-develop] Next things .. > Baptiste Lepilleur wrote: > [...] > >I skimmed a bit of the C++ standard concerning declaration (by the way, the > >outtermost level of a source file is only about declaration), and I can say > >that it's not going to be simple. > > > Yep, but I was looking through the ebnf-syntax today. The result of this > is this addition to your FullParser > wiki page. After having some "lazy parsing" declaration parser for the > source level, we could add the > features step by step. For that reason I started to think about how to > find out the different types of declaration > which are in fact not too many and than findout their end symbol ";" or "}". > At highest level that are only 6 different kinds of declaration > - block decl (this is the interessting stuff, classes/struct/typedef, etc.) > - function decl > - different template declarations > - extern declaration (extern "identifier" { ... } ) > - namespace declaration > > the identification and getting the length of extern, namespace is not to > difficult. > the identification of template-declaration is easy but getting the > length is worse because the declaration can recurse > the length of block-declaration is easy since all of the sub types end > with ";" and I think none of them has a ";" inside (need to check this) > identification between block and function declaration is described in > the wiki and follows the idea, that only a function implementation > has a brace ")" just before the compound statement whereas for block > declaration that use "{}" no such thing can happen. I went over the wiki and the basic ideas is there. If you look at the StatementsParser you see it's a lot like the declarations parsing. Though finding the end of declarations is a bit trickier. Take the following case for instance: static int values[] = { 1,2, 3 }; The declaration does not stop at the brace, but at the semicolon. But detecting the brace and semi-colon and backtracking is the way to go for complex declarations, but should not be necessary for basic constructs (using, namespace...) Thinking about it, fault tolerance could probably be introduced when nothing else is matched for a declaration (that's how I would do it for the StatementsParser). Then, it would skip text (while balance curly brace) until a semi-colon is found. Baptiste. |