语法分析
<translation-unit> ::= {<external-declaration>}*
<external-declaration> ::= <function-definition> //外部声明
| <declaration>
<翻译单位>:= {对外声明> } * //函数的定义
<declaration-specifier> ::= <storage-class-specifier> //类的定义
| <type-specifier>
| <type-qualifier>
<存储类说明符>::=“自动” //存储说明符auto register static extern说明的四种存储类型,四种存储类别说明符有两种存储期:自动存储期和静态存储期
| "register"
| "static"
| "extern"
| "typedef"
<type-specifier> ::= "void" //类型说明符
| "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> "{" {<struct-declaration>}+ "}"
| <struct-or-union> <identifier>
<struct-or-union> ::= "struct" //结构体:共用体
| "union"
<struct-declaration> ::= {<specifier-qualifier>}* <struct-declarator-list>
<specifier-qualifier> ::= <type-specifier>
| <type-qualifier>
<struct-declarator-list> ::= <struct-declarator> //struct声明
| <struct-declarator-list> "," <struct-declarator>
<struct-declarator> ::= <declarator> //struct声明
| <declarator> ":" <constant-expression>
| ":" <constant-expression>
<declarator> ::= {<pointer>}? <direct-declarator> //说明
<pointer> ::= "*" {<type-qualifier>}* {<pointer>}? //指针
<type-qualifier> ::= "const" //const是一个C语言的关键字,它限定一个变量不允许被改变。
| "volatile"
<direct-declarator> ::= <identifier> //括号的用处
| "(" <declarator> ")"
| <direct-declarator> "[" {<constant-expression>}? "]"
| <direct-declarator> "(" <parameter-type-list> ")"
| <direct-declarator> "(" {<identifier>}* ")"
//以下是运算符的运用 与,或,异或运算,四则运算符(加减乘除求余),位运算
<constant-expression> ::= <conditional-expression>
<conditional-expression> ::= <logical-or-expression>
| <logical-or-expression> "?" <expression> ":" <conditional-expression>
<logical-or-expression> ::= <logical-and-expression>
| <logical-or-expression "||" <logical-and-expression>
<logical-and-expression> ::= <inclusive-or-expression>
| <logical-and-expression "&&" <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> "==" <relational-expression>
| <equality-expression> "!=" <relational-expression>
<relational-expression> ::= <shift-expression>
| <relational-expression> "<" <shift-expression>
| <relational-expression> ">" <shift-expression>
| <relational-expression> "<=" <shift-expression>
| <relational-expression> ">=" <shift-expression>
<shift-expression> ::= <additive-expression>
| <shift-expression> "<<" <additive-expression>
| <shift-expression> ">>" <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>
| "++" <unary-expression> //"自增"
| "--" <unary-expression> //"自减"
| <unary-operator> <cast-expression>
| "sizeof" <unary-expression> //动态分配空间
| "sizeof" <type-name>
<postfix-expression> ::= <primary-expression> //后缀表达式
| <postfix-expression> "[" <expression> "]"
| <postfix-expression> "(" {<assignment-expression>}* ")"
| <postfix-expression> "." <identifier>
| <postfix-expression> "->" <identifier>
| <postfix-expression> "++"
| <postfix-expression> "--"
<primary-expression> ::= <identifier> //前缀表达式
| <constant>
| <string>
| "(" <expression> ")"
<constant> ::= <integer-constant>
| <character-constant>
| <floating-constant>
| <enumeration-constant>
<expression> ::= <assignment-expression> //表达式
| <expression> "," <assignment-expression>
<assignment-expression> ::= <conditional-expression>
| <unary-expression> <assignment-operator> <assignment-expression>
<assignment-operator> ::= "=" //赋值运算符
| "*="
| "/="
| "%="
| "+="
| "-="
| "<<="
| ">>="
| "&="
| "^="
| "|="
<unary-operator> ::= "&" //一元运算符
| "*"
| "+"
| "-"
| "~"
| "!"
<type-name> ::= {<specifier-qualifier>}+ {<abstract-declarator>}? //定义一个变量的方法
<parameter-type-list> ::= <parameter-list> //函数参数类型分隔符列表
| <parameter-list> "," ...
<parameter-list> ::= <parameter-declaration>
| <parameter-list> "," <parameter-declaration>
<parameter-declaration> ::= {<declaration-specifier>}+ <declarator> //声明说明符
| {<declaration-specifier>}+ <abstract-declarator>
| {<declaration-specifier>}+
<abstract-declarator> ::= <pointer> //指针,直接摘要说明
| <pointer> <direct-abstract-declarator>
| <direct-abstract-declarator>
<direct-abstract-declarator> ::= ( <abstract-declarator> ) //直接声明符
| {<direct-abstract-declarator>}? "[" {<constant-expression>}? "]"
| {<direct-abstract-declarator>}? "(" {<parameter-type-list>|? ")"
<enum-specifier> ::= "enum" <identifier> "{" <enumerator-list> "}" //枚举声明符
| "enum" "{" <enumerator-list> "}"
| "enum" <identifier>
<enumerator-list> ::= <enumerator> //枚举类型列表
| <enumerator-list> "," <enumerator>
<enumerator> ::= <identifier> //枚举类型的定义的方法
| <identifier> "=" <constant-expression>
<typedef-name> ::= <identifier> //typedef 类型名
<declaration> ::= {<declaration-specifier>}+ {<init-declarator>}*
<init-declarator> ::= <declarator>
| <declarator> "=" <initializer>
<initializer> ::= <assignment-expression> //初始化
| "{" <initializer-list> "}" //初始化列表
| "{" <initializer-list> "," "}"
<initializer-list> ::= <initializer>
| <initializer-list> "," <initializer>
<compound-statement> ::= "{" {<declaration>}* {<statement>}* "}"
<statement> ::= <labeled-statement> //标记语句
| <expression-statement> //表达式语句
| <compound-statement> //复合语句
| <selection-statement> //选择语句
| <iteration-statement> //迭代语句
| <jump-statement> //跳转语句
<labeled-statement> ::= <identifier> ":" < statement> //switch用法
| "case" <constant-expression> ":" <statement>
| "default" ":" <statement>
<expression-statement> ::= {<expression>}? ";"
<selection-statement> ::= "if" "(" <expression> ")" <statement> //if-else 用法,以及嵌套
| "if" "(" <expression> ")" <statement> "else" <statement> //if---else
| "switch" "(" <expression> ")" <statement> //switch
<iteration-statement> ::= "while" "(" <expression> ")" <statement> //do-while用法
| "do" <statement> "while" "(" <expression> ")" ";"
| "for" "(" {<expression>}? ";" {<expression>}? ";" {<expression>}? ")" <statement>
<jump-statement> ::= "goto" <identifier> ";" //goto用法
| "continue" ";"
| "break" ";"
| "return" {<expression>}? ";"