bnfc 漂亮打印机 java 错误

bnfc pretty printer java error

我有这个 BNFC 文件,它描述了一个由许多部分组成的配置文件,其中每个部分都有一个介于 [] 之间的名称,后跟一个简单声明列表

comment "#";
rulse Boolean ::= "True" | "False";
Conf. Config ::= [Section];  //a config is a list of sections
terminator Section "";

Sec. Section ::= "[" NomeSec "]" [Decl]; //A section is made of a name and a list of declarations
terminator Decl ";";

NomeSez. NomeSec ::= Ident;

Dec. Decl ::= VarN "=" Type;

VarName. VarN ::= Ident;

Int.    Type::=Integer;
Char.   Type::=Char;
String. Type::=String;
Float.  Type::=Double;
Bool.   Type::=Boolean;

示例:

[Section1]
Var1 = 3;
Var2 = "test";
#ignored comment

[SectionA]
var4 = True;

具有未定义数量的节和声明。

我 运行 来自 shell 的命令 bnfc -m -java <filename> 并且漂亮打印机的一部分一切正常。编译 prettyprinter.java 时会生成大量错误。例如:

ES5/PrettyPrinter.java:10: error: reference to String is ambiguos 
private static final String _L_PAREN = new String("("); both class
ES5.Absyn.String  and class java.lang.String in java.lang match

所有的错误都是这种类型。我想知道,我刚刚构建了语法,我语法失败了还是 BNFC 失败了?谢谢

因为 BNFC 为每个类别和标签创建 java 类,如果使用 java.lang 中的名称,则会产生歧义(例如 StringBoolean...).

它适用于以下重命名(我还添加了一个显式入口点):

entrypoints Config;

comment "#";
rules MyBoolean ::= "True" | "False";
Conf. Config ::= [Section];  -- a config is a list of sections
terminator Section "";

Sec. Section ::= "[" NomeSec "]" [Decl]; -- A section is made of a name and a list of declarations
terminator Decl ";";

NomeSez. NomeSec ::= Ident;

Dec. Decl ::= VarN "=" Type;

VarName. VarN ::= Ident;

TInt.    Type::=Integer;
TChar.   Type::=Char;
TString. Type::=String;
TFloat.  Type::=Double;
TBool.   Type::=MyBoolean;