[antlr-interest] Help on syntactic predicate

Ric Klaren klaren at cs.utwente.nl
Fri Dec 12 03:26:22 PST 2003


Hi,

On Fri, Dec 12, 2003 at 04:04:18AM -0000, kelvin7600 wrote:
> //Lexer
> 
> WORD	: ((ALPHABET)+) => (ALPHABET)+ (DIGIT)+ {$setType(ALPHANUM);}
> 	| (ALPHABET)+
> 	;

This would probably perform better in this case:

WORD : (ALPHABET)+ {$setType(WORD);} ( (DIGIT)+ {$setType(ALPHANUM);} )? ;

This kind of predicate introduces backtracking e.g. first the expression
before the => is tried and then redone if the test succeeded.

That aside the predicate does not make much sense since it won't
disambiguate the alternatives. I would more expect something like:

WORD : ( (ALPHABET)+ DIGIT ) => (ALPHABET)+ (DIGIT)+ {$setType(ALPHANUM);}
     | (ALPHABET)+ 
     ;

E.g. look for letter sequence followed by a digit if so select first
alternative else ...

> The .g file compiles without a warning but when I run it, it crashes 
> with a debug warning "This application has requested the Runtime to 
> terminate it in a unusual way." This only happened after I added the 
> above code segments to the grammer file. Is there anything wrong in 
> the way I wrote my code? Thanks!

Things like ANTLR version and used compiler could be handy...

Looking at the code generated (with latests snapshot) I don't see anything
funny. A backtrace of the crash would be helpfull. (You did run it in a
debugger to see where it crashes?)

Cheers,

Ric
-- 
-----+++++*****************************************************+++++++++-------
    ---- Ric Klaren ----- j.klaren at utwente.nl ----- +31 53 4893722  ----
-----+++++*****************************************************+++++++++-------
 Why don't we just invite them to dinner and massacre them all when they're
  drunk? You heard the man. There's seven hundred thousand of them. Ah? ..
           So it'd have to be something simple with pasta, then.
                 From: Interesting Times by Terry Pratchet


 

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




More information about the antlr-interest mailing list