- 論壇徽章:
- 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實際調(diào)用treelang_parse_file
LANG_HOOKS_INITIALIZER . LANG_HOOKS_PARSE_FILE
#define LANG_HOOKS_PARSE_FILE treelang_parse_file
調(diào)用bison 的parser提取語法tree。GCC真正用的是自己實現(xiàn)的parser,沒用bison的。
treelang_parse_file() -> yyparse ()
這里是parse函數(shù)定義,
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
中有這種函數(shù)聲明
int yyparse (arg) void *
C語言中有這種語法嗎?
2.像__GNUC__,__LINE__這些宏說是操作系統(tǒng)內(nèi)置的,不知道怎么理解?
[ 本帖最后由 fineamy 于 2009-1-17 00:36 編輯 ] |
|