[antlr-interest] To match or not to match
Raphael Reitzig
r_reitzi at cs.uni-kl.de
Fri Jun 20 08:19:33 PDT 2008
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