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

查看:371
本文介绍了得到“表达式太长或太复杂而无法编译".使用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.

任何指针都值得赞赏.

Any pointers are appreciated.

这是一些其他信息.我正在使用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#编译器似乎无法处理这么多concat.我试图避免从我的语言中删除关键字,并使用它们创建一个哈希表.这可能是我目前唯一的解决方案.

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.

推荐答案

我环顾四周,发现这可能是由于编译器引发了深度递归问题".这意味着编译器由于过于复杂而无法解析表达式.有关更多信息,请参见构建错误:表达式太长或太复杂而无法编译"

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天全站免登陆