【问题标题】:Having trouble using gperf:Empty input keyword is not allowed使用 gperf 时遇到问题:不允许空输入关键字
【发布时间】:2011-03-16 06:43:39
【问题描述】:

command_options.gperf:

%{
#include "command_options.h"
typedef struct CommandOptionCode CommandOptionCode;
%}
struct CommandOption
  {
  const char *Option;
  int OptionCode;
  };
%%
+helpverbose, CommandOptionCode::HELPVERBOSE
+password, CommandOptionCode::PASSWORD
+nocopyright, CommandOptionCode::NOCOPYRIGHT
+nolog, CommandOptionCode::NOLOG
+_64bit, CommandOptionCode::_64BIT

command_options.h:

#ifndef __COMMANDOPTIONS_H
#define __COMMANDOPTIONS_H
struct CommandOptionCode 
  {
  enum 
    {
    HELPVERBOSE = 1,
    PASSWORD = 2,
    NOCOPYRIGHT = 3,
    NOLOG = 4,
    _64BIT = 5
    };
  };
#endif

当我跑步时:

gperf  -L C++ -t --output-file=perfecthash.hpp command_options.gperf

只为得到:

不允许空输入关键字。到 识别一个空的输入关键字,你的 代码应该在之前检查 len == 0 调用 gperf 生成的查找 功能。

版本:GNU gperf 3.0.1 为什么?

【问题讨论】:

    标签: c++ open-source gperf


    【解决方案1】:

    我发现 gperf 2.7 并不关心第一部分和关键字之间是否有 '%%' 分隔符。 3.0.1 严格执行这一点。因此,就我而言,我进行了修改:

    %{
    #include <string.h>
    %}
    
    scan
    

    成为

    %{
    #include <string.h>
    %}
    %%
    
    scan
    

    我相信你的情况不同,因为手册规定结构的第一个字段必须称为“名称”:

    "This first field must be called `name', although it is possible to modify its name with the `-K' option (or, equivalently, the `%define slot-name' declaration) described below."
    

    -查理

    【讨论】:

      【解决方案2】:

      我发现 gperf 不喜欢关键字部分的空行。我猜它将空行视为空字符串,因为它不是注释,并且抱怨它是“空的”并且len = 0。由于我习惯于总是以空行结束文件(有些汇编程序和编译器不愿意没有它),所以这总是一个问题!

      【讨论】:

        【解决方案3】:

        除了 Richard 提到的空行问题,gperf 也不喜欢某些标记前的空格。 (我剪切并粘贴了一个简单的 gperf 示例,该示例在用户输入中查找“粗鲁”字词。示例的名称是 rude-1.gperf。示例有一些缩进触发了同样的错误。)

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2014-01-30
          • 2021-06-04
          • 1970-01-01
          • 2018-08-05
          • 2016-09-22
          • 1970-01-01
          • 1970-01-01
          • 2018-12-09
          相关资源
          最近更新 更多