使用单声道在 F# 中生成解析器的命令行

Command line to generate a parser in F# with mono

我正在尝试使用 fsyacc(用于 F# 的 Yacc 解析器生成器)做一些作业。

当我运行

 mono fsyacc.exe --module Stmt Stmt.fsy

在包含文件 Stmt.fsy 和 fsyacc.exe 的当前文件夹中,我收到此错误消息:

Unhandled Exception:
System.IO.FileNotFoundException: Could not load file or assembly 'FSharp.Core, Version=4.4.3.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies

但我的当前文件夹中确实有 FSharp.Core.4.3.4/。

仅供参考,如果重要的话,我正在 Mac OS X 上进行测试。我通过 nuget 安装了 FsLexYacc:

nuget install FsLexYacc

然后我将 fsyacc.exe 的 link 符号化到当前文件夹。

使用 fsyacc 在 Mac 上解析的正确命令行是什么?我正在研究 MacOS.

文档中的说明不是很清楚。您需要工具的二进制文件,您可以按如下方式构建它们:

git clone https://github.com/fsprojects/FsLexYacc.git

然后从命令行构建它

/build.sh

这些工具分别在FsLexx 和FsYacc 中。对 运行 他们你做了:

dotnet fslex.dll inputfile -o outputfile
dotnet fsyacc.dll inputfile -o outputfile

但更简单的是,您可以 运行 示例之一,例如Lex 和 Yacc 迷你项目。当您构建它时(例如在 Visual Studio 中),您可以看到它在幕后 运行 提供工具并生成解析器。查看项目文件以了解这是如何完成的。

现在您可以通过复制此示例来创建自己的项目。

旁注:您不需要 Mono。 .NET 核心中的 FsLexYacc 运行s。