translation_unit:
[ translation_unit ] external_decl
external_decl:
function_definition
| decl
function_definition:
[ decl_specs ] declarator [ decl_list ] compound_stat
decl_list:
[ decl_list ] decl_specs [ init_declarator_list ] ";"
decl_specs:
( storage_class_spec | type_spec | type_qualifier ) [ decl_specs ]
storage_class_spec:
"auto"
| "register"
| "static"
| "extern"
| "typedef"
type_spec:
"void"
| "char"
| "short"
| "int"
| "long"
| "float"
| "double"
| "signed"
| "unsigned"
| struct_or_union_spec
| enum_spec
| typedef_name
type_qualifier:
"const"
| "volatile"
struct_or_union_spec:
( "struct" | "union" ) ( id | [ id ] "{" struct_decl_list "}" )
struct_decl_list:
[ struct_decl_list ] spec_qualifier_list struct_declarator_list ";"
init_declarator_list:
[ init_declarator_list "," ] declarator [ "=" initializer ]
spec_qualifier_list:
( type_spec | type_qualifier ) [ spec_qualifier_list ]
struct_declarator_list:
[ struct_declarator_list "," ] ( declarator | [ declarator ] ":" const_exp )
enum_spec:
"enum" ( id | [ id ] "{" enumerator_list "}" )
enumerator_list:
[ enumerator_list "," ] id [ "=" const_exp ]
declarator:
[ pointer ] direct_declarator
direct_declarator:
id
| "(" declarator ")"
| direct_declarator "[" [ const_exp ] "]"
| direct_declarator "(" [ param_type_list | id_list ] ")"
pointer:
"*" [ type_qualifier_list ] [ pointer ]
type_qualifier_list:
[ type_qualifier_list ] type_qualifier
param_type_list:
param_list [ "," "..." ]
param_list:
{ param_decl "," } param_decl
param_decl:
decl_specs [ declarator | abstract_declarator ]
id_list:
{ id "," } id
initializer:
assignment_exp
| "{" initializer_list "}"
| "{" initializer_list "," "}"
initializer_list:
{ initializer "," } initializer
type_name:
spec_qualifier_list [ abstract_declarator ]
abstract_declarator:
pointer
| pointer direct_abstract_declarator
| direct_abstract_declarator
direct_abstract_declarator:
"(" abstract_declarator ")"
| [ direct_abstract_declarator ] ( "[" const_exp "]" | "[" "]" | "(" [ param_type_list ] ")" )
typedef_name:
id
stat:
labeled_stat
| exp_stat
| compound_stat
| selection_stat
| iteration_stat
| jump_stat
labeled_stat:
( id | "case" | "default" ) ":" stat
exp_stat:
[ exp ] ";"
compound_stat:
"{" [ decl_list ] [ stat_list ] "}"
stat_list:
{ stat } stat
selection_stat:
"if" "(" exp ")" stat [ "else" stat ]
| "switch" "(" exp ")" stat
iteration_stat:
"while" "(" exp ")" stat
| "do" stat "while" "(" exp ")" ";"
| "for" "(" [ exp ] ";" [ exp ] ";" [ exp ] ")" stat
jump_stat:
"goto" id ";"
| "continue" ";"
| "break" ";"
| "return" [ exp ] ";"
exp:
[ exp "," ] assignment_exp
assignment_exp:
conditional_exp
| unary_exp assignment_operator assignment_exp
assignment_operator:
"="
| "*="
| "/="
| "%="
| "+="
| "-="
| "<<="
| ">>="
| "&="
| "^="
| "|="
conditional_exp:
logical_or_exp [ "?" exp ":" conditional_exp ]
const_exp:
conditional_exp
logical_or_exp:
logical_and_exp
| logical_or_exp [ "||" logical_and_exp ]
logical_and_exp:
[ logical_and_exp "&&" ] inclusive_or_exp
inclusive_or_exp:
[ inclusive_or_exp "|" ] exclusive_or_exp
exclusive_or_exp:
[ exclusive_or_exp "^" ] and_exp
and_exp:
[ and_exp "&" ] equality_exp
equality_exp:
[ equality_exp ( "==" | "!=" ) ] relational_exp
relational_exp:
[ relational_exp ( "<" | ">" | "<=" | ">=" ) ] shift_expression
shift_expression:
[ shift_expression ( "<<" | ">>" ) ] additive_exp
additive_exp:
[ additive_exp ( "+" | "-" ) ] mult_exp
mult_exp:
[ mult_exp ( "*" | "/" | "%" ) ] cast_exp
cast_exp:
unary_exp
| "(" type_name ")" cast_exp
unary_exp:
postfix_exp
| ( "++" | "--" ) unary_exp
| unary_operator cast_exp
| "sizeof" ( unary_exp | "(" type_name ")" )
unary_operator:
"&"
| "*"
| "+"
| "-"
| "~"
| "!"
postfix_exp:
primary_exp
| postfix_exp "[" exp "]"
| postfix_exp "(" [ argument_exp_list ] ")"
| postfix_exp ( "." | "->" ) id
| postfix_exp ( "++" | "--" )
primary_exp:
id
| const
| string
| "(" exp ")"
argument_exp_list:
[ argument_exp_list "," ] assignment_exp
const:
int_const
| char_const
| float_const
| enumeration_const