如何将 c 合并到 c# 中(特别是 lex)

发布于 2024-12-26 11:32:26 字数 109 浏览 4 评论 0原文

有人能给我指出正确的方向吗?我有一个 lex 解析器,我想在 C# 中使用,之前有人做过类似的事情,或者将 c/c++ 与 C# 混合吗?

编辑:更具体地说,我想解析数学表达式和 XML。

Can someone point me in the right direction, I have a parser in lex I want to use in C#, has anyone before done something like this, or mixed c/c++ with C#?

EDIT: More specifically I would like to parse mathematical expressions and XML.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

假装不在乎 2025-01-02 11:32:26

有许多 C# Lex 处理器。例如:

http://www.seclab.tuwien.ac.at/项目/cuplex/lex.htm

There are a number of C# Lex processors out there. For instance:

http://www.seclab.tuwien.ac.at/projects/cuplex/lex.htm

关于从前 2025-01-02 11:32:26

您可以制作一个c代码的dll,并在c#中使用它 PlatformInvoke 机制可用。

即使您可以创建一个包含两个项目的解决方案,其中一个是包含 c/c++ 源代码的库项目,另一个是 c# 项目。

You can make a dll of c code and use it in c# with PlatformInvoke mechanisms available.

Even you can create a solution containing two projects, one of them is a Library Project containing the c/c++ source and another one is c#.

清眉祭 2025-01-02 11:32:26

如果您仅在桌面/服务器应用程序中使用此模块(例如不在 Silverlight 或 Compact Framework 上),您可以使用 clr 支持构建 C/C++ 代码并从 C# 使用它。

If you will be using this module in desktop/server applications only (and not on Silverlight or Compact Framework for example) you could build your C/C++ code with clr support and use it from C#.

吲‖鸣 2025-01-02 11:32:26

我使用了 Flex 的 C++ 版本并取得了巨大成功。

获取 Windows 预构建的二进制文件

您可以从http://www.kohsuke.org/flex++ bison++/

具体来说,我用它来解析一个包含十多个规则的 EBNF 语法(对于 boost::spirit 来说太多了),这些规则将带有类似这样的语句作为输入用户脚本,

  IF a > 10 AND b < -22 THEN OUTPUT X

所以我认为它对于你提到的数学表达式。

解析 XML 则是另一回事。有这么多专门构建的用于解析 XML 的库,为什么您要推出自己的库呢?有 TinyXML ( http://www.grinninglizard.com/tinyxml/ ) 和 CMarkup ( http://www.firstobject.com/dn_markup.htm )这两个我都用过并在多个项目上取得了成功。

I have used a C++ version of flex with great success.

You can get the windows pre-built binaries from

http://www.kohsuke.org/flex++bison++/

Specifically, I have used this to parse an EBNF grammer of more than a dozen rules ( too many for boost::spirit ) which take as input user scripts with statements like

  IF a > 10 AND b < -22 THEN OUTPUT X

So I think it would do fine for the mathematical expressions you mention.

Parsing XML is a different story. There are so many purpose built libraries for parsing XML why would you want to roll your own? There is TinyXML ( http://www.grinninglizard.com/tinyxml/ ) and CMarkup ( http://www.firstobject.com/dn_markup.htm ) both of which I have used successfully on several projects.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文