hi!  crap. ok,Added the following to your post on that webpage:

> Ok, looks like we need some kind of formal mechanism after all, or at least a 
> predicate that tests the input without consuming. Problem is I already use ~ 
> to mean "not element but consume" and '!' to mean don't include in the tree. 
> Maybe -LetterOrDigit?

Still, we could easily do it with a simple {...}? so ANTLR can still do it 
without formalism, just as PEGs force you to manually say that as well. :)

Ter

On Apr 17, 2011, at 3:35 AM, Peter Kooiman wrote:

> Ter, 
> 
> First of all, let me explain that the only reason I'm being such a nuisance 
> is that I really want this to work! However, I'm afraid that in the end, 
> ANTLR falls just short of being a scannerless tool. 
> 
> The problem lies with distinguishing between keywords, and identifiers that 
> happen to start with the same letters as a keyword. 
> The sample at http://bit.ly/gT3Q1C cannot distinguish between "returnme;" and 
> "return me;", because kreturn is expressed as: 
> 
> kreturn : 'r' 'e' 't' 'u' 'r' 'n' ws? ; 
> 
> My first thought was, just make the whitespace not optional. But, in C for 
> example, we can have 
> return; 
> return me; 
> 
> whereas "returnme;" would be a syntax error. Now, making ws not optional is 
> no longer possible; what is really needed is a way to express 
> "'r' 'e' 't' 'u' 'r' 'n' followed by anything that can NOT be part of an 
> identifier". Although you could re-write the return statement rule to 
> something awful like 
> 
> retstat: kreturn ws? colon 
>         | kreturn ws id colon 
>         ; 
> 
> the underlying problem remains: there is no way to prevent ANTLR entering 
> rule kreturn upon seeing an identifier like "returnme" that happens to start 
> with the same letters as keyword "return". In Rats!, you would write
> 
> KRETURN = "return" !LetterOrDigit ws? ;
> 
> where the "!" operator denotes a syntactic predicate meaning "LetterOrDigit 
> must not match, and corresponding input will not be consumed"
> 
> Without the ability to express "something followed by anything that is not a 
> letter or digit", I don't see how to get it right in ANTLR. I very much hope 
> I am wrong though!
> 


List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe: 
http://www.antlr.org/mailman/options/antlr-interest/your-email-address

-- 
You received this message because you are subscribed to the Google Groups 
"il-antlr-interest" group.
To post to this group, send email to il-antlr-inter...@googlegroups.com.
To unsubscribe from this group, send email to 
il-antlr-interest+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/il-antlr-interest?hl=en.

Reply via email to