On 05/10/2011 12:14, Andreas Liebig wrote:
> Hello,
> I am not very experienced with ANTLR, and I would like to ask for some ideas 
> how to solve this task:
>
> I have to distinguish input streams like
> "3 + 4" (parsed as three tokens NUMBER PLUS NUMBER) from
> "3 +4" (parsed as NUMBER NUMBER, because the + is part of the number +4).
>
> I would like to ignore whitespace in general using the "$channel=HIDDEN;" 
> syntax. But only in this situation whitespace does matter.
> Can you guide me to a good explanation of a possible solution?

Don't really know what docs are where, but off the top of my head... you 
need to have your NUMBER lexer rule start with an optional +, or 
presumably actually + or -, so a human-readable version of the grammar 
would have something like

NUMBER : ('+'|'-')? DIGIT+;
PLUS : '+';
MINUS : '-';

Of course, ANTLR won't like that, because it's ambiguous. There are a 
few ways to resolve the ambiguity, you'll see one if you look on the 
wiki about how to differentiate between ints and floats in the lexer. I 
can't remember the syntax off the top of my head.

Sam


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 il-antlr-inter...@googlegroups.com.
To unsubscribe from this group, send email to 
il-antlr-interest+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/il-antlr-interest?hl=en.

Reply via email to