在 ANTLR CPP 语法中解析 const 减速输入时出错

Error parsing input for const deceleration in ANTLR CPP Grammar

我正在使用下面的 ANTLR 语法来解析我的代码。

https://github.com/antlr/grammars-v4/tree/master/cpp

但是我在代码的以下部分遇到了解析错误

const GstTensorsInfo info_in = {
        .num_tensors = 1U,
        .info = {{ .name = NULL, .type = _NNS_UINT8, .dimension = { 1, 10, 1, 1}}},
      };

我正在为 CPP 解析器使用以下输入:

TEST(tensor_filter_custom_easy, in_code_func_01)
    {
      int ret;
      const guint num_buffers = 10;
      TestOption option = { num_buffers, TEST_CUSTOM_EASY_ICF_01 };
      guint timeout_id;
    
      const GstTensorsInfo info_in = {
        .num_tensors = 1U,
        .info = {{ .name = NULL, .type = _NNS_UINT8, .dimension = { 1, 10, 1, 1}}},
      };
      
      ret = NNS_custom_easy_register ("safe_memcpy_10x10", cef_func_safe_memcpy,
          NULL, &info_in, &info_out);
      ASSERT_EQ(ret, 0);
    }

parser/lexer 中需要进行哪些修改才能正确解析输入?非常感谢对此的任何帮助。提前致谢。

designated initializer syntax (.num_tensors = 1U) 仅在 C++20 中添加到 C++。您尝试使用的语法名为“CPP14”,我想这意味着它是 C++14 语法。在那种情况下,它不接受语法也就不足为奇了。

您可能会在 C 语法中找到有用的东西,因为自 C99 以来指定的初始值设定项已成为 C 的一部分。