[antlr-interest] more newbie help required

karl wettin kalle at snigel.net
Mon Feb 13 16:44:53 PST 2006


I like ANTLR more and more, but have lots of troubles understanding  
documentation and examples regarding AST. I get some parts, but  
suddenly new characters and for me unknown terms is supposed to  
generate something I can use. But I dont understand what or how. Too  
many calculator-examples. Not even sure if I need AST, the  
interpreted text is in no way hierarchical.

I just want a simple Visitor  that follows the expressions as it  
matches. I could synchronize System.out and read the results from  
there. I don't want to do that. What am I supposed to do here?

2.
This is my single parser expression:

	expr: WELL_FORMATTED | BAD_FORMATTED;

Now I get an error where the grammar listed before the other in the  
lexer will be the matching expression. If the input is bad formatted  
data and WELL_FORMATTED is before the BAD_FORMATTED in the lexer, it  
will not match. My guess is that it has something to do with  
lookahead, but even at absurd levels it has no effect. I can get it  
to fail on the second character.

My solution is two parser expressions, and if WELL_FORMATTED throws a  
parser exception, then I call BAD_FORMATTED instead.

I do not understand at all why I get this error.


>
> In essense, why does this return the text:
>  	
> 	(show:SOME_EXPRESSION {System.out.println(show);})+
>
> and why does this return null:
> 	show:(options { greedy=false; } : SOME_EXPRESSION )+
> 	{System.out.println(show);}
>

I still don't understand this.

-- 
karl



More information about the antlr-interest mailing list