1樓:
最佳答案就在C語言的標準裡,C99標準裡定義了6種statement(語句):
for語句屬於: iteration-statementif語句屬於:selection-statement所謂花括號{} 屬於compound-statement而帶分號;的語句屬於expression-statement這裡需要重點說明一下(導致題主疑惑的關鍵點,也是很多人不清楚的地方):
x = 1; // 注意!這裡有分號,這是乙個語句!
x = 1 //注意!這裡沒有分號,這是僅僅是乙個表示式(expression),不是乙個語句(statement)!
2樓:TTTTTT
似乎語句塊內部自帶分號,於是被定義為完整語句,直接就用,當做一條語句處理。
結構體和陣列定義成員是一樣的,不算完整語句,所以後面加分號(?)
3樓:
C語言語法的BNF描述:
%token int_const char_const float_const id string enumeration_const
%%translation_unit : external_decl
| translation_unit external_decl
;external_decl : function_definition
| decl
;function_definition : decl_specs declarator decl_list compound_stat
| declarator decl_list compound_stat
| decl_specs declarator compound_stat
| declarator compound_stat
;decl : decl_specs init_declarator_list ';'
| decl_specs ';'
;decl_list : decl
| decl_list decl
;decl_specs : storage_class_spec decl_specs
| storage_class_spec
| type_spec decl_specs
| type_spec
| type_qualifier decl_specs
| type_qualifier
;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_or_union id ''
| struct_or_union ''
| struct_or_union id
;struct_or_union : 'struct' | 'union'
;struct_decl_list : struct_decl
| struct_decl_list struct_decl
;init_declarator_list : init_declarator
| init_declarator_list ',' init_declarator
;init_declarator : declarator
| declarator '=' initializer
;struct_decl : spec_qualifier_list struct_declarator_list ';'
;spec_qualifier_list : type_spec spec_qualifier_list
| type_spec
| type_qualifier spec_qualifier_list
| type_qualifier
;struct_declarator_list : struct_declarator
| struct_declarator_list ',' struct_declarator
;struct_declarator : declarator
| declarator ':' const_exp
| ':' const_exp
;enum_spec : 'enum' id ''
| 'enum' ''
| 'enum' id
;enumerator_list : enumerator
| enumerator_list ',' enumerator
;enumerator : id
| id '=' const_exp
;declarator : pointer direct_declarator
| direct_declarator
;direct_declarator : id
| '(' declarator ')'
| direct_declarator '[' const_exp ']'
| direct_declarator '[' ']'
| direct_declarator '(' param_type_list ')'
| direct_declarator '(' id_list ')'
| direct_declarator '(' ')'
;pointer : '*' type_qualifier_list
| '*'
| '*' type_qualifier_list pointer
| '*' pointer
;type_qualifier_list : type_qualifier
| type_qualifier_list type_qualifier
;param_type_list : param_list
| param_list ',' '...'
;param_list : param_decl
| param_list ',' param_decl
;param_decl : decl_specs declarator
| decl_specs abstract_declarator
| decl_specs
;id_list : id
| id_list ',' id
;initializer : assignment_exp
| ''
| ''
;initializer_list : initializer
| initializer_list ',' initializer
;type_name : spec_qualifier_list abstract_declarator
| spec_qualifier_list
;abstract_declarator : pointer
| pointer direct_abstract_declarator
| direct_abstract_declarator
;direct_abstract_declarator: '(' abstract_declarator ')'
| direct_abstract_declarator '[' constexp ']ལ[' const_exp ']'
| direct_abstract_declarator '[' ']ལ[' ']'
| direct_abstract_declarator '(' param_type_list ')ལ(' param_type_list ')'
| direct_abstract_declarator '(' ')ལ(' ')'
;typedef_name : id
;stat : labeled_stat
| exp_stat
| compound_stat
| selection_stat
| iteration_stat
| jump_stat
;labeled_stat : id ':' stat
| 'case' const_exp ':' stat
| 'default' ':' stat
;exp_stat : exp ';'
| ';'
;compound_stat : ''
| ''
| ''
| ''
;stat_list : stat
| stat_list stat
;selection_stat : 'if' '(' exp ')' stat
| 'if' '(' exp ')' stat 'else' stat
| 'switch' '(' exp ')' stat
;iteration_stat : 'while' '(' exp ')' stat
| 'do' stat 'while' '(' exp ')' ';'
| 'for' '(' exp ';' exp ';' exp ')' stat
| 'for' '(' exp ';' exp ';' ')' stat
| 'for' '(' exp ';' ';' exp ')' stat
| 'for' '(' exp ';' ';' ')' stat
| 'for' '(' ';' exp ';' exp ')' stat
| 'for' '(' ';' exp ';' ')' stat
| 'for' '(' ';' ';' exp ')' stat
| 'for' '(' ';' ';' ')' stat
;jump_stat : 'goto' id ';'
| 'continue' ';'
| 'break' ';'
| 'return' exp ';'
| 'return' ';'
;exp : assignment_exp
| exp ',' assignment_exp
;assignment_exp : conditional_exp
| unary_exp assignment_operator assignment_exp
;assignment_operator : '=' | '*=' | '/=' | '%=' | '+=' | '-=' | '<<='
| '>>=' | '&=' | '^=' | '|='
;conditional_exp : logical_or_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 : inclusive_or_exp
| logical_and_exp '&&' inclusive_or_exp
;inclusive_or_exp : exclusive_or_exp
| inclusive_or_exp '|' exclusive_or_exp
;exclusive_or_exp : and_exp
| exclusive_or_exp '^' and_exp
;and_exp : equality_exp
| and_exp '&' equality_exp
;equality_exp : relational_exp
| equality_exp '==' relational_exp
| equality_exp '!=' relational_exp
;relational_exp : shift_expression
| relational_exp '<' shift_expression
| relational_exp '>' shift_expression
| relational_exp '<=' shift_expression
| relational_exp '>=' shift_expression
;shift_expression : additive_exp
| shift_expression '<<' additive_exp
| shift_expression '>>' additive_exp
;additive_exp : mult_exp
| additive_exp '+' mult_exp
| additive_exp '-' mult_exp
;mult_exp : cast_exp
| mult_exp '*' cast_exp
| mult_exp '/' cast_exp
| mult_exp '%' cast_exp
;cast_exp : unary_exp
| '(' type_name ')' cast_exp
;unary_exp : postfix_exp
| '++' unary_exp
| '--' unary_exp
| unary_operator cast_exp
| 'sizeof' unary_exp
| 'sizeof' '(' type_name ')'
;unary_operator : '&' | '*' | '+' | '-' | '~' | '!'
;postfix_exp : primary_exp
| postfix_exp '[' exp ']'
| postfix_exp '(' argument_exp_list ')'
| postfix_exp '(' ')'
| postfix_exp '.' id
| postfix_exp '->' id
| postfix_exp '++'
| postfix_exp '--'
;primary_exp : id
| const
| string
| '(' exp ')'
;argument_exp_list : assignment_exp
| argument_exp_list ',' assignment_exp
;const : int_const
| char_const
| float_const
| enumeration_const;
請問乙個c語言的問題?
土地測量員 反對那些說看IEEE 754浮點數標準的 暫且不談c標準裡浮點數表示方法是implementation defined 即使你知道了IEEE754浮點標準,也不能解釋輸出的結果。因為用 d輸出浮點數是未定義行為。同理,也反對樓上通過看彙編解釋輸出結果的方法,因為這解釋只在特定實現下有效。...
如何用C語言畫乙個蘑菇?
冷月i include include int main printf printf n printf printf n printf printf n printf printf n printf printf n printf printf n printf return 0 小時候金字塔就是這...
論語的乙個小疑問?
已重置 孔子罵宰我朽木不可雕,只是一時氣憤,孔子原本想好好 雕 好好教育他的,這正說明也子有教無類。但是孔子也是因材施教,還說中人以下,不可以語上。他發現宰我不可以語上,不肯用功,所以就說朽木不可雕,二者不矛盾。乙個是想不想教,乙個是被教之人是不是那塊材料,是不是可造之材。乙個是指老師的態度而言,乙...