program à //程序
external_declaration //外部声明
| program external_declaration
external_declaration à //外部声明
function_definition //函数定义
| declaration //声明
function_definition à type_specifier declarator compound_statement
类型说明符 声明 复合语句
type_specifier à
VOID
| CHAR
| INT
| FLOAT
declarator
pointer direct_declarator //指针 直接说明符
| direct_declarator
Pointerà //指针
‘*‘
| ‘*‘ pointer
direct_declarator //直接说明符
IDENTIFIER //标识符
|direct_declarator’[‘ ‘]’ ////直接说明符
|direct_declarator ’[’ constant_expression ’]’ //常量表达式
| IDENTIFIER ‘(‘ parameter_list ‘)‘ //参数表
| IDENTIFIER ‘(‘ ‘)‘
|direct_declarator ‘,’ identifier_list //标识符列表
identifier_list //标识符列表
: IDENTIFIER //标识符
| identifier_list ‘,‘ IDENTIFIER
constant_expressionà //常量表达式
conditional_expression //条件表达式
parameter_list à //参数表
parameter_declaration //参数声明
| parameter_list ‘,‘ parameter_declaration
参数表 参数声明
parameter_declaration à //参数声明
declaration_specifiers IDENTIFIER
声明说明 标识符
compound_statement à //复合语句
‘{‘ ‘}‘
| ‘{‘ statement_list ‘}‘ //语句列表
| ‘{‘ declaration_list statement_list ‘}‘
声明列表 语句列表
declaration_list à //声明列表
declaration
| declaration_list declaration
Declarationà // 声明
init_declarator //初始化声明符
| init_declarator_list ‘,‘ init_declarator
初始化声明符列表
init_declarator à
declaratory //声明符
| declarator ‘=‘ initializer //初始化
Initializer à //初始化
assignment_expression //赋值表达式
| ‘{‘ initializer_list ‘}‘ //初始化列表
| ‘{‘ initializer_list ‘,‘ ‘}‘
initializer_list à //初始化列表
initializer
| initializer_list ‘,‘ initializer
statement_listà //语句列表
statement
| statement_list statement
Statement à
| compound_statement //复合语句
| expression_statement //表达式语句
| selection_statement //选择语句
| iteration_statement //循环语句
| jump_statement //跳转语句
expression_statement à //表达式语句
‘;‘
| expression ‘;‘ //表达式
selection_statement //选择语句
: IF ‘(‘ expression ‘)‘ statement
| IF ‘(‘ expression ‘)‘ statement ELSE statement
iteration_statementà //循环语句
WHILE ‘(‘ expression ‘)‘ statement
| FOR ‘(‘ expression_statement expression_statement ‘)‘ statement
| FOR ‘(‘ expression_statement expression_statement expression ‘)‘ statement
jump_statement //跳转语句
| CONTINUE ‘;‘
| BREAK ‘;‘
| RETURN ‘;‘
| RETURN expression ‘;‘
expression
: assignment_expression //赋值表达式
| expression ‘,‘ assignment_expression
assignment_expression à //赋值表达式
conditional_expression //条件表达式
| unary_expression assignment_operator assignment_expression
一元表达式 赋值运算符 赋值表达式
conditional_expression à //条件表达式
logical_or_expression //逻辑或表达式
| logical_or_expression ‘?‘ expression ‘:‘ conditional_expression
逻辑或表达式 条件表达式
logical_or_expression à
logical_and_expression //逻辑与
| logical_or_expression OR_OP logical_and_expression
logical_and_expression //逻辑与
: inclusive_or_expression //包容或表达式
| logical_and_expression AND_OP inclusive_or_expression
inclusive_or_expressionà
exclusive_or_expression //唯一或表达式
| inclusive_or_expression ‘|‘ exclusive_or_expression
exclusive_or_expression //唯一或表达式
: and_expression
| exclusive_or_expression ‘^‘ and_expression
and_expression
: equality_expression //平等表达
| and_expression ‘&‘ equality_expression
equality_expression //平等表达
: relational_expression //关系式
| equality_expression EQ_OP relational_expression
| equality_expression NE_OP relational_expression
relational_expression //关系式
: shift_expression //移动式
| relational_expression ‘<‘ shift_expression
| relational_expression ‘>‘ shift_expression
| relational_expression LE_OP shift_expression
| relational_expression GE_OP shift_expression
shift_expression //移动式
: additive_expression //附加表达式
| shift_expression LEFT_OP additive_expression
| shift_expression RIGHT_OP additive_expression
additive_expression //附加表达式
: multiplicative_expression //乘法式
| additive_expression ‘+‘ multiplicative_expression
| additive_expression ‘-‘ multiplicative_expression
multiplicative_expression //乘法式
: cast_expression //转换表达式
| multiplicative_expression ‘*‘ cast_expression
| multiplicative_expression ‘/‘ cast_expression
| multiplicative_expression ‘%‘ cast_expression
cast_expression //转换表达式
: unary_expression //一元表达式
| ‘(‘ type_name ‘)‘ cast_expression
unary_expression //一元表达式
: postfix_expression //后缀表达式
| INC_OP unary_expression //一元表达式
| DEC_OP unary_expression
| unary_operator cast_expression //转换表达式
| SIZEOF unary_expression
| SIZEOF ‘(‘ type_name ‘)‘ //类型名称
postfix_expression à //后缀表达式
: primary_expression //主要表现
| postfix_expression ‘[‘ expression ‘]‘
| postfix_expression ‘(‘ ‘)‘
| postfix_expression ‘(‘ argument_expression_list ‘)‘
参数表达式列表
| postfix_expression ‘.‘ IDENTIFIER //标识符
| postfix_expression PTR_OP IDENTIFIER
| postfix_expression INC_OP
| postfix_expression DEC_OP
primary_expression à //主要表现
IDENTIFIER
| CONSTANT
| STRING_LITERAL
| ‘(‘ expression ‘)argument_expression_list //参数表达式列表
: assignment_expression
| argument_expression_list ‘,‘ assignment_expression
unary_operator //一元运算符
: ‘&‘
| ‘*‘
| ‘+‘
| ‘-‘
| ‘~‘
| ‘!‘
assignment_operator à //赋值运算符
‘=‘
| MUL_ASSIGN
| DIV_ASSIGN
| MOD_ASSIGN
| ADD_ASSIGN
| SUB_ASSIGN
| LEFT_ASSIGN
| RIGHT_ASSIGN
| AND_ASSIGN
| XOR_ASSIGN
| OR_ASSIGN
storage_class_specifier à //存储类说明
TYPEDEF
| EXTERN
| STATIC
| AUTO
| REGISTER
struct_or_union_specifier //结构或联合说明符
: struct_or_union IDENTIFIER ‘{‘ struct_declaration_list ‘}‘
结构声明表
| struct_or_union ‘{‘ struct_declaration_list ‘}‘
| struct_or_union IDENTIFIER
struct_or_union
: STRUCT
| UNION
struct_declaration_list //结构声明表
: struct_declaration //结构声明
| struct_declaration_list struct_declaration
struct_declaration //结构声明
: specifier_qualifier_list struct_declarator_list ‘;‘
specifier_qualifier_list à
type_specifier specifier_qualifier_list
| type_specifier
| type_qualifier specifier_qualifier_list
| type_qualifier
struct_declarator_list à //结构声明表
struct_declarator //结构声明
| struct_declarator_list ‘,‘ struct_declarator
struct_declarator à : declarator
| ‘:‘ constant_expression
| declarator ‘:‘ constant_expression
enum_specifier à //枚举说明
ENUM ‘{‘ enumerator_list ‘}‘ //枚举列表
| ENUM IDENTIFIER ‘{‘ enumerator_list ‘}‘ //枚举列表
| ENUM IDENTIFIER
enumerator_list à //枚举列表
enumerator
| enumerator_list ‘,‘ enumerator
Enumerator à
IDENTIFIER
| IDENTIFIER ‘=‘ constant_expression
type_qualifier à
CONST
| VOLATILE
type_qualifier_list à
type_qualifier
| type_qualifier_list type_qualifier
parameter_type_list à //参数类型列表
parameter_list
| parameter_list ‘,‘ ELLIPSIS
parameter_list à //参数类型列表
: parameter_declaration //参数类型说明
| parameter_list ‘,‘ parameter_declaration
type_name à
specifier_qualifier_list
| specifier_qualifier_list abstract_declarator
抽象声明符
abstract_declarator à //抽象声明符
pointer
| direct_abstract_declarator
| pointer direct_abstract_declarator
direct_abstract_declarator à //直接抽象声明
‘(‘ abstract_declarator ‘)‘ //抽象声明符
| ‘[‘ ‘]‘
| ‘[‘ constant_expression ‘]‘ //常量表达式
| direct_abstract_declarator ‘[‘ ‘]‘
| direct_abstract_declarator ‘[‘ constant_expression ‘]‘
| ‘(‘ ‘)‘
| ‘(‘ parameter_type_list ‘)‘ //参数类型列表
| direct_abstract_declarator ‘(‘ ‘)‘
| direct_abstract_declarator ‘(‘ parameter_type_list ‘)‘
labeled_statement à //标签语句
IDENTIFIER ‘:‘ statement
| CASE constant_expression ‘:‘ statement //常量表达式
| DEFAULT ‘:‘ statement