文法分析

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

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

<翻译单位>:= {对外声明> } *      //函数的定义

<declaration-specifier> ::= <storage-class-specifier>            //类的定义
| <type-specifier>
| <type-qualifier>

<存储类说明符>::=“自动”      //四种存储类型,自动存储期和静态存储期,外部变量,定义类型
| "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>

<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>

posted @ 2015-10-29 11:36  22陈施恩  阅读(290)  评论(7编辑  收藏  举报