tags:

views:

20

answers:

1

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

  %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

+1  A: 

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.

AndiDog