[antlr-interest] How to have strings enclosed in " and/or "

Terence Parr parrt at cs.usfca.edu
Thu Dec 9 09:32:30 PST 2004



On Dec 8, 2004, at 12:47 PM, matthew ford wrote:
> Hi all,
> I am having trouble in the lexer handling strings that start and end 
> with "
> or "
> (might start with " and end with ")
> Some html editors kindly replace " with " when you load the file.
>
> I would like to be able to handle something like
>  "str is ""here""""
> to return
>  str is "here"
>  due to the (STRING_PART)*  below and dropping the final quote of each
> STRING_PART
> "" inside a string just escapes a single "
>
> Any ideas on how to make this work?

Hi Matthew,

I'm thinking that this is a language ambiguity.  I can easily give you 
two input sentences that could be interpreted either way.  
Consequently, you're going to have trouble with with generalized LR 
(only diff is that GLR would give you back both interpretations).  You 
might have some luck with a semantic predicate that tracked what you 
start with or something, but I guess what you start with is 
meaningless.  Yep, seems like a language ambiguity leading to a problem 
for any grammar.

To get around it, you might try a special char input stream that did 
the replacement, but even then it won't help you I think; don't know 
when to flip and when not to. :(

Ter
--
CS Professor & Grad Director, University of San Francisco
Creator, ANTLR Parser Generator, http://www.antlr.org
Cofounder, http://www.jguru.com
Cofounder, http://www.knowspam.net enjoy email again!





 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/antlr-interest/

<*> To unsubscribe from this group, send an email to:
    antlr-interest-unsubscribe at yahoogroups.com

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





More information about the antlr-interest mailing list