[antlr-interest] C++ Comment like parsing
wbsza
bloudraak at hotmail.com
Fri Jan 9 17:14:56 PST 2004
Hi,
I'm aiming at writing a JSP/ASP like parser. For starters, I wrote a
grammar to parse a standard C++ comment. However, my grammar doesn't
work. If I pass /* x */ to the parser, I get an error. Actually, I
want to get just "x". I'm not sure what to do to get the parser to
read the text between /* and */.
Below is my grammar. Note that the comment part was taken from the
Java grammar.
Thanks
Werner
options
{
language="Cpp";
}
{
#include <iostream>
#include <antlr/Token.hpp>
}
class MyParser extends Parser;
startRule
: n:ML_COMMENT
{std::cout << "Hi there, " /*<< n->getText()*/ << std::endl;}
;
class MyLexer extends Lexer;
options
{
k=2;
}
// multiple-line comments
ML_COMMENT
: "/*"
options {
generateAmbigWarnings=false;
}
:
{ LA(2)!='/' }? '*'
| '\r' '\n' {newline();}
| '\r' {newline();}
| '\n' {newline();}
| ~('*'|'\n'|'\r')
)*
"*/"
;
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