- 论坛徽章:
- 0
|
treelang语法分析的大致处理流程如下
main (argc, argv)-> toplev_main (argc, argv) -> do_compile ()
-> compile_file () -> lang_hooks.parse_file (set_yydebug)
lang_hooks注册钩子
const struct lang_hooks lang_hooks = LANG_HOOKS_INITIALIZER;
parse_file实际调用treelang_parse_file
LANG_HOOKS_INITIALIZER . LANG_HOOKS_PARSE_FILE
#define LANG_HOOKS_PARSE_FILE treelang_parse_file
调用bison 的parser提取语法tree。GCC真正用的是自己实现的parser,没用bison的。
treelang_parse_file() -> yyparse ()
这里是parse函数定义,
int
yyparse (YYPARSE_PARAM_ARG)
YYPARSE_PARAM_DECL
{
/* If reentrant, generate the variables here. */
#if YYPURE
YY_DECL_VARIABLES
#endif /* !YYPURE */
register int yystate;
register int yyn;
...
...
...
}
#ifdef YYPARSE_PARAM
# if defined (__STDC__) || defined (__cplusplus)
# define YYPARSE_PARAM_ARG void *YYPARSE_PARAM
# define YYPARSE_PARAM_DECL
# else
# define YYPARSE_PARAM_ARG YYPARSE_PARAM
# define YYPARSE_PARAM_DECL void *YYPARSE_PARAM;
# endif
#else /* !YYPARSE_PARAM */
# define YYPARSE_PARAM_ARG
# define YYPARSE_PARAM_DECL
#endif /* !YYPARSE_PARAM */
/* Prevent warning if -Wstrict-prototypes. */
#ifdef __GNUC__
# ifdef YYPARSE_PARAM
int yyparse (void *);
# else
int yyparse (void);
# endif
#endif
#line 315 "/usr/local/share/bison/bison.simple"
#line 175 "plural.y"
#line 183 "plural.y"
有两个疑惑:
1.在int yyparse (YYPARSE_PARAM_ARG)
YYPARSE_PARAM_DECL
中有这种函数声明
int yyparse (arg) void *
C语言中有这种语法吗?
2.像__GNUC__,__LINE__这些宏说是操作系统内置的,不知道怎么理解?
[ 本帖最后由 fineamy 于 2009-1-17 00:36 编辑 ] |
|