📄 fbparse.y
字号:
%{/* * FBCC - A simple C compiler. * * Copyright (c) 1996 Fabrice Bellard * * Contact addresses: * mail: Fabrice Bellard, 451 chemin du mas de Matour, 34790 Grabels, France * email: bellard@email.enst.fr * url: http://www.enst.fr/~bellard * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include "fbcc.h"%}/* structures des programmes */%token sym_if%token sym_else%token sym_while%token sym_do%token sym_for%token sym_goto%token sym_continue%token sym_break%token sym_return%token sym_case%token sym_default%token sym_switch%token sym_sizeof/* types */%token sym_void%token sym_char%token sym_short%token sym_int%token sym_long%token sym_float%token sym_double%token sym_signed%token sym_unsigned%token sym_struct%token sym_union%token sym_enum /* classes de stockage */%token sym_auto%token sym_register%token sym_static%token sym_extern%token%token sym_typedef/* qualificatifs de type */%token sym_const%token sym_volatile /* symboles divers */%token sym_le%token sym_ge%token sym_eq%token sym_ne%token sym_inc%token sym_dec%token sym_land%token sym_lor%token sym_shl%token sym_shr%token sym_assign_add%token sym_assign_sub%token sym_assign_mul%token sym_assign_div%token sym_assign_mod%token sym_assign_and%token sym_assign_or%token sym_assign_xor%token sym_assign_shr%token sym_assign_shl%token sym_three_points%token sym_arrow/* constantes */%token sym_const_int%token sym_const_str%token sym_const_char/* identificateurs */%token sym_ident%token sym_typedef_ident%%unite_de_traduction: declaration_externe| unite_de_traduction declaration_externe;declaration_externe: definition_de_fonction| declaration;/* declarations de fonction */definition_de_fonction: specificateur_de_declaration declarateur { Func_Declare($1,$2,NULL); } instruction_composee { Func_End(); }| declarateur { Func_Declare(NULL,$1,NULL); } instruction_composee { Func_End(); }| specificateur_de_declaration declarateur liste_de_declarations_fonction { Func_Declare($1,$2,$3); } instruction_composee { Func_End(); }| declarateur liste_de_declarations_fonction { Func_Declare(NULL,$1,$2); } instruction_composee { Func_End(); };liste_de_declarations_fonction: declaration_fonction { $$=$1; }| liste_de_declarations_fonction declaration_fonction { $$=append($1,$2); }; declaration_fonction: specificateur_de_declaration liste_de_declarateurs_init ';' { $$=Type_VarList($1,$2); };/* declarations de variables */ liste_de_declarations: declaration| liste_de_declarations declaration;declaration: specificateur_de_declaration ';' { list_free($1); }| specificateur_de_declaration liste_de_declarateurs_init ';' { LIST *vars; vars=Type_VarList($1,$2); Var_Declare(vars); list_free(vars); };specificateur_de_declaration: specificateur_de_classe_de_stockage { $$=$1; }| specificateur_de_classe_de_stockage specificateur_de_declaration { $$=append($1,$2); }| specificateur_de_type { $$=$1; }| specificateur_de_type specificateur_de_declaration { $$=append($1,$2); }| qualificatif_de_type { $$=$1; }| qualificatif_de_type specificateur_de_declaration { $$=append($1,$2); };specificateur_de_classe_de_stockage : sym_auto { $$=mk_tag(STORAGE_AUTO,NULL); }| sym_register { $$=mk_tag(STORAGE_REGISTER,NULL); }| sym_static { $$=mk_tag(STORAGE_STATIC,NULL); }| sym_extern { $$=mk_tag(STORAGE_EXTERN,NULL); }| sym_typedef { $$=mk_tag(STORAGE_TYPEDEF,NULL); };specificateur_de_type: sym_void { $$=mk_tag(TYPE_VOID,NULL); }| sym_char { $$=mk_tag(TYPE_CHAR,NULL); }| sym_short { $$=mk_tag(TYPE_SHORT,NULL); }| sym_int { $$=mk_tag(TYPE_INT,NULL); }| sym_signed { $$=mk_tag(TYPE_SIGNED,NULL); }| sym_unsigned { $$=mk_tag(TYPE_UNSIGNED,NULL); }| specificateur_de_struct { $$=$1; }| specificateur_enumeration { $$=$1; }| sym_typedef_ident { $$=mk_tag(TYPE_TYPEDEF_IDENT,$1); };qualificatif_de_type: sym_const { $$=mk_tag(QUALIF_CONST,NULL); }| sym_volatile { $$=mk_tag(QUALIF_VOLATILE,NULL); };liste_de_declarateurs_init: declarateur_init { $$=$1; }| liste_de_declarateurs_init ',' declarateur_init { $$=append($1,$3); };declarateur_init: declarateur { $$=mk_list($1,mk_list(NULL,NULL)); }| declarateur '=' initialisateur { $$=mk_list($1,mk_list($3,NULL)); };/* structs et unions */struct_ou_union: sym_struct { $$=mk_tag(TYPE_STRUCT,NULL); }| sym_union { $$=mk_tag(TYPE_UNION,NULL); };specificateur_de_struct: struct_ou_union '{' liste_de_declarations_de_struct '}' { $$=Struct_Declare(NULL,hd_tag($1),$3); list_free($1); list_free($3); }| struct_ou_union sym_ident '{' liste_de_declarations_de_struct '}' { $$=Struct_Declare(hd_str($2),hd_tag($1),$4); list_free($1); list_free($2); list_free($4);}| struct_ou_union sym_ident { $$=Struct_Use(hd_str($2),hd_tag($1)); list_free($1); list_free($2);};liste_de_declarations_de_struct: declaration_de_struct { $$=$1; }| liste_de_declarations_de_struct declaration_de_struct { $$=append($1,$2);};declaration_de_struct: liste_de_qualificatifs_de_specificateurs liste_de_declarateurs_de_struct ';' { $$=Type_VarList($1,$2); };liste_de_qualificatifs_de_specificateurs: specificateur_de_type { $$=$1; }| specificateur_de_type liste_de_qualificatifs_de_specificateurs { $$=append($1,$2); }| qualificatif_de_type { $$=$1; }| qualificatif_de_type liste_de_qualificatifs_de_specificateurs { $$=append($1,$2); }; /* nous avons supprim
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -