[antlr-interest] FW: Some about C header parser problems
Gowerivy
foxie at live.cn
Thu Jun 25 17:22:15 PDT 2009
From: foxie at live.cn
To: antlr-interest-owner at antlr.org
Subject: Some about C header parser problems
Date: Fri, 26 Jun 2009 08:20:11 +0800
Hi,
I am writing a C header parser, but I find some problems about macro define specifier.
There are three kinds of macro define specifier:
1. No arguments macro define specifier.The general form is: #define identifier string(#define Ext extern)
2. With arguments macro define specifier. The general form is: #define identifer(argument list) string(#define Max(a,b) a>b? a:b)
3. Only identifier. The general form is : #deifine identifier(#define _ADC)
My specifier is that:
define_specifier
: PDefine (Symbol | define_identifier) (t=(expression | key_word))?
key_word
:'auto' | 'break' | 'case' | 'char' |'const' |'continue'|'default' | 'do' | 'double' |'else'
|'enum' | 'extern' | 'float' | 'for' | 'goto' | 'if' | 'int' | 'long' | 'register' | 'return'
| 'short' | 'signed' | 'sizeof' | 'static' | 'struct' | 'switch' |'union' |'ussigned'
| 'void' | 'voliatile' |'while' | 'typedef'
;
PDefine
:'#define'
;
define_identifier
:Symbol '(' define_qualifier_list')'
;
define_qualifier_list
:Symbol (',' Symbol)*
|Number (',' Number)*
;
But this form specifier is wrong. And for axmple test:
1. #ifndef __STM32F10x_MAP_H
#define __STM32F10x_MAP_
#ifndef EXT
#define EXT extern
#endif /* EXT */
#endif/*__STM32F10x_MAP_H*/
NOTE:extern is also a rule
2. #ifndef __STM32F10x_TYPE_H
#define __STM32F10x_TYPE_H
typedef signed long s32;
#endif/*__STM32F10x_MAP_H*/
NOTE: tyedef is alse a rule
3. #ifdef DEBUG
#define assert_param(expr) ((expr) ? (void)0 : assert_failed((u8 *)__FILE__, __LINE__))
void assert_failed(u8* file, u32 line);
#else
#define assert_param(expr) ((void)0)
#endif /* DEBUG */
These three exmple all can't pass test.
I looking forword for your reply. Thanks a lot.
更多热辣资讯尽在新版MSN首页! 立刻访问!
没有互动,哪来共识?微软地图MSN互动为你提供全新地图浏览体验! 立即试用!
更多热辣资讯尽在新版MSN首页! 立刻访问!
_________________________________________________________________
打工,挣钱,买房子,快来MClub一起”金屋藏娇”!
http://club.msn.cn/?from=10
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20090626/8ff643fb/attachment.html
More information about the antlr-interest
mailing list