[antlr-interest] Re: Need help: How to remove comments before
parsing?
Premkumar Rathanavelu
rprememail at yahoo.com
Thu Mar 17 17:39:58 PST 2005
Hi ..
Thanks for your relply.
Your Question : Why the comment rules are not working ?
Ans: Because, take
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 in this eg., "(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
:
id:ID
| num:Number
| cl:CharLiteral
| sl:StringLiteral
| opt:OPERATORS
;
Explanation : As the #define macros ( Object-like and Function -like) has very
complex structure of expanding its macros i.e. sometimes with lot of
operators and expressions, I can't able to write a perfect rule for
parsing the replacement value and so I thought of capturing all
everything upto the nextline.But here the problem comes due
to comments.I can use the comment rules to skip ..but it is not
working in this context becos I'm capturing all up to the end of the line..
Result:The comments are also written to my
Database together with the replacement value.
Suggestion: I tried by exploring lot of rules and
now I got an idea to precompile the files(.c or .h or .cpp)
to remove all the comments by using some tools
and then acting grammar upon them.
Please reply me whether this above concept work ?
Pleasure to have comments..
Thanks.,
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/20050317/2c2423ba/attachment.html
More information about the antlr-interest
mailing list