flex 与 bison的 调试

  1. 官方网站与文档(sourceforge我在使用的时候经常遇到无法访问的情况,自己想办法吧,你懂)

    1. flex:http://flex.sourceforge.net/

      文档:http://flex.sourceforge.net/manual/

    2. bison:http://www.gnu.org/software/bison/

      文档:https://www.gnu.org/software/bison/manual/html_node/index.html

    3. 我目前正在使用的版本分别为:flex 2.5.37、bison 3.0.2,均为 yum 安装

  2. 调试参数

    通过 --help 可以看到,flex 调试开关 -d,bison 调试开关为 -t,生成代码时加入这两个参数即可。

  3. 手动调整 bison 代码,光有开关是不够的,打开 gram.c,可以看到很多宏定义里边都有:“if (yydebug)”,搜索 "int yydebug;" 定义改为:“int yydebug = 1;”;还有一个办法是在其他文件中启动语法引擎前设置 yydebug 非零。

    参见章节:https://www.gnu.org/software/bison/manual/html_node/Tracing.html

  4. scan.c的错误修复,在我使用的版本中无法编译文件,错误:

    1. In file included from gram.y:14877:0:
      scan.c: In function ‘core_yylex’:
      scan.c:9263:47: error: macro "fprintf" requires 3 arguments, but only 2 given
           fprintf( stderr, "--scanner backing up\n" );
                                                     ^
      scan.c:9263:5: warning: statement with no effect [-Wunused-value]
           fprintf( stderr, "--scanner backing up\n" );
           ^
      scan.c:9266:52: error: macro "fprintf" passed 4 arguments, but takes just 3
                    (long)yy_rule_linenum[yy_act], yytext );
                                                          ^
      scan.c:9265:5: warning: statement with no effect [-Wunused-value]
           fprintf( stderr, "--accepting rule at line %ld (\"%s\")\n",
           ^
        ...
    2. 打开 scan.c发现宏定义:

      1. #undef fprintf
        #define fprintf(file, fmt, msg)  fprintf_to_ereport(fmt, msg)
        
        static void
        fprintf_to_ereport(const char *fmt, const char *msg)
        {
        	ereport(ERROR, (errmsg_internal("%s", msg)));
        }
    3. 与其下 fprintf 的用法冲突,注释掉这几行即可



转载于:https://my.oschina.net/quanzl/blog/500536

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值