0

I'm trying to built C-- compiler using ANTLR 3.4.

For the grammar for a function I wrote

fundeclaration  : typespecifier ID OPENP params CLOSEP compoundstmt     ;
typespecifier   : INT | VOID                                            ;
params          : VOID | paramlist                                      ;
paramlist       : param (COMMA param)*                                  ;
param           :  /*typespecifier*/INT ID (OPENSQ CLOSESQ)?            ;

compoundstmt    : OPENCUR vardeclaration* statement* CLOSECUR       ;

But using two Kleene star operations gives me error:

warning(200): /CMinusMinus/src/CMinusMinus/CMinusMinus.g:24:40: 
Decision can match input such as "CLOSECUR" using multiple alternatives: 1, 2
As a result, alternative(s) 2 were disabled for that input
 |---> compoundstmt : OPENCUR vardeclaration* statement* CLOSECUR       ;

error(201): /CMinusMinus/src/CMinusMinus/CMinusMinus.g:24:40: The following alternatives can never be matched: 2
 |---> compoundstmt : OPENCUR vardeclaration* statement* CLOSECUR       ;
Cœur
  • 37,241
  • 25
  • 195
  • 267
DarRay
  • 2,550
  • 6
  • 27
  • 39
  • 1
    The problem is not with the rules you posted (the `statement` rule is probably the problem). Could you edit your question and post the entire grammar? – Bart Kiers Mar 03 '12 at 08:40
  • @Bart After editing satement rule, it works. I think the mistake i have done is leaving statement as a empty. – DarRay Mar 03 '12 at 09:43
  • Cool. In that case, feel free to remove this question. – Bart Kiers Mar 03 '12 at 13:02

0 Answers0