2010-02-21 77 views
0

%code top命令不包含parser.tab.h文件中的內容(應該這樣做吧?)。野牛版本是2.4.1。這個(簡化)代碼有什麼問題?Bison%code top error

%{ 
    #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:錯誤: '結構DICT' 的重新定義

parser.tab .H:47:錯誤的:typedef 'DICT' 的重新定義

parser.tab.c:145:錯誤:的 'DICT' 先前的聲明在這裏

回答

1

使用%code top不會將代碼插入到標題中,而只能插入到源文件中。它是well documented here

我猜%code provides(或%code requires)會更合適,因爲它在源文件和頭文件中都插入了定義。

相關問題