From: Stefan S. <se...@sy...> - 2004-06-08 13:30:29
|
Grzegorz Jakacki wrote: > On Mon, 7 Jun 2004, Stefan Seefeld wrote: >>All I'm pondering about now is whether optionally removing the C++ keywords >>would get us closer to a C parser, and if so, what else needs to be done to >>complete the step so opencxx could be used for both languages. > > > This is an interesting question, i.e. can the "common factor" of C and C++ > parser be factored out and how. > > Switching between C/C++ keywords should be easy with existing code. > Moreover, lexer is encapsulated, so this is not an issue too. The fun > begins in parser. indeed. For the lexer we might get away with a dynamically assigned token table (one for C and one for C++), but for the parser we may have a parser base that deals with the common statements that are valid in C as well as C++ while a derived C parser recognizes valid C that is not valid C++ (such as void foo() int x, int y { } and a derived C++ parser that deals with the C++ specific stuff. > I think it depends. There are many possible AST object models. In > particular, existing Ptree hierarchy gives raise to one of them. Having > read-only type-safe API along this model is quite easy, it is just a > matter of determining the Car/Cdr paths. If this API is useful and > convenient is another question. right. regards, Stefan |