[antlr-interest] Please help : Grammar rule for preprocessor

Premkumar Rathanavelu rprememail at yahoo.com
Wed Mar 16 02:47:13 PST 2005


Hi to all ANTLR -ers.,
   I am writing a Grammar for Preprocessors and strucking with its complex code structure .. I want to parse the C/C++  preprocessor code and then have to write in the database for further applications...
  Already i spent morethan a month exploring all possible ways to parse/Lex the code but still struggling .. 
 The problem is 
Eg : #define MAX_SETUP_STRINGS  (sizeof(setup_strings) / sizeof(char *))  /*comment*/
In the above eg. my rule should parse/lex after #define " MAX_SETUP_STRINGS "  - this should be done seperately and written to the DB and then whatever comes next to this, that is here  "(sizeof(setup_strings) / sizeof(char *)) " - this should be written to the DB seperately and after that comments should be skipped.. removing comments is very important..
 
The rule what i tried and became tired -- this is for the third part that is the replacement value ..in lexer 

ReplacementList returns [String Replacement=""]



:

(

Rep :PPtokens

{Replacement = Rep.getText();}

)

;

PPtokens returns [String pt = ""] 

:

 id:ID  

| num:Number 

| cl:CharLiteral 

| sl:StringLiteral 

| opt:OPERATORS

 | Comment

| CPPComment 



; 

 
 
 
Please help me by providing some tipps to the above #define rule .. and i'll be grateful to you..
 
Thanking you., 
PREM

		
---------------------------------
Do you Yahoo!?
 Yahoo! Small Business - Try our new resources site! 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20050316/64c0c396/attachment.html


More information about the antlr-interest mailing list