首页 > 代码库 > 简单文法(以c语言为例)
简单文法(以c语言为例)
<program> :
external_declaration
| program external_declaration
<external_declaration> : //外部声明
function_definition
| declaration
<function_definition> : //函数
type_specifier declarator //说明符
compound_statement //混合声明
<declaration>: //声明
Symbol //符号 identifier ‘<’ identifier ‘>’ declaration
|type_specifier variate ‘;’ declaration
|identifier ‘{’ body ‘}’
<body> : //函数主体
type_specifier variate ‘;’
|initializer //初始化
<initializer> : //初始化
variate Initializer
|Symbol Initializer
<type_specifier> : //类型
Void
|char
|int
|float
|double
<identifier> : //标识符 头文件
Include
| define
|stdio.h
|math.h
|stdlib.h
|time.h
|string.h
|main ‘(‘ ‘)’
<statement> : //声明、陈述
udge_statement
|jump_statement
|iteration_statement
|selection_statement
<Judge_statement> : //判断
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 ‘(’ ’)’ ’;’
<Symbol > : //符号
#
|+
|=
|-
|:
|,
<bracket> : //括号
(
|)
|{
|}
<Pointer > : //指针
‘*‘
| ‘*‘ variate //变量
<variate >: //变量
a variate
|b variate
|c variate
|.....
|z variate
简单文法(以c语言为例)