本人最近研究语言,并在.net上用C#测试实现。
我把这个语言框架命名为Story,
并希望它最总能够实如其名的理解人的部分语言。
向大家介绍一下目前进展。
世界你好程序:
Console.WriteLine "Hello world".
#这是注释#
解释运行,交互运行:
可以当作计算器:
>>>1+1
2
>>>5/10
0.5
基于.net内裤:
和.net交互,能够调用.net的类库。
包括你自己写.net的类。
>>>"abcdef".Substring(1)
bcdef
语法通俗,超通俗:
#他是一个学生#
he is a new student.
#他的名字是Jack#
he's name is "Jack".
动态语法和语义,只要告诉它某个语法代表什么语义:
#说某话将输出某话#
say(hi) will Console.WriteLine(hi)
#便可以用#
say "Hello world"
#输出 Hello world#
看起来像定义方法,其实不然:
还可以:
#某人说某话将输入某人的名字:说的话#
(sb)say(hi)will print sb's name +":"+hi
这样就可以用:
he say "Hello world!"
#输出:Jack:Hello world#
还可更夸张的定义语法:
#{花括号}表示文本,暂时的语法#
get a {type}will read string.Format("the {0} is a new {0}",type)
有了这个语法就可以:
get a student.
the student say "hello world".
这个意思就是,比如get a student 就会读 the student is a new student
读了the student is a new student它就明白的the student 是什么东西。
就可以直接用the student 说话了。
甚至可以用来定义sql语法:
select{attr}from(table)will dosomething.
希望大家都给个建议。