开发者

Bison %code top error

开发者 https://www.devze.com 2022-12-20 16:24 出处:网络
%code top command doesn\'t include its contents in parser.tab.h file (It should do so, right?). Bison version is 2.4.1. What is the problem with this (simplified) code?

%code top command doesn't include its contents in parser.tab.h file (It should do so, right?). Bison version is 2.4.1. What is the problem with this (simplified) code?

%{
  #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);
  }
%}

  开发者_JS百科%no_lines

  %union
  {
    int     Value;
    char    *ID;
    NODE    *Node;
  }

EDIT: with "%code requires" problem was resolved but another arise:

parser.tab.h:40: error: redefinition of 'struct DICT'

parser.tab.h:47: error: redefinition of typedef 'DICT'

parser.tab.c:145: error: previous declaration of 'DICT' was here


Using %code top will not insert the code into the header but only into the source file. It is well documented here.

I guess %code provides (or %code requires) will be more suited because it inserts the definitions in both source and header file.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号