C Language Grammar

Source: Internet
Author: User
Tags goto

<translation-unit>:: = {<external-declaration>}*

<external-declaration>:: = <function-definition>
| <declaration>

< translation Unit >:= {External declaration >} *//Definition of function

<declaration-specifier>:: = <storage-class-specifier> //Definition of class
| <type-specifier>
| <type-qualifier>

< storage class Descriptor >::= "Automatic"//storage specifier auto Register static extern description of four storage types, four storage class specifiers have two storage periods: automatic storage period and static storage period
| "Register"
| "Static"
| "extern"
| "typedef"

<type-specifier>:: = "void"//type specifier
| "Char"
| "Short"
| "Int"
| "Long"
| "Float"
| "Double"
| "Signed"
| "Unsigned"
| <struct-or-union-specifier>
| <enum-specifier>
| <typedef-name>

<struct-or-union-specifier>:: = <struct-or-union><identifier> "{" {<struct-declaration>}+ " }"//struct or union specifier
| <struct-or-union> "{" {<struct-declaration>}+ "}"
| <struct-or-union> <identifier>

<struct-or-union>:: = "struct"//structure, common body
| "Union"

<struct-declaration>:: = {<specifier-qualifier>}*<struct-declarator-list>//Structure declaration

<specifier-qualifier>:: = <type-specifier>//qualified type specifier
| <type-qualifier>

<struct-declarator-list>:: = <struct-declarator>//struct Statement
| <struct-declarator-list> "," <struct-declarator>

<struct-declarator>:: = <declarator>//struct Statement
| <declarator> ":" <constant-expression>
| ":" <constant-expression>

<declarator>:: = {<pointer>}? <direct-declarator>//Description

<pointer>:: = "*" {<type-qualifier>}* {<pointer>}?//Hands

<type-qualifier>:: = "Const" //const is a c keyword, and he restricts a variable to be allowed to be changed
| "Volatile"

<direct-declarator>:: = <identifier>//Direct declaration, identifier
| "(" <declarator> ")"
| <direct-declarator> "[" {<constant-expression>}? "]"
| <direct-declarator> "(" <parameter-type-list> ")"
| <direct-declarator> "(" {<identifier>}* ")"

<constant-expression>:: = <conditional-expression>//Common expressions, conditional expressions

<conditional-expression>:: = <logical-or-expression>//Three-bit operators
| <logical-or-expression> "?" <expression> ":" <conditional-expression>

<logical-or-expression>:: = <logical-and-expression>//"or"
| <logical-or-expression "| |" <logical-and-expression>

<logical-and-expression>:: = <inclusive-or-expression>//"and"
| <logical-and-expression "&&" <inclusive-or-expression>

<inclusive-or-expression>:: = <exclusive-or-expression>//"or"
| <inclusive-or-expression> "|" <exclusive-or-expression>

<exclusive-or-expression>:: = <and-expression> //"XOR"
| <exclusive-or-expression> "^" <and-expression>

<and-expression>:: = <equality-expression> //"and"
| <and-expression> "&" <equality-expression>

<equality-expression>:: = <relational-expression>
| <equality-expression> "= =" <relational-expression>//"Take value"
| <equality-expression> "! =" <relational-expression>//"Not equal to"

<relational-expression>:: = <shift-expression>
| <relational-expression> "<" <shift-expression>//"Greater than"
| <relational-expression> ">" <shift-expression>//"less than"
| <relational-expression> "<=" <shift-expression>//"Less than equals"
| <relational-expression> ">=" <shift-expression>//"greater than equals"

<shift-expression>:: = <additive-expression>//"bitwise operator"
| <shift-expression> "<<" <additive-expression>
| <shift-expression> ">>" <additive-expression>

<multiplicative-expression>:: = <cast-expression>//"' *,/,% ' operator"
| <multiplicative-expression> "*" <cast-expression>
| <multiplicative-expression> "/" <cast-expression>
| <multiplicative-expression> "%" <cast-expression>

<cast-expression>:: = <unary-expression>//Unary operators
| "(" <type-name> ")" <cast-expression>

<unary-expression>:: = <postfix-expression>
| "+ +" <unary-expression>//"self-increment"
| "--" <unary-expression>//"self-reduction"
| <unary-operator> <cast-expression>
| "sizeof" <unary-expression>//Dynamic allocation of space
| "sizeof" <type-name>

<postfix-expression>:: = <primary-expression>//suffix expression
| <postfix-expression> "[" <expression> "]"
| <postfix-expression> "(" {<assignment-expression>}* ")"
| <postfix-expression> "." <identifier>
| <postfix-expression>, <identifier>
| <postfix-expression> "+ +"
| <postfix-expression> "--"

<primary-expression>:: = <identifier>//Prefix expression
| <constant>
| <string>
| "(" <expression> ")"

<constant>:: = <integer-constant>//integral type constant
| <character-constant>//Character Constants
| <floating-constant>//floating-point constants
| <enumeration-constant>//Enumeration Constants

<expression>:: = <assignment-expression>//Assignment Expression
| <expression> "," <assignment-expression>

<assignment-expression>:: = <conditional-expression> //Assignment expression
| <unary-expression> <assignment-operator><assignment-expression>

<assignment-operator>:: = "="//Assignment operator
| "*="
| "/="
| "%="
| "+="
| "-="
| "<<="
| ">>="
| "&="
| "^="
| "|="

<unary-operator>:: = "&"//Unary operators
| "*"
| "+"
| "-"
| "~"
| "!"

<type-name>:: = {<specifier-qualifier>}+{<abstract-declarator>}?//Modifier

<parameter-type-list>:: = <parameter-list>//Parameter type list
| <parameter-list> "," ...

<parameter-list>:: = <parameter-declaration>//Parameter declaration
| <parameter-list> "," <parameter-declaration>

<parameter-declaration>:: = {<declaration-specifier>}+<declarator>//Declaration specifier
| {<declaration-specifier>}+ <abstract-declarator>
| {<declaration-specifier>}+

<abstract-declarator>:: = <pointer>//pointers, Direct Summary description
| <pointer> <direct-abstract-declarator>
| <direct-abstract-declarator>

<direct-abstract-declarator>:: = (<abstract-declarator>)//Direct declarator
| {<direct-abstract-declarator>}? "[" {<constant-expression>}? "]"
| {<direct-abstract-declarator>}? "(" {<parameter-type-list>|? ")"

<enum-specifier>:: = "enum" <identifier> "{" <enumerator-list> "}"//Enumeration declarator
| "Enum" "{" <enumerator-list> "}"
| "Enum" <identifier>

<enumerator-list>:: = <enumerator>//Enumerator
| <enumerator-list> "," <enumerator>

<enumerator>:: = <identifier>//Enumeration identifier
| <identifier> "=" <constant-expression>

<typedef-name>:: = <identifier>//Identifiers

<declaration>:: = {<declaration-specifier>}+ {<init-declarator>}*//Declaration specifier, initializing

<init-declarator>:: = <declarator>//Initialize declarator
| <declarator> "=" <initializer>

<initializer>:: = <assignment-expression>//Initialize
| "{" <initializer-list> "}"
| "{" <initializer-list> "," "}"

<initializer-list>:: = <initializer>//Initialization list
| <initializer-list> "," <initializer>

<compound-statement>:: = "{" {<declaration>}*{<statement>}* "}"//Compound statement

<statement>:: = <labeled-statement>//Tag statement

| <expression-statement>//Expression Statements
| <compound-statement>//Compound statement
| <selection-statement>//SELECT statement
| <iteration-statement>//Iteration Statements
| <jump-statement>//Jump statement

<labeled-statement>:: = <identifier> ":" <statement>//Tag statement, identifier
| "Case" <constant-expression> ":" <statement>
| "Default" ":" <statement>

<expression-statement>:: = {<expression>}? ";"//Expression Statements

<selection-statement>:: = "If" "(" <expression> ")" <statement>//SELECT statement
| "If" ("<expression>") "<statement> Else" <statement>//if---else
| "Switch" ("<expression>") "<statement>//switch

<iteration-statement>:: = "while" ("<expression>") "<statement>//while Loop statement do while,for
| "Do" <statement> "while" ("<expression>") "";
| "For" "(" {<expression>}? ";" {<expression>}? ";" {<expression>}? ")" <statement>

<jump-statement>:: = "goto" <identifier> ";"//goto Jump Statement Continue,break,return
| "Continue" ";"
| "Break" ";"
| "Return" {<expression>}? ";"

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.