Cool语言的词法结构

来源:互联网 发布:澳客体彩软件 编辑:程序博客网 时间:2024/06/05 12:56

cool语言的词法单元有:整数、类型标识符、对象标识符、特殊语法符号、字符串、关键字和空白符

cool语言的整数:0-9组成的非空串

cool语言的标识符由数字、字母和下划线组成,类型标识符以大写字母开头,对象标识符以小写字母开头,还有两个特殊的标识符(但不是关键字)self和SELF_TYPE

cool语言的字符串:位于双引号""中间,换行用斜杠/,‘\c’代表字符'c',\b backspace,\t tab,\n newline,\f formfeed

cool语言的注释:--(相对于C语言的//)或(*…*)相对于C语言的/*…*/

cool语言的关键字有:: class, else, false, fi, if, in, inherits, isvoid, let, loop, pool, then, while,case, esac, new, of, not, true.

cool语言的空白符有:blank,\n,\r,\t,\f,\v

program ::= [[class; ]]+

class ::= class TYPE [inherits TYPE] { [[feature; ]]∗}
feature ::= ID( [ formal [[, formal]]∗] ) : TYPE { expr }
| ID : TYPE [ <- expr ]
formal ::= ID : TYPE
expr ::= ID <- expr
| expr[@TYPE].ID( [ expr [[,expr]]∗] )
| ID( [ expr [[,expr]]∗] )
| if expr then expr else expr fi
| while expr loop expr pool
| { [[expr; ]]+}
| let ID : TYPE [ <- expr ] [[,ID : TYPE [ <- expr ]]]∗in expr
| case expr of [[ID : TYPE => expr; ]]+esac
| new TYPE
| isvoid expr
| expr + expr
| expr − expr
| expr ∗ expr
| expr/expr
| ˜expr
| expr < expr
| expr <= expr
| expr = expr
| not expr
| (expr)
| ID
| integer
| string
| true
| false
原创粉丝点击