I have a very simple grammar where I am attempting to parse some C++ code.  The 
input is very simple and I am having trouble figuring out how to parse (lex?) a 
line.  What I want to do is match a '#define" and then the rest of the line.  I 
don't care what is in the rest of the line (even if empty) but I do want it 
passed to a processing function where I can examine its contents.  The code 
snippet I have used is

definestatement
    : '#define' defineoption
    ;

defineoption
    : RESTOFLINE
    ;
...
COMMENT
    :   '/*' ( options {greedy=false;} : . )* '*/' {$channel=HIDDEN;}
    ;

LINE_COMMENT
    : '//' ~('\n'|'\r')* '\r'? '\n' {$channel=HIDDEN;}
    ;
    
RESTOFLINE
 : ~('\n'|'\r')* '\r'? '\n'
 ;

This was taken out of the example grammar for 'C' and modified.

The problem is that when I attempt to use a RESTOFLINE in the grammar, the 
parser stops with an Unexpected Token at the terminal */ of the comment in the 
header.  It doesn't seem to make any difference if I modify LINE_COMMENT to 
contain the RESTOFLINE item or not.

Questions:
1.  How can I capture the rest of the line into a string that I can examine in 
the function handling that expression?
2.  Why doesn't the above construct work?

The grammar generates and compiles ok in Visual Studio 2008.

Thanks
Sterling
                                          

List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe: 
http://www.antlr.org/mailman/options/antlr-interest/your-email-address

-- 
You received this message because you are subscribed to the Google Groups 
"il-antlr-interest" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/il-antlr-interest?hl=en.

Reply via email to