In-depth compilation principles-1-C Grammar

Source: Internet
Author: User

Compilation principles-1-C Grammar
Syntax:
 
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 '}'
| '{'Claration_list statement_list '}'
 
Declaration_list à
Declaration
| Declaration_list declaration
 
Declaration à
Init_declarator
| Init_declarator_list ', 'init_declarator
 
Init_declarator à
Declarator
| 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 '{'__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_effecact_declarator à
'('Abstract_declarator ')'
| '['']'
| '['Stant_expression']'
| Direct_effecact_declarator '['']'
| Direct_effecact_declarator '['constant_expression']'
| '('')'
| '('Parameter_type_list ')'
| Direct_effecact_declarator '('')'
| Direct_effecact_declarator '('parameter_type_list ')'

Labeled_statement à
IDENTIFIER ': 'Statement
| CASE constant_expression': 'Statement
| DEFAULT ': 'Statement
Author: rill_zhen

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.