初始化声明符列表和GNU GCC属性文法 [英] init-declarator-list and the GNU GCC attribute grammar

查看:206
本文介绍了初始化声明符列表和GNU GCC属性文法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的改造室内C语言野牛/基于Flex的解析器,除其他外引进适当的__ attribute__支持。

因为我找不到任何官方BNF风格的语法描述GNU GCC __ attribute__想法(除了的 http://gcc.gnu.org/onlinedocs/gcc/Attribute-Syntax.html 文件)我抽取调查显示,在各种实现从C ++标准的X11的点点滴滴和评论网页。

我也差点完成它(当它涉及至少包含在GCC的文档上面提到的例子解析),但是一个特别的例子给了我没有一丝的外部资源解决头疼的问题。

的例子是如下:

  __ __属性((noreturn))的无效D0(无效),
         __attribute __((格式(printf的,1,2)))D1(为const char *,...)
          D2(无效);

附的说明说:


  

这是属性说明符列表可能在声明符之前立即出现
  在声明符在一个逗号分隔的列表(比第一个除外)
  使用单列出了多个标识符声明
  符和限定词。这样的属性说明符仅适用于
  符前的声明符出现。


因此​​,导致我这一解决方案:

 的init声明符列表:
 初始化声明符
 初始化声明符列表,属性说明符-SEQ [选择]初始化声明符

我知道它的工作原理,但我想寻求验证/支持,如果这是解决上面提到的情况下,取之有道。

谢谢,

沃伊切赫

编辑:
此链接(有点过时,虽然)给出了一个解决方案,就像我的:的http:// PLG。 uwaterloo.ca/~cforall/gcc.y
奇怪的是,我没有在它的时候我做了__ extension__关键字搜索偶然发现较早,只是现在。


解决方案

早期GCC 2.X.X的版本中使用依靠野牛解析

。所以下载的旧版本应该提供你想要的东西。

只是要注意,新的属性引入了新版本的GCC ...

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.

解决方案

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 ...

这篇关于初始化声明符列表和GNU GCC属性文法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆