【开源】超越 lua 的国产神语言,编译器仅仅92行!

roundsheep 2014-10-06 03:59:11
神语言是基于lua和RPP的新一代国产编程语言

为什么需要它?


1.很多人不喜欢lua的语法,神语言的语法更像C
2.神语言支持元编程、闭包、协程
3.凡是lua支持的特性神语言也支持,lua不支持的宏神语言也支持,因此神语言比lua强大
4.神语言可以使用lua库,甚至允许神语言和lua混合编程
5.神语言是最快的脚本语言之一,性能与C接近,因为神语言基于luaJIT
6.神语言的编译器只有92行代码,这是世界上最简单的编译器,即使是菜鸟也能看懂并修改
7.神语言完全开源,92行代码想不开源都不行


官网:https://github.com/roundsheep/god


神语言代码示例:


var f
f=function(a){
if(a<=1)
{
return 1
}
return f(a-1)*a
}
print(f(5))

var i=0
while(i<10)
{
print(i)
i++
}

for(i=1,10)
{
print(i)
}

var b=['abc','123',test=111]
print(b[1])
print(b.test)
print(b['test'])
...全文
891 20 打赏 收藏 转发到动态 举报
写回复
用AI写文章
20 条回复
切换为时间正序
请发表友善的回复…
发表回复
nini302 2016-12-23
  • 打赏
  • 举报
回复
都是牛人,大神
  • 打赏
  • 举报
回复
未来数年之后 神语言 神经语言 神马语言将占领整个地球
赵4老师 2014-10-08
  • 打赏
  • 举报
回复
强脚的花 2014-10-08
  • 打赏
  • 举报
回复
哈哈,好厉害的样子
roundsheep 2014-10-08
  • 打赏
  • 举报
回复
神语言项目组推出新计划,设计一个基于模式匹配和宏的新语言,目前暂定名字为 鸟语(The Bird Language),敬请期待。
li4c 2014-10-08
  • 打赏
  • 举报
回复
不明觉利,膜拜
max_min_ 2014-10-08
  • 打赏
  • 举报
回复
幻夢之葉 2014-10-08
  • 打赏
  • 举报
回复
完全不明白92行怎么算出来的。
帅得不敢出门 2014-10-08
  • 打赏
  • 举报
回复
简单就说原理
Saleayas 2014-10-08
  • 打赏
  • 举报
回复
你可曾听说 C/C++ 超越过谁吗? 当你说超越的时候,你已经把你自己拉低了。
phommy 2014-10-08
  • 打赏
  • 举报
回复
[code=神语言]源码打不开。。既然只有92行能不能复制过来。。。[/code]
roundsheep 2014-10-08
  • 打赏
  • 举报
回复
神语言写的控制台贪食蛇:




ffi=require('ffi')

ffi.cdef[
#pragma pack(1)
typedef struct
{
int dwSize;
int bVisible;
}CONSOLE_CURSOR_INFO;
int SetConsoleCursorInfo(int hConsoleOutput,
CONSOLE_CURSOR_INFO* lpConsoleCursorInfo);
int system(const char* s);
typedef struct
{
unsigned short x;
unsigned short y;
}COORD;
int SetConsoleCursorPosition(int hConsoleOutput,
COORD dwCursorPosition);
int GetStdHandle(int nStdHandle);
int printf(const char* fmt,...);
typedef unsigned short ushort;
int SetConsoleTextAttribute(int h,ushort w);
short GetAsyncKeyState(int vkey);
int GetTickCount();
]

clear=function(v)
{
var i
for(i=1,table.maxn(v))
{
v[i]=null
}
}

exist=function(v,a)
{
var i
for(i=1,table.maxn(v))
{
if(v[i]==a)
{
return true
}
}
return false
}

push=function(v,a)
{
v[table.maxn(v)+1]=a
}

push_front=function(v,a)
{
var count=#v
var i
for(i=count,1,-1)
{
v[i+1]=v[i]
}
v[1]=a
}

food=function()
{
//todo : array index unusual
g_food=math.modf(math.random()*10000)%200
if(exist(g_arr,g_food))
{
food()
}
}

update=function()
{
var i
for(i=1,200)
{
gotoxy(i%10*2,math.modf(i/10))
if(exist(g_arr,i))
{
out('■')
}
elif(i==g_food)
{
out('★')
}
else
{
out(' ')
}
}
}

gotoxy=function(x,y)
{
var pos=ffi.new('COORD',[])
pos.x=x
pos.y=y
ffi.C.SetConsoleCursorPosition(g_std_out,pos)
}

out=function(s)
{
ffi.C.printf(s)
}

init=function()
{
math.randomseed(os.time())
g_std_out=ffi.C.GetStdHandle(-11)
g_next=10
clear(g_arr)
push(g_arr,105)
food()
var cur_info=ffi.new('CONSOLE_CURSOR_INFO',[])
cur_info.dwSize=1
cur_info.bVisible=0
ffi.C.SetConsoleCursorInfo(g_std_out,cur_info)
ffi.C.system('mode con cols=20 lines=22')
ffi.C.SetConsoleTextAttribute(g_std_out,0x0a)
gotoxy(0,20)
out(' ******************')
}

key=function()
{
var temp
if(ffi.C.GetAsyncKeyState(0x26)!=0)
{
temp=-10
}
elif(ffi.C.GetAsyncKeyState(0x28)!=0)
{
temp=10
}
elif(ffi.C.GetAsyncKeyState(0x25)!=0)
{
temp=-1
}
elif(ffi.C.GetAsyncKeyState(0x27)!=0)
{
temp=1
}
else
{
return
}
if(table.maxn(g_arr)<2||g_arr[2]!=g_arr[1]+temp)
{
g_next=temp
}
}

check=function()
{
var temp=g_arr[1]+g_next
if(temp<1||temp>200||math.abs(temp%10-g_arr[1]%10)>1||exist(g_arr,temp))
{
return false
}
return true
}

g_arr=[]
init()
var start=ffi.C.GetTickCount()
while(true)
{
key()
if(ffi.C.GetTickCount()-start<100)
{
goto continue
}
start=ffi.C.GetTickCount()
if(!check())
{
break
}
push_front(g_arr,g_arr[1]+g_next)
if(g_food!=g_arr[1])
{
g_arr[#g_arr]=null
}
else
{
food()
}
update()
::continue::
}
  • 打赏
  • 举报
回复
roundsheep 2014-10-06
  • 打赏
  • 举报
回复
其实我还写了另一个叫 神经语言,目前计划开发一个新的 神马语言,敬请期待。
LostOmato 2014-10-06
  • 打赏
  • 举报
回复
新手不明觉厉
百曉生 2014-10-06
  • 打赏
  • 举报
回复
引用 3 楼 lovesmiles 的回复:
编译器92行代码 哥也是醉了,要是没有这些广告词还想看一下,加了这些吹牛b的话,那就有空再看吧。
有意思,我是来看回复的
勤奋的小游侠 2014-10-06
  • 打赏
  • 举报
回复
编译器92行代码 哥也是醉了,要是没有这些广告词还想看一下,加了这些吹牛b的话,那就有空再看吧。
FancyMouse 2014-10-06
  • 打赏
  • 举报
回复
调用外部程序也是喷了。不过比那个riwei肯动手,也是值得鼓励。
  • 打赏
  • 举报
回复

64,282

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧