野牛-d创建头文件不能正确包含头文件

时间:2013-06-24 16:34:56

标签: c bison

只是对案例进行抽样

test.grm

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

%%    
program:   exp    
exp:   ID    
ID: id

bison -d test.grm -o test.c aute生成test.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 个答案:

答案 0 :(得分:1)

生成的标头test.h不包含任何代码,只包含解析器API;所以没有问题:在{%%}之间不会有需要代码的代码。

生成的C文件包含{%%}之间的代码以及您的操作代码(当然还有生成的解析器逻辑)。所以也没有问题。

如果您想要一个包含生成的解析器API和您自己的API的头文件,则必须执行#include - 反过来:将生成的test.h包含在您的自己的头文件。

相关问题