[antlr-interest] lexical modes

Jeff Dahl jddahl at micron.com
Wed Jun 7 14:50:11 PDT 2006


+1

This would greatly simplify my lexers if such functionality existed.  
Great idea!

Jeff

Terence Parr wrote:
> What if you want the lexer though to return a stream of tokens chosen 
> from a different set in between square brackets such as when 
> recognizing regular expressions.  Inside [...] you can refer to '(' as 
> just a char not a grouping symbol.  Rather than creating and switching 
> to a new lexer every time you see a '[', perhaps good old lexical 
> modes from lex are the right idea.
>
> grammar regex;
>
> expr : atom | range | ebnf | ... ;
>
> range : LBRACK (CHAR | CHAR DASH CHAR)+ RBRACK ;
>
> LBRACK : '[' {pushMode(inside_brackets);} ;
>
> mode inside_brackets;
>
> CHAR : ... ;
> DASH : '-' ;
> RBRACK : ']' {popMode();} ;
>
> Something like that...make sense to add?  ANTLR can just 
> switch-on-mode when it enters nextToken() to jump to the appropriate 
> set of lexical rules.
>
> Ter
>
>


More information about the antlr-interest mailing list