C Language Grammar

Source: Internet
Author: User

SOURCE program 〉-〉< External declarations >|< source programs >< External declarations >
< external declarations >->< defining functions >|< declarations >
< function definition >→< type specifier > < declarator > < compound statement >
< descriptor type >→< no return type > | < character type > | < integral type > | < floating-point >
< declarators > < pointers > < direct declarators > | < direct declarators >
< pointers >→< ' * ' > | < ' * ' pointers >
< direct declarators > < identifiers > | < Direct statement >[]| < Direct declaration ><[constant Expression]> | < identifiers > (parametric tables) | < identifiers > () | < direct declarations >,< identifiers list >
< identifier list >:< identifiers > | < identifier list >,< identifiers >
< constant expressions >→< conditional expressions >
< parameter list >→< parameter declaration > | < parameter list >,< parameter declaration >
< parameter declarations >→< descriptor declarations >< identifiers >

compound_statement→ Compound statement

‘{‘ ‘}‘

| ' {' statement_list '} ' {' Statement list '} '

| ' {' Declaration_list statement_list '} ' {' Declaration statement list '} '

declaration_list→ Declaration List

Declaration

| Declaration_list Declaration Declaration List Declaration

declaration→ statement

Init_declarator Initialization Declaration

| Init_declarator_list ', ' init_declarator

Initialize declaration list ', ' Initialize declaration

init_declarator→ Initialization Declaration

Declarator Initialization Declaration

| declarator ' = ' initializer declaration ' = ' initialization program

initializer→ Initialization Program

Assignment_expression-value Assignment expression

| ' {' initializer_list '} ' {' Initialize list '} '

| ' {' Initializer_list ', '} ' ibid.

initializer_list→ Initialization List

Initializer Initialization program

| Initializer_list ', ' initializer

statement_list→ Statement List

Statement statements

| Statement_list statement

statement→ statements

| Compound_statement Compound statement

| Expression_statement expression Statements

| Selection_statement conditional statements

| Iteration_statement Loop Statements

| Jump_statement Jump Statement

expression_statement→

‘;‘

| expression '; '

expression statement → '; ' | An expression '; '

Selection_statement

: IF ' (' expression ') ' statement

| IF ' (' expression ') ' statement ELSE statement

Conditional statement: IF ' (' expression ') statement | IF ' (' expression ') ' statement conditional statement

iteration_statement→

While ' (' expression ') ' statement

| For ' (' expression_statement expression_statement ') ' statement

| For ' (' expression_statement expression_statement expression ') ' statement

Loop statement →while ' (' expression ') ' statement | For ' (' expression statement expression statement ') ' statement | For ' (' expression statement expression Statement expression ') ' statement

Jump_statement

| CONTINUE '; '

| Break '; '

| RETURN '; '

| RETURN expression '; '

Jump Statement | CONTINUE '; ' | Break '; ' | RETURN '; ' | RETURN expression '; '

Expression

: assignment_expression

| Expression ', ' assignment_expression

Expression: an Assignment expression | Expression ', ' an assignment expression

assignment_expression→

Conditional_expression

| Unary_expression Assignment_operator assignment_expression

assignment expression → conditional expression | Unary expression assignment operator assignment expression

conditional_expression→

Logical_or_expression

| Logical_or_expression '? ' expression ': ' Conditional_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

Logic or expression → logic and expression | Logical OR expression or arithmetic logical expression

Logical_and_expression

: inclusive_or_expression

| Logical_and_expression And_op inclusive_or_expression

Logic and expression: or expression | Logical expressions and operations or expressions

inclusive_or_expression→

Exclusive_or_expression

| Inclusive_or_expression ' | ' exclusive_or_expression

or op-expression → xor expression | or arithmetic expression ' | ' XOR expression

Exclusive_or_expression

: and_expression

| Exclusive_or_expression ' ^ ' and_expression

Xor expression: with Expression | Xor expression ' ^ ' with an expression

And_expression

: equality_expression

| And_expression ' & ' equality_expression

With expression: Equality expression | Equality expression with expression ' & '

Equality_expression

: relational_expression

| Equality_expression Eq_op relational_expression

| Equality_expression Ne_op relational_expression

Equality expressions: Relational Expressions | Equality expression equals an expression of an operation relationship | An equality expression is not equal to an expression of an operation relationship

Relational_expression

: shift_expression

| Relational_expression ' < ' shift_expression

| Relational_expression ' > ' shift_expression

| Relational_expression Le_op shift_expression

| Relational_expression Ge_op shift_expression

Relational expressions: Shift Expressions | Relationship expression ' < ' shift expression | Relationship expression ' > ' Shift expression | Relational expression is less than or equal to an operation shift expression | Relational expression is greater than or equal to an operation shift expression

Shift_expression

: additive_expression

| Shift_expression Left_op additive_expression

| Shift_expression Right_op additive_expression

Shift expression: addition expression | Shift expression Left arithmetic addition expression | Shift expression Right arithmetic addition expression

Additive_expression

: multiplicative_expression

| Additive_expression ' + ' multiplicative_expression

| Additive_expression '-' multiplicative_expression

Addition expression: multiplication expression | Addition expression ' + ' multiplication expression | Addition expression '-' multiplication expression

Multiplicative_expression

: cast_expression

| Multiplicative_expression ' * ' cast_expression

| Multiplicative_expression '/' cast_expression

| Multiplicative_expression '% ' cast_expression

Multiplication Expressions: Cast Expressions | Multiplication expression ' * ' casts an expression | Multiplication expression '/' cast expression | Multiply expression '% ' cast expression

Cast_expression

: unary_expression

| ' (' type_name ') ' 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 ') '

Unary expression: suffix expression | inc Operation unary Expression | Dec Operation unary Expression | Unary operator adds an expression | unary expressions for struct variables | struct variable ' (' 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

Postfix expression: basic expression | suffix expression ' [' expression '] ' | Suffix expression ' (') | Suffix expression ' (' parameter expression list ') ' | Suffix expression '. ' identifier | Suffix expression Pointer Operation identifier | Postfix Expression Inc Operations | Suffix Expression Dec operation

primary_expression→

IDENTIFIER

| CONSTANT

| String_literal

| ' (' expression ') '

Basic Expressions → identifiers | Constants | String Constants | ' (' expression ') '

Argument_expression_list

: assignment_expression

| Argument_expression_list ', ' assignment_expression

Parameter expression list: assignment Expression | Parameter expression list ', ' assignment expression

Unary_operator

: ' & '

| ‘*‘

| +

| ‘-‘

| ~

| ‘!‘

Unary operators: ' & ' | ' * ' | ' + ' | '-' | ' ~ ' | ‘!‘

assignment_operator→

=

| Mul_assign

| Div_assign

| Mod_assign

| Add_assign

| Sub_assign

| Left_assign

| Right_assign

| And_assign

| Xor_assign

| Or_assign

Assignment operator → ' = ' | Multiplication Allocation | div Assignment | MoD Assignment | Addition Assignment | Sub Assignment | Left Assignment | Right Assignment | and Distribution | XOR Distribution | or assign

storage_class_specifier→

TYPEDEF

| EXTERN

| STATIC

| AUTO

| REGISTER

Storage class descriptor → definition type | External variables | static | Automatic | 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 descriptor: struct or union identifier ' {' struct declaration list '} ' | struct or union ' {' struct declaration list '} ' | struct or Union identifier

Struct_or_union

: STRUCT

| UNION

Structure or union: Structure | Joint

Struct_declaration_list

: struct_declaration

| Struct_declaration_list struct_declaration

struct declaration list: struct declaration | struct declaration list of struct-body declarations

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 declaration: Descriptor qualifier list structure specifier '; ' Specifiers → type specifier specifier qualifier list | Type descriptor | Type qualifier specifier Qualifier List | Type qualifier

struct_declarator_list→

Struct_declarator

| Struct_declarator_list ', ' struct_declarator

struct descriptor list → Struct declaration | struct Descriptor list ', ' struct declaration

struct_declarator→

: declarator

| ': ' Constant_expression

| Declarator ': ' constant_expression

struct declaration →: declaration | ': ' Constant-expression | Declaration ': ' Constant expression

enum_specifier→

ENUM ' {' enumerator_list '} '

| ENUM IDENTIFIER ' {' enumerator_list '} '

| ENUM IDENTIFIER

Enum declaration → enum ' {' Enumerator list '} ' | Enum identifier ' {' Enumerator list '} ' | Enumeration identifiers

enumerator_list→

Enumerator

| Enumerator_list ', ' enumerator

Enumerator List → Enumerator | Enumerator list ', ' Enumerator

enumerator→

IDENTIFIER

| IDENTIFIER ' = ' constant_expression

Enumerator → identifiers | identifier ' = ' constant expression

type_qualifier→

CONST

| VOLATILE

Type Qualifiers → Constants | Easily lost.

type_qualifier_list→

Type_qualifier

| Type_qualifier_list Type_qualifier

Type qualifier list → type qualifier | Type Qualifier List Type qualifier

parameter_type_list→

Parameter_list

| Parameter_list ', ' ellipsis

parameter type list → parameter list | Parameter list ', ' ellipsis

parameter_list→

: parameter_declaration

| Parameter_list ', ' parameter_declaration

parameter list →: Declaration parameters | Parameter list ', ' declaring parameters

C Language Grammar

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.