|
From: Andre B. <and...@gm...> - 2003-04-17 19:21:11
|
hello together,
I'm currently working on the "declaration" parsing.
That's stuff like:
typedef class x { ... } x_type;
const int * (*f)(...);
I've analyzed the C++ Spec. and identified the following elements.
However I'm not yet sure if the parsing has to go that deep at the moment.
Maybe at implementation phase I decide to reduce the level for the first.
Here comes a proposal for a possible AST structure:
===============================================================
* Declaration-Level-Elements
// each declaration consists of a list of specifier and a list of
declarators (with optional init part)
[simple-declaration]
declaration-specifier-property => [declaration-specifier-list] //
specifiers for all declarators...
n [init-declarator] // each declaration can declare 'n' identifier
[declaration-specifier-list] // type declaration is organized as list
n [declaration-specifier]
[init-declarator] // each declarator consist of a
declarator identifier, initialize-part and the declarator-description
(pointer, const, ref etc.)
?identifier-property => [#declarator-identifier]
?initializer => [expression]
declarator-property => [unparsed-declarator] , [declarator]
[unparsed-declarator]
#mutate: declarator
[declarator] // declarators are organized
hierarchical, the property 'sub-declarator-property' links to the sub
element.
?sub-declarator-property => [declarator]
?[function-declarator] // int ... (...)
?[array-declarator] // int ... [...]
?[#braces] // int (...)
?[ptr-declarator] // int (* ...)
?[#ref-declarator] // int (& ...)
?[named-ptr-declarator] // int (::c::d * ...)
[declaration-specifier]
?[#type-specifier] // "simple-type-specifier" (char, wchar_t, bool,
etc.) also "cv-qualifier" ---> see C++ Spec.
?[class-specifier] // full class spec: "class x { ... }"
?[enum-specifier] // full enum spec
?[elaborated-type-specifier] // something like "class xxx" or "struct y"
===============================================================
I will put this on a wiki page for discussion
and add examples which use this ast.
Just feel free to send your opinion !
greetings,
André
|