[antlr-interest] Problem using predicates in V3
Dr. Hartmut Kocher
hwk.cortex-brainware at t-online.de
Sun Feb 11 13:15:32 PST 2007
The language is fixed :-( And no, I didn't invent it.
Your second solution is also not possible because then "t123a" would parse
OK, but "t 123 a" too, which is not allowed. (Of course there's a whitespace
rule)...
In ANTLR2 I did the following:
tokens {
"abc";
}
IDENT
options {
testLiterals=true;
}
:
("abc" DIGIT) => "abc"
| ('a'..'z') (LD | '_')*; // LD is letter or digit
This worked quite well. Now I'm trying to accomplish the same with ANTLR 3.
No such luck so far.
Hartmut
-----Ursprüngliche Nachricht-----
Von: antlr-interest-bounces at antlr.org
[mailto:antlr-interest-bounces at antlr.org] Im Auftrag von Terence Parr
Gesendet: Sonntag, 11. Februar 2007 21:39
An: ANTLR Interest
Betreff: Re: [antlr-interest] Problem using predicates in V3
On Feb 11, 2007, at 12:26 PM, Dr. Hartmut Kocher wrote:
> I know that this is ambiguous. That's why I tried to solve it with a
> predicate. I need both definitions. In other places in the grammar
> I have
> identifiers like "t123a". Still 'abc' must always be parsed as
> 'abc' never
> as identifier. That means 'abc2' must be parsed as 'abc' INT even
> though it
> matches the definition of the ID token.
>
> So I need to force the lexer to never parse 'abc' as ID.
Oh, you have a context-sensitivity problem. First thing. Try not to
do that. Either redesign your language or send hate mail to the
designer. ;) Now, it might be a simple problem. Just match ID w/o
digits and then put back together later using the context from the
parser.
identifierInSomeCase : IDENT INT? {put backtogether} ;
Ter
More information about the antlr-interest
mailing list