0

この 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;

セクションと宣言の数が未定義です。

シェルからコマンドを実行した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 に失敗したのか疑問に思っています。ありがとう

4

1 に答える 1

0

BNFC はカテゴリとラベルごとに Java クラスを作成するため、その中の名前を使用するとjava.langあいまいさが生じます (例: String... Boolean)。

次の名前変更で動作します (明示的なエントリ ポイントも追加しました)。

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;
于 2016-06-05T15:29:46.727 に答える