[antlr-interest] To match or not to match

Raphael Reitzig r_reitzi at cs.uni-kl.de
Tue Jun 24 02:26:30 PDT 2008


Hello again!

I think I got a couple of steps farther. However, some behaviour of ANTLR
is hazarding me.

Please consider the (updated) grammer at
http://raphael.frhk.de/files/property.g . Note that for rule property, the
first symbols of all alternatives are pairwise different. The grammar works
nice without any additional stuff, i.e. reading the following inputs

(1) : (5*(x+2))=0
(2) : [x=5 | [y=3 U z=5]]

Now try uncommenting line 3, turning backtracking on. I would expect
nothing to change, for backtracking wasn't necessary at all.
However, neither input is recognized using backtracking. To be more
precise, ANTLR failes in evaluating the (implicit) syntactic predicates.
This is unsettling, because it proved seconds earlier that there is exactly
one alternativ of rule property matching each input!

Is this, now, a bug in ANTLR or am I, still, too unskilled? ?(

Sunny German greetings

Raphael

On Fri, 20 Jun 2008 17:19:33 +0200, Raphael Reitzig <r_reitzi at cs.uni-kl.de>
wrote:
> Apparantly, attachments won't work. Sorry for that.
> 
> You can find the grammar file here:
> http://raphael.frhk.de/files/property.g
> 
> For those afraid of viruses or such:
> 
> *****
> 
> grammar property;
> 
> start
> 	:	property EOF;
> 
> property //options { backtrack=true; memoize=true; }
> 	:	NOT '(' property ')'
> 	|	( ALL | GLOB | SOME | FIN | NEXT)+ '(' property ')'
> 	|	'(' property ( (AND | OR) property )+ ')'
> 	|	('(' atom ')')  => '(' atom ')'
> 	|	( atom ) => atom;
> 
> atom
> 	:	term (EQ | NEQ | LES | GRT | LEQ | GEQ) term;
> 
> term
> 	:	'(' term (PLUS | MINUS | MULT| DIV | MOD) term ')'
> 	|	(MIN | MAX) '(' term ',' term ')'
> 	|	(MINUS)? INT
> 	|	(MINUS)? VAR
> 	|	MINUS '(' term ')';
> 
> INT 	:	('0'..'9')+;
> VAR 	:	('a'..'z') ('a'..'z' | 'A'..'Z' | '0'..'9' | '_')*;
> 
> ALL	:	'A';
> SOME 	:	'E';
> GLOB	:	'G';
> FIN 	:	'F';
> NEXT		:	'X';
> 
> UNTIL 	:	'U';
> IMPL 	:	'->';
> AND 	:	'&';
> OR 	:	'|';
> NOT 	:	'!';
> 
> PLUS 	:	'+';
> MINUS 	:	'-';
> MULT 	:	'*';
> DIV 	:	'/';
> MOD 	:	'%';
> 
> MIN 	:	'Min';
> MAX 	:	'Max';
> 
> EQ 	:	'=';
> NEQ 	:	'!=';
> LES 	:	'<';
> GRT 	:	'>';
> LEQ 	:	 '<=';
> GEQ 	:	 '>=';
> 
> WS 	:	(' ' | '\t' | '\n' | '\r')+ { skip(); };
> 
> *****
> 
> On Fri, 20 Jun 2008 14:52:52 +0200, Raphael Reitzig
> <r_reitzi at cs.uni-kl.de>
> wrote:
>> Hello!
>>
>> I am quite a novice to ANTLR as well as language parsing at all, so
>> perhaps
>> I dug in a bit to quickly (got The Book the day before yesterday).
> Anyway,
>> I try to build a grammar I need for a job at university and get some
>> strange results I do not understand. I hope file appendings work on the
>> list.
>>
>> Using ANTLRWorks' Interpreter, I try to match the following sentence
>> against rule 'atom':
>>
>> Min(4,3)=x
>>
>> It works perfectly. It should match rule 'property' as well (last
>> alternative: 'property : ( atom ) => atom;'), but trying that yields
>> FailedPredicateException. (I (think I) need the predicates to help LL(*)
>> along with multiple '('s in a row.) Exactly why does the predicate
> become
>> false _if_ the checked sequence _is_ an atom?
>>
>> Matching Min(4,3) alone against 'term' I expect to work, for it did,
>> matching the statement given above against 'atom'. However, it fails
>> without exception, aparently not recognizing ',' correctly.
>>
>> I would not be surprised I if made a (simple?) systematic error. Can you
>> help me?
>>
>> Greetings from Germany
>>
>> Raphael Reitzig



More information about the antlr-interest mailing list