代码之家  ›  专栏  ›  技术社区  ›  DSblizzard

Bison%代码顶部错误

  •  0
  • DSblizzard  · 技术社区  · 15 年前

    %Codetop命令在parser.tab.h文件中不包含其内容(它应该这样做,对吗?)。Bison版本是2.4.1。这个(简化的)代码有什么问题?

    %{
      #include <stdlib.h>
      #include <string.h>
      #include <stdio.h>
      #include <io.h>
      #define  YYDEBUG 0
      int  errors;
    %}
    
    %code top {
    
      struct DICT
      {
        char *Name;
        int  Offs;
        int  Size;
        struct DICT *Next;
      };
    
      typedef struct DICT DICT;
    
      struct NODE
      {
        int  ID;
        int  Value;
        DICT *Var;
        struct NODE *Left;
        struct NODE *Right;
      };
    
      typedef struct NODE NODE;
    }
    
    %{
      NODE *Tree = 0;
    
      NODE *Node(int ID, int Value, DICT *Var, NODE *Left, NODE *Right);
    
      void yyerror(char *s)
      {
        errors++;
        printf("%s\n", s);
      }
    %}
    
      %no_lines
    
      %union
      {
        int     Value;
        char    *ID;
        NODE    *Node;
      }
    

    编辑:

    parser.tab.h:40:错误:“struct DICT”的重新定义

    parser.tab.h:47:错误:重新定义typedef'DICT'

    1 回复  |  直到 15 年前
        1
  •  1
  •   AndiDog    15 年前

    使用 %code top 不会将代码插入头文件,而只插入源文件。它是 well documented here .

    我猜 %code provides %code requires )将更适合,因为它将在源文件和头文件中插入定义。