[antlr-interest] wierdness - or perhaps my ignorance

Bogdan Mitu bogdan_mt at yahoo.com
Fri Aug 2 05:23:57 PDT 2002


Hi Davy,
 
First of all, protected rules don't return any token. Second, if you set the
token type to SKIP, lexer won't output it. Third, if the rule is empty, it
won't consume any char. Try:

BLAH    :  .    // Note the dot, which means "anything"
        {  System.out.println("ignoring: "+ $getText); } 
        ;

Bogdan

--- genericised <trigonometric at softhome.net> wrote:
> class SillyLexer extends Lexer;
> options { filter=BLAH; }
> 
> protected BLAH    : { 
>   $setType(Token.SKIP);
>   System.out.println("ignoring: "+getText());
> } ;
> ---------------------------------------------------
> 
> called from a main like so:
> 
> ---------------------------------------------------
> while(true) {
>    try {
>       sillyLexer.nextToken();   
>    } catch(Exception e) {}
> }
> ---------------------------------------------------
> 
> when executed, no output is generated and
> the lexer gets stuck in an infinate loop, why?
> 
> I comprehend that if newlines were an issue I
> would have to catch them otherwise the lexer
> would be stuck on one line, but here input is
> from stdin so newlines should not be an issue?
> 
> Note: I am not trying to achieve anything specific
> here, I am just curious.
> 
> Davy
> 
> 
>  
> 
> Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/ 
> 
> 
> 


__________________________________________________
Do You Yahoo!?
Yahoo! Health - Feel better, live better
http://health.yahoo.com

 

Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/ 



More information about the antlr-interest mailing list