📄 grammar.y
字号:
{ char *s; if ((s = implied_typedef()) == 0) (void)sprintf(s = buf, "%s {}", $1.text); new_decl_spec(&$$, s, $1.begin, DS_NONE); } | struct_or_union any_id { (void)sprintf(buf, "%s %s", $1.text, $2.text); new_decl_spec(&$$, buf, $1.begin, DS_NONE); } ;struct_or_union : T_STRUCT { imply_typedef($$.text); } | T_UNION { imply_typedef($$.text); } ;init_declarator_list : init_declarator { new_decl_list(&$$, $1); } | init_declarator_list ',' init_declarator { add_decl_list(&$$, &$1, $3); } ;init_declarator : declarator { if ($1->func_def != FUNC_NONE && func_params == NULL && func_style == FUNC_TRADITIONAL && cur_file->convert) { gen_func_declarator($1); fputs(cur_text(), cur_file->tmp_file); } cur_declarator = $$; } | declarator '=' { if ($1->func_def != FUNC_NONE && func_params == NULL && func_style == FUNC_TRADITIONAL && cur_file->convert) { gen_func_declarator($1); fputs(" =", cur_file->tmp_file); } } T_INITIALIZER ;enum_specifier : enumeration any_id braces { char *s; if ((s = implied_typedef()) == 0) (void)sprintf(s = buf, "enum %s", $2.text); new_decl_spec(&$$, s, $1.begin, DS_NONE); } | enumeration braces { char *s; if ((s = implied_typedef()) == 0) (void)sprintf(s = buf, "%s {}", $1.text); new_decl_spec(&$$, s, $1.begin, DS_NONE); } | enumeration any_id { (void)sprintf(buf, "enum %s", $2.text); new_decl_spec(&$$, buf, $1.begin, DS_NONE); } ;enumeration : T_ENUM { imply_typedef("enum"); $$ = $1; } ;any_id : T_IDENTIFIER | T_TYPEDEF_NAME ;declarator : pointer direct_declarator { $$ = $2; (void)sprintf(buf, "%s%s", $1.text, $$->text); free($$->text); $$->text = xstrdup(buf); $$->begin = $1.begin; $$->pointer = TRUE; } | direct_declarator ;direct_declarator : identifier_or_ref { $$ = new_declarator($1.text, $1.text, $1.begin); } | '(' declarator ')' { $$ = $2; (void)sprintf(buf, "(%s)", $$->text); free($$->text); $$->text = xstrdup(buf); $$->begin = $1.begin; } | direct_declarator T_BRACKETS { $$ = $1; (void)sprintf(buf, "%s%s", $$->text, $2.text); free($$->text); $$->text = xstrdup(buf); } | direct_declarator '(' parameter_type_list ')' { $$ = new_declarator("%s()", $1->name, $1->begin); $$->params = $3; $$->func_stack = $1; $$->head = ($1->func_stack == NULL) ? $$ : $1->head; $$->func_def = FUNC_ANSI; } | direct_declarator '(' opt_identifier_list ')' { $$ = new_declarator("%s()", $1->name, $1->begin); $$->params = $3; $$->func_stack = $1; $$->head = ($1->func_stack == NULL) ? $$ : $1->head; $$->func_def = FUNC_TRADITIONAL; } ;pointer : '*' opt_type_qualifiers { (void)sprintf($$.text, "*%s", $2.text); $$.begin = $1.begin; } | '*' opt_type_qualifiers pointer { (void)sprintf($$.text, "*%s%s", $2.text, $3.text); $$.begin = $1.begin; } ;opt_type_qualifiers : /* empty */ { strcpy($$.text, ""); $$.begin = 0L; } | type_qualifier_list ;type_qualifier_list : type_qualifier { (void)sprintf($$.text, "%s ", $1.text); $$.begin = $1.begin; free($1.text); } | type_qualifier_list type_qualifier { (void)sprintf($$.text, "%s%s ", $1.text, $2.text); $$.begin = $1.begin; free($2.text); } ;parameter_type_list : parameter_list | parameter_list ',' T_ELLIPSIS { add_ident_list(&$$, &$1, "..."); } ;parameter_list : parameter_declaration { new_param_list(&$$, $1); } | parameter_list ',' parameter_declaration { add_param_list(&$$, &$1, $3); } ;parameter_declaration : decl_specifiers declarator { check_untagged(&$1); $$ = new_parameter(&$1, $2); } | decl_specifiers abs_declarator { check_untagged(&$1); $$ = new_parameter(&$1, $2); } | decl_specifiers { check_untagged(&$1); $$ = new_parameter(&$1, (Declarator *)0); } ;opt_identifier_list : /* empty */ { new_ident_list(&$$); } | identifier_list ;identifier_list : any_id { new_ident_list(&$$); add_ident_list(&$$, &$$, $1.text); } | identifier_list ',' any_id { add_ident_list(&$$, &$1, $3.text); } ;identifier_or_ref : any_id { $$ = $1; } | '&' any_id {#if OPT_LINTLIBRARY if (lintLibrary()) { /* Lint doesn't grok C++ ref variables */ $$ = $2; } else#endif (void)sprintf($$.text, "&%s", $2.text); $$.begin = $1.begin; } ;abs_declarator : pointer { $$ = new_declarator($1.text, "", $1.begin); } | pointer direct_abs_declarator { $$ = $2; (void)sprintf(buf, "%s%s", $1.text, $$->text); free($$->text); $$->text = xstrdup(buf); $$->begin = $1.begin; } | direct_abs_declarator ;direct_abs_declarator : '(' abs_declarator ')' { $$ = $2; (void)sprintf(buf, "(%s)", $$->text); free($$->text); $$->text = xstrdup(buf); $$->begin = $1.begin; } | direct_abs_declarator T_BRACKETS { $$ = $1; (void)sprintf(buf, "%s%s", $$->text, $2.text); free($$->text); $$->text = xstrdup(buf); } | T_BRACKETS { $$ = new_declarator($1.text, "", $1.begin); } | direct_abs_declarator '(' parameter_type_list ')' { $$ = new_declarator("%s()", "", $1->begin); $$->params = $3; $$->func_stack = $1; $$->head = ($1->func_stack == NULL) ? $$ : $1->head; $$->func_def = FUNC_ANSI; } | direct_abs_declarator '(' ')' { $$ = new_declarator("%s()", "", $1->begin); $$->func_stack = $1; $$->head = ($1->func_stack == NULL) ? $$ : $1->head; $$->func_def = FUNC_ANSI; } | '(' parameter_type_list ')' { Declarator *d; d = new_declarator("", "", $1.begin); $$ = new_declarator("%s()", "", $1.begin); $$->params = $2; $$->func_stack = d; $$->head = $$; $$->func_def = FUNC_ANSI; } | '(' ')' { Declarator *d; d = new_declarator("", "", $1.begin); $$ = new_declarator("%s()", "", $1.begin); $$->func_stack = d; $$->head = $$; $$->func_def = FUNC_ANSI; } ;%%#if defined(__EMX__) || defined(MSDOS) || defined(OS2) || defined(WIN32) || defined(vms)# ifdef USE_flex# include "lexyy.c"# else# include "lex_yy.c"# endif#else# include "lex.yy.c"#endifstatic voidyaccError (char *msg){ func_params = NULL; put_error(); /* tell what line we're on, and what file */ fprintf(stderr, "%s at token '%s'\n", msg, yytext);}/* Initialize the table of type qualifier keywords recognized by the lexical * analyzer. */voidinit_parser (void){ static char *keywords[] = { "const", "restrict", "volatile", "interrupt",#ifdef vms "noshare", "readonly",#endif#if defined(MSDOS) || defined(OS2) "__cdecl", "__export", "__far", "__fastcall", "__fortran", "__huge", "__inline", "__interrupt", "__loadds", "__near", "__pascal", "__saveregs", "__segment", "__stdcall", "__syscall", "_cdecl", "_cs", "_ds", "_es", "_export", "_far", "_fastcall", "_fortran", "_huge", "_interrupt", "_loadds", "_near", "_pascal", "_saveregs", "_seg", "_segment", "_ss", "cdecl", "far", "huge", "near", "pascal",#ifdef OS2 "__far16",#endif#endif#ifdef __GNUC__ /* gcc aliases */ "__builtin_va_arg", "__builtin_va_list", "__const", "__const__", "__inline", "__inline__", "__restrict", "__restrict__", "__volatile", "__volatile__",#endif }; unsigned i; /* Initialize type qualifier table. */ type_qualifiers = new_symbol_table(); for (i = 0; i < sizeof(keywords)/sizeof(keywords[0]); ++i) { new_symbol(type_qualifiers, keywords[i], NULL, DS_NONE); }}/* Process the C source file. Write function prototypes to the standard * output. Convert function definitions and write the converted source * code to a temporary file. */voidprocess_file (FILE *infile, char *name){ char *s; if (strlen(name) > 2) { s = name + strlen(name) - 2; if (*s == '.') { ++s; if (*s == 'l' || *s == 'y') BEGIN LEXYACC;#if defined(MSDOS) || defined(OS2) if (*s == 'L' || *s == 'Y') BEGIN LEXYACC;#endif } } included_files = new_symbol_table(); typedef_names = new_symbol_table(); define_names = new_symbol_table(); inc_depth = -1; curly = 0; ly_count = 0; func_params = NULL; yyin = infile; include_file(strcpy(base_file, name), func_style != FUNC_NONE); if (file_comments) {#if OPT_LINTLIBRARY if (lintLibrary()) { put_blankline(stdout); begin_tracking(); }#endif put_string(stdout, "/* "); put_string(stdout, cur_file_name()); put_string(stdout, " */\n"); } yyparse(); free_symbol_table(define_names); free_symbol_table(typedef_names); free_symbol_table(included_files);}#ifdef NO_LEAKSvoidfree_parser(void){ free_symbol_table (type_qualifiers);#ifdef FLEX_SCANNER if (yy_current_buffer != 0) yy_delete_buffer(yy_current_buffer);#endif}#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -