init-declarator-list and the GNU GCC attribute grammar

ぐ巨炮叔叔 提交于 2019-12-22 06:45:09

问题


I am revamping an inhouse C language bison/flex-based parser, amongst others introducing proper __ attribute__ support.

Since I cannot find any official BNF-style grammar which describes GNU GCC __ attribute__ idea (except the http://gcc.gnu.org/onlinedocs/gcc/Attribute-Syntax.html document) I am extracting bits and pieces from the C++x11 standard and comments in various implementations found over the web.

I have almost got it done (at least when it comes to parsing examples included in GCC's doc cited above) but one particular example has given me a headache with no hint of solution in external sources.

The example is as follow:

__attribute__((noreturn)) void d0 (void),
         __attribute__((format(printf, 1, 2))) d1 (const char *, ...),
          d2 (void);

The description attached says that:

An attribute specifier list may appear immediately before a declarator (other than the first) in a comma-separated list of declarators in a declaration of more than one identifier using a single list of specifiers and qualifiers. Such attribute specifiers apply only to the identifier before whose declarator they appear.

Thus, leading me to this solution:

init-declarator-list:
 init-declarator
 init-declarator-list , attribute-specifier-seq[opt] init-declarator

I know it works but I would like to seek for a verification/support if this is a proper way to resolve the above-mentioned case.

Thanks,

Wojciech

EDIT: this link (a bit dated, though) gives a solution just as mine: http://plg.uwaterloo.ca/~cforall/gcc.y strangely, I haven't stumbled upon it earlier, only now when I did a search for __ extension__ keyword.


回答1:


Early version of GCC 2.X.X used to rely on bison for parsing. So downloading an old version should provide you what you want.

Just beware that new attribute are introduced with new GCC version ...



来源:https://stackoverflow.com/questions/15250318/init-declarator-list-and-the-gnu-gcc-attribute-grammar

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!