[antlr-interest] Re: Nondeterministically blind
Terence Parr
parrt at jguru.com
Sat Dec 8 19:03:51 PST 2001
On Saturday, December 8, 2001, at 06:54 PM, Edward Povazan wrote:
> Ok, I seem to be answering my own questions while I hack around.
> My grammar did not parse valid strings, so I fixed that. I still don't
> see
> why I need the predicate in the STRING_LIT:
> rule. Both versions parse valid strings (from my little tests).
>
> -Ed
> ---------
>
> protected
> ESCAPE_SEQ:
> '\\'.;
>
> protected
> SHORT_STRING_CHAR_SINGLE:
> ~('\\'|'\n'|'\r'|'\'') ;
>
> protected
> SHORT_STRING_CHAR_DOUBLE:
> ~('\\'|'\n'|'\r'|'"') ;
>
> protected
> LONG_STRING_CHAR_SINGLE:
> ~('\\'|'\'') ;
>
> protected
> LONG_STRING_CHAR_DOUBLE:
> ~('\\'|'"') ;
>
> protected
> SHORT_STRING_ITEM_SINGLE:
> SHORT_STRING_CHAR_SINGLE | ESCAPE_SEQ ;
>
> protected
> SHORT_STRING_ITEM_DOUBLE:
> SHORT_STRING_CHAR_DOUBLE | ESCAPE_SEQ ;
>
> protected
> LONG_STRING_ITEM_SINGLE:
> LONG_STRING_CHAR_SINGLE | ESCAPE_SEQ ;
>
> protected
> LONG_STRING_ITEM_DOUBLE:
> LONG_STRING_CHAR_DOUBLE | ESCAPE_SEQ ;
>
> protected
> SHORT_STRING:
> '\'' (SHORT_STRING_ITEM_SINGLE)* '\''
> | '"' (SHORT_STRING_ITEM_DOUBLE)* '"' ;
>
> protected
> LONG_STRING:
> "'''" (LONG_STRING_ITEM_SINGLE)* "'''"
> | "\"\"\"" (LONG_STRING_ITEM_DOUBLE)* "\"\"\"" ;
>
>
> STRING_LIT:
> (("'''") | ("\"\"\"")) => LONG_STRING
> | SHORT_STRING ;
>
> // STRING_LIT: LONG_STRING | SHORT_STRING; // why is this non
> deterministic?
You shouldn't need the predicate. The string start chars should
uniquely identify which to grab. Another problem you may have is that
your (...)* loops are 0 or more not 1 or more. It may be that an empty
string with single quotes looks like the start of a triple quote for
first 2 char.
Ter
--
Chief Scientist & Co-founder, http://www.jguru.com
Creator, ANTLR Parser Generator: http://www.antlr.org
Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
More information about the antlr-interest
mailing list