C# 使用“键”作为规则元素标签

C# 使用“键”作为规则元素标签,c#,antlr4,C#,Antlr4,在我的项目中,我编写了一种用于处理键值对的语言。所以我有一些规则来匹配多个键keysList和一个值valuesList。现在我想在另一条规则中使用它们 operationExpression : keysList CompareOperator valuesList ; 这很好用 我想最好将这些规则元素命名为键和值 当我现在尝试编译我的项目时,我会收到上千个错误,抱怨缺少分号。当我查看生成的代码时,我发现Antlr给这些上下文起了奇怪的名字。我希望它们是键和值,但它们似

在我的项目中,我编写了一种用于处理键值对的语言。所以我有一些规则来匹配多个键keysList和一个值valuesList。现在我想在另一条规则中使用它们

operationExpression
    :    keysList CompareOperator valuesList
    ;
这很好用

我想最好将这些规则元素命名为键和值

当我现在尝试编译我的项目时,我会收到上千个错误,抱怨缺少分号。当我查看生成的代码时,我发现Antlr给这些上下文起了奇怪的名字。我希望它们是键和值,但它们似乎是每个C关键字和值之间都有一些@s

public KeysListContext structexterndoushortfloatwhileoperatorrefprotectedreadonlycontinueelsecheckedlockcatchifcasenewusingstaticvoidinsizeofbytedoublesealedfinallythisuncheckedisparamsenumexplicitasnulltruefixedtrydecimalobjectimplicitinternalprivatevirtualboolconststringforinterfaceunsafelongoutswitchdelegateforeachdefaultulonggotopublicstackallocoverrideeventclasstypeofbreakfalsevolatileabstractuintintthrowcharnamespacesbyteshortreturnbase;
public ValuesListContext @struct@extern@do@ushort@float@while@operator@ref@protected@readonly@continue@else@checked@lock@catch@if@case@new@using@static@void@in@sizeof@byte@double@sealed@finally@this@unchecked@is@params@enum@explicit@as@null@true@fixed@try@decimal@object@implicit@internal@private@virtual@bool@const@string@for@interface@unsafe@long@out@switch@delegate@foreachkey@ulong@goto@public@stackalloc@override@event@class@typeof@break@false@volatile@abstract@uint@int@throw@char@namespace@sbyte@short@return@base;

其他名字似乎都不错。为什么Antlr会这样做,为什么我不允许使用键和值作为规则元素标签?

我假设这是告诉您使用保留关键字作为标签名称的一种方法。因为您已经发现其他名称可以正常工作,所以请使用与您的语言保留字不冲突的名称。

这是一个错误:

似乎有一个映射,其中用户定义的标识符可能与映射中已经存在的某些键冲突,这些键包括键和值


因此,在等待bug修复时,您必须使用不同的名称。

键和值在C中不是保留字。这一点很好。也许它们在这个特定的上下文中是无效的?如果其他名字有用,为什么还要麻烦呢?对我来说,键和值显然与这里的某些东西冲突。
public KeysListContext structexterndoushortfloatwhileoperatorrefprotectedreadonlycontinueelsecheckedlockcatchifcasenewusingstaticvoidinsizeofbytedoublesealedfinallythisuncheckedisparamsenumexplicitasnulltruefixedtrydecimalobjectimplicitinternalprivatevirtualboolconststringforinterfaceunsafelongoutswitchdelegateforeachdefaultulonggotopublicstackallocoverrideeventclasstypeofbreakfalsevolatileabstractuintintthrowcharnamespacesbyteshortreturnbase;
public ValuesListContext @struct@extern@do@ushort@float@while@operator@ref@protected@readonly@continue@else@checked@lock@catch@if@case@new@using@static@void@in@sizeof@byte@double@sealed@finally@this@unchecked@is@params@enum@explicit@as@null@true@fixed@try@decimal@object@implicit@internal@private@virtual@bool@const@string@for@interface@unsafe@long@out@switch@delegate@foreachkey@ulong@goto@public@stackalloc@override@event@class@typeof@break@false@volatile@abstract@uint@int@throw@char@namespace@sbyte@short@return@base;