syntactic predicate question

64 views
Skip to first unread message

Ghislain Benrais

unread,
Feb 13, 2013, 5:13:20 AM2/13/13
to antlr-di...@googlegroups.com
Hello,
I have too small a brain to really understand grammars and ANTLR. But I love ANTLR because it saved my life a few times already. The enclosed grammar parses classical expressions (assignments, conditions and function calls) with one specific expression that I added with 'codeList' rule. This rule parses a shortcut to enumerate 'or' conditions :
x = 1-3,18
which means
x=1 or x=2 or x=3 or x = 18

Everything went fine until I I added the 'functionCall' rule, I got the warning :
Decision can match input such as "COMMA INT" using multiple alternatives

In rule codeList, I have tried to use a syntactic predicate :
codeList :       codeListElement  (((COMMA)=>COMMA|PLUS) codeListElement)*

But I still got the warning.
Then I tried a rule option :
codeList
options
{greedy = true; }
       
:       codeListElement  ((COMMA|PLUS) codeListElement)*
       
;

And it still displays the warning.
It is not an issue yet because it works anyway, but I would like to understand what went wrong with the syntactic predicate.
Thans a lot for your help,
Ghislain
PS : the purpose is to produce AST but I have not defined rewrite rules yet
PPS : The warning disappears if I add the grammar option 'backtrack=true' but then ANTLRworks interpreter doesn't work anymore

Expression.g.txt

Mike Lischke

unread,
Feb 13, 2013, 7:29:23 AM2/13/13
to antlr-di...@googlegroups.com

Hi Ghislain,

Everything went fine until I I added the 'functionCall' rule, I got the warning :
Decision can match input such as "COMMA INT" using multiple alternatives

In rule codeList, I have tried to use a syntactic predicate :
codeList :       codeListElement  (((COMMA)=>COMMA|PLUS) codeListElement)*

But I still got the warning.
Then I tried a rule option :
codeList
options {greedy = true; }
        :       codeListElement  ((COMMA|PLUS) codeListElement)*
        ;


Try marking the inner loop greedy (it is already greedy by default, but telling the parser that you know silences the warning), e.g

codeList:
codeListElement ( options {greedy = true;}: (COMMA | PLUS) codeListElement)*

Ghislain Benrais

unread,
Feb 13, 2013, 9:08:51 AM2/13/13
to antlr-di...@googlegroups.com, mike.l...@googlemail.com
Hello Mike,
Thank you four your answer but it didn't silence the warning.
codeList
   
:    codeListElement  ( (options {greedy = true;}:COMMA|PLUS)! codeListElement)*
   
;

Yours,
Ghislain


Jim Idle

unread,
Feb 14, 2013, 7:11:11 AM2/14/13
to antlr-di...@googlegroups.com
Try k=1 fir that rule?

Jim
--
You received this message because you are subscribed to the Google Groups "antlr-discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to antlr-discussi...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Ghislain Benrais

unread,
Feb 16, 2013, 8:02:52 AM2/16/13
to antlr-di...@googlegroups.com
Hello Jim,
It didn't work.
Thanks,
Ghislain

George S Cowan

unread,
Feb 23, 2013, 3:18:43 PM2/23/13
to
Hi, Ghislain,
I notice that your rule for codeList in your reply to Mike did not place the option exactly where he suggested. I personally think Mike's suggestion is very wierd, but he does sound like he knows what he's talking about.
Mike's: codeListElement  (  options {greedy = true;}:(COMMA|PLUS)  codeListElement)*
yours : codeListElement  ( (options {greedy = true;}: COMMA|PLUS)! codeListElement)*
 - George

Ghislain Benrais

unread,
Feb 24, 2013, 11:39:40 AM2/24/13
to antlr-di...@googlegroups.com
Hello George,
Thanks a lot, no more warning, great.
Yours,
Ghislain


Le samedi 23 février 2013 21:10:17 UTC+1, George S Cowan a écrit :
Hi, Ghislain,
I notice that your rule for codeList in your reply to Mike did not place the option exactly where he suggested. I personally think Mike's suggestion is very wierd, but he does sound like he knows what he's talking about.
Mike's: codeListElement  (  options {greedy = true;}:(COMMA|PLUS)  codeListElement)*
yours : codeListElement  ( (options {greedy = true;}: COMMA|PLUS)! codeListElement)*
 - George

On Wednesday, February 13, 2013 9:08:51 AM UTC-5, Ghislain Benrais wrote:
Reply all
Reply to author
Forward
0 new messages