ANTLR语法错误:永远不能匹配以下替代方案

时间:2012-03-03 07:02:56

标签: compiler-construction antlr context-free-grammar antlrv3ide

我正在尝试使用ANTLR 3.4构建C--编译器。

对于我写的函数的语法

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       ;

但是使用两个Kleene星操作会给我错误:

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       ;

0 个答案:

没有答案