CMM 语法分析文档
学号:200632580268 姓名:张成龙 班级 :06 级八班
一, CMM语言的文法说明:
program -> stmt-sequence //程序是由语句序列组成
stmt-sequence -> { statement } // 语句序列由多条语句组成
statement -> assign-stmt | write-stmt | read-stmt | if-stmt |
while-stmt | declaration | compound-stmt //单条语句有七种
assign-stmt -> identifier = exp ; //赋值语句
identifier -> ID [ ‘[‘ exp ‘]’ ] //标识符 包括单词和数组
wrie-stmt -> write exp ; //写语句
read-stmt -> read identifier ; //读语句
if-stmt -> if ‘ (‘ condition ‘)’ ( statement [ else statement ] | ; ) //if 语句
while-stmt -> while ‘(‘ condition ‘)’ ( statement | ; ) //while 语句
declaration -> type-specifier ID ( = exp | ∈ ) ; //声明 int 和 real 数字
declaration -> type-specifier ‘ [‘ exp ‘ ] ’ ID ; //申明数组
type-specifier -> int | real //类型
compound-stmt -> ‘ { ‘ stmt-sequence ‘ } ’ //复合语句 由单条语句复合而成
condition -> exp comparision-op exp //条件语句 在 while 和 if 语句中中构成判
断条件
comparision-op -> < | <= | > | >= | == | <>