2013-06-24 67 views
0

只是採樣的情況下野牛-d創建頭文件不能包含頭文件正確

test.grm

%{ 
#include <stdio.h> 
%} 
%token id 
%start program 

%%  
program: exp  
exp: ID  
ID: id 

野牛-d test.grm -o test.c的奧特生成測試。^h

#ifndef YY_TEST_H 
# define YY_TEST_H 
#ifndef YYDEBUG 
# define YYDEBUG 0 
#endif 
#if YYDEBUG 
extern int yydebug; 
#endif 

#ifndef YYTOKENTYPE 
# define YYTOKENTYPE 
    enum yytokentype { 
    id = 258 
    }; 
#endif 

#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED 
typedef int YYSTYPE; 
# define YYSTYPE_IS_TRIVIAL 1 
# define yystype YYSTYPE /* obsolescent; will be withdrawn */ 
# define YYSTYPE_IS_DECLARED 1 
#endif 
extern YYSTYPE yylval; 
#ifdef YYPARSE_PARAM 
#if defined __STDC__ || defined __cplusplus 
int yyparse (void *YYPARSE_PARAM); 
#else 
int yyparse(); 
#endif 
#else /* ! YYPARSE_PARAM */ 
#if defined __STDC__ || defined __cplusplus 
int yyparse (void); 
#else 
int yyparse(); 
#endif 
#endif /* ! YYPARSE_PARAM */ 
#endif /* !YY_TEST_H */ 

你可以看到的#include是不是在這個文件。這個會有一個問題,當.grm使用頭文件中被定義在%{%}一些定義。

這裏是我的問題,我如何自動生成test.h包括%{%}中包含的內容。

回答

1

生成的標頭test.h不包含您的代碼,而只包含解析器API;所以這裏沒有問題:不會有代碼需要{%%}之間的代碼。

生成的C文件包含您在{%%}之間的代碼以及您的操作代碼(當然還有生成的分析器邏輯)。所以再次沒有問題。

如果您需要一個包含生成的解析器API和您自己的API的頭文件,則必須執行#include-反其道而行之處:將生成的test.h包含在您自己的頭文件中。