得到“一个表达式太长或太复杂而无法编译"使用 c# 目标时 [英] Getting "An expression is too long or complex to compile" when using c# target

查看:22
本文介绍了得到“一个表达式太长或太复杂而无法编译"使用 c# 目标时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

今天早些时候我终于搞定了完整的语法,但遇到了字符串太长"的 Java 问题.

I've finally got my full grammar up earlier today and ran into the "String is too long" Java issue.

我知道这个问题已经解决,但我害怕遇到其他限制,所以我决定改用 C# 目标.我是一名经验丰富的 C++ 程序员,学习了 Java 以便能够使用 Antlr4,切换到 C# 没什么大不了的,只是要学习一种新的语法.

I understand that this problem has been resolved but I was afraid of running into other limitations so I decided to switch to using the C# target. I'm an experienced C++ programmer and learned Java to be able to use Antlr4, switching to C# is no big deal, just a new syntax to learn.

我现在收到消息:1>CSC:致命错误 CS1647:表达式太长或太复杂,无法编译

I am now getting the message: 1>CSC : fatal error CS1647: An expression is too long or complex to compile

没有提供其他信息.有没有人用 Antlr4 生成的代码见过这个?我在网上搜索了这条消息,但没有找到任何有用的信息(许多参考了应该修复的旧错误).

There's no other information provided. Has anyone seen this one before with code generated by Antlr4? I searched the web for the message but found nothing that could help (many references to older bugs that are supposed to be fixed).

我的项目目前由一个 .cs 文件和 2 个 .g4 文件(词法分析器和解析器语法)组成.

My project is currently composed of a single .cs file along with 2 .g4 file (lexer and parser grammars).

语法非常复杂(实现 IEEE 标准中定义的语言).

The grammar is pretty complex (implement a language define in an IEEE standard).

我最初使用 Java 目标实现了语法的一个子集,没有任何问题.

I originally implemented a subset of the grammar using the Java target without any issues.

感谢任何指针.

这里有一些附加信息.我正在使用 Visual Studio 2012.这似乎与我最初看到的 Java 问题的不同版本相同.

Here's some additional information. I am using Visual Studio 2012. It seems to be the same a different version of the Java issue I originally saw.

我能够创建一个仅包含该行的示例 C# 文件:

I was able to create a sample C# file containing just the line :

public static readonly string _serializedATN =
    "\x5\x3\x176\x234A\x4\x2\t\x2\x4\x3\t\x3\x4\x4\t\x4\x4\x5\t\x5\x4\x6\t"+
    "\x6\x4\a\t\a\x4\b\t\b\x4\t\t\t\x4\n\t\n\x4\v\t\v\x4\f\t\f\x4\r\t\r\x4"+
    "\xE\t\xE\x4\xF\t\xF\x4\x10\t\x10\x4\x11\t\x11\x4\x12\t\x12\x4\x13\t\x13"+
    "\x4\x14\t\x14\x4\x15\t\x15\x4\x16\t\x16\x4\x17\t\x17\x4\x18\t\x18\x4\x19"+
    "\t\x19\x4\x1A\t\x1A\x4\x1B\t\x1B\x4\x1C\t\x1C\x4\x1D\t\x1D\x4\x1E\t\x1E"+
    "\x4\x1F\t\x1F\x4 \t \x4!\t!\x4\"\t\"\x4#\t#\x4$\t$\x4%\t%\x4&\t&\x4\'"+
    "\t\'\x4(\t(\x4)\t)\x4*\t*\x4+\t+\x4,\t,\x4-\t-\x4.\t.\x4/\t/\x4\x30\t"+
    "\x30\x4\x31\t\x31\x4\x32\t\x32\x4\x33\t\x33\x4\x34\t\x34\x4\x35\t\x35"+
                 ...
                 ...
                 "\x2316\x231E\x2324\x2328\x232D";

并且该问题是可重现的.该行超过 4400 行.C# 编译器似乎无法处理这么多的连接.我试图避免从我的语言中删除关键字并用它们创建一个哈希表.这可能是我目前唯一的解决方案.

and the issue was reproducible. The line is over 4400 lines long. The C# compiler doesn't seem to be able to handle this many concat. I was trying to avoid removing the keyword from my language and creating a hash table with them. This might be my only solution at this time.

推荐答案

我环顾四周,发现这可能是由于编译器抛出的深度递归问题"所致.这意味着编译器在解析表达式时会出现问题,因为它太复杂了.有关详细信息,请参阅构建错误:表达式太长或太复杂,无法编译"http://ayende.com/blog/3528/setting-out-to-break-the-compiler.

I have looked around a found that this could be due to a "deep recursion problem" thrown at the compiler. What this means is that the compiler has problems parsing an expression due to it being too complex. For more information, see Build error: "An expression is too long or complex to compile" and http://ayende.com/blog/3528/setting-out-to-break-the-compiler.

这篇关于得到“一个表达式太长或太复杂而无法编译"使用 c# 目标时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆