[antlr-interest] Do I have to use lex state in this case?

Bryan Ewbank ewbank at gmail.com
Fri Oct 7 16:57:50 PDT 2005


If you can figure out the context to know if it is "divide" or
"regex", that's probably your only choice because of ugly math
expressions like "a+b/c*32/d" which would probably match any attempt
at a lex regular expression point of view.

Another option is to tokenize using "divide", and have your parser
recognize when DIV....DIV should be a regex instead of a DIV operator.

For extra credit :-), do you want to match C++ style comments, too? 
from "//" to the end of the line?

On 10/7/05, Xue Yong Zhi <zhixueyong at hotmail.com> wrote:
> In Perl and ruby, regular expression starts and ends with '/', for example:
> /perl|ruby/
>
> As we all know, '/' is the divide operator.
>
> In my lexer I need to know wether '/' is the start of regular expression or
> simple a divide operator. Seems I have to reply on the current "context" (by
> introducing lex state). Are better ideas?
>
> Thank you.
>
> Yong
> http://seclib.blogspot.com
>
>
>
>


More information about the antlr-interest mailing list