[antlr-interest] Re: Updated C++ parser
atripp54321
atripp at comcast.net
Mon Jul 5 06:57:58 PDT 2004
Ric,
Thanks for releasing that.
I also wanted to deal with preprocessor stuff in within Monty's
C grammar. There are a couple of "gotchas": mult-line preprocessor
directives and the dreaded "##" operator. Below is what I have.
Andy
protected RestOfPP :
(
'\\'! Newline! // note the "!"s to delete escaped newlines
| Comment
| CharLiteral// 6/11/04: avoid matching '"' as StringLiteral
| StringLiteral //without this, "//" inside string gets processed
| {LA(2) != '*' && LA(2) != '/'}? '/'
| '#' // "stringification"
| ~('\r' | '\n' | '/')
)+
;
// PPSpaceRule will convert "# define" to "#define", etc.
PPspace : "#" (Whitespace)+ RestOfPP
;
PPdefine : "#define" (Whitespace)+ RestOfPP
;
PPif : "#if" (Whitespace)+ RestOfPP
;
PPelse : "#else"
;
PPelif : "#elif" (Whitespace)+ RestOfPP
;
PPendif : "#endif"
;
// Note the "*" instead of "+" here, to handle "#include<whatever.h>"
PPinclude : "#include" (Whitespace)* RestOfPP
;
PPifdef : "#ifdef" (Whitespace)+ RestOfPP
;
PPifndef : "#ifndef" (Whitespace)+ RestOfPP
;
PPundef : "#undef" (Whitespace)+ RestOfPP
;
PPpragma : "#pragma" RestOfPP
;
PPerror : "#error" RestOfPP
;
PPline : "#line" RestOfPP
;
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/antlr-interest/
<*> To unsubscribe from this group, send an email to:
antlr-interest-unsubscribe at yahoogroups.com
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/
More information about the antlr-interest
mailing list