0

我正在尝试使用 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       ;
4

0 回答 0