[antlr-interest] Newbie prob - nondeterminism :-(

Robert Colquhoun rjc at trump.net.au
Tue Mar 25 03:46:10 PST 2003


Hello Anthony,

At 02:19 PM 24/03/2003 +0000, Anthony W. Youngman wrote:
>As for tokens being propagated back, do you mean I should rewrite eg the 
>IF as
>
>ifst : ("IF"^ logicexpr "THEN" statement ) ;
>
>and it'll create them for me?

Yes if the lexer and parser are in the same file and in the lexer string 
literal rule you use the define "testLiterals=true".  Look in the 
*TokenTypes.[java|txt] files and you can see the "IF" literal specified in 
the parser automatically gets converted to a token type named "LITERAL_IF" 
which can be used in token stream filters and tree walkers to match if 
statements.

>A bit more ... I said I put in a PRINT JUNK - I've tried adding JUNK2 
>after the REPEAT and JUNK3 after the END. It's not doing the JUNK2. So 
>it's probably the LOOP/REPEAT that's causing the hang. But is there any 
>reason why, as it drops out of the IF, it's not printing my trace 
>statement? Might the AST be doing something I don't expect?

If the rule "ifst" is not matched the action attached to the rule will not 
be executed ie no println.  Depending on the situation the parser will then 
look for an alternative to try and match the "IF" maybe causing a hang or 
generate an exception causing the parser to try and resume on the next line 
or perhaps abort completely.

  - Robert


 

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



More information about the antlr-interest mailing list