lexer - Token for odd number of spaces -
i'm trying create token odd number of spaces. have
token : { < space: " " > | < oddspace: <space> ((<space>)(<space>))* > } void start() : {} { <oddspace> }
this fine 3, 5, 7...etc spaces, fails when try using once space. ideas why happening?
see question 3.3 of javacc faq. http://www.engr.mun.ca/~theo/javacc-faq/javacc-faq-moz.htm#tth_sec3.3
there 3 golden rules picking regular expression use identify next token:
- the regular expression must describe prefix of remaining input stream.
- if more 1 regular expression describes prefix, regular expression describes longest prefix of input stream used. (this called "maximal munch rule".)
- if more 1 regular expression describes longest possible prefix, regular expression comes first in .jj file used.
in case rule 3 applied. can rewrite start
as
void start() : {} { <oddspace> | <space> }
Comments
Post a Comment