声振论坛

 找回密码
 我要加入

QQ登录

只需一步,快速开始

查看: 4503|回复: 4

[其他相关] BrainFuck语言

[复制链接]
发表于 2010-12-6 09:16 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?我要加入

x
本帖最后由 wqsong 于 2010-12-6 19:15 编辑

在上一个帖子里面说到了BrainFuck,BrainFuck就是一个最小化的图灵机抽象,语法简单,发明者是Urban Müller。这里简单介绍一下,增加对编程的兴趣,也可以简单了解一下解释性语言解释器是什么样子,大家可以用自己擅长的语言写一个,练习一下。


语法很简单,只有8中运算符:
> Increment the pointer.
< Decrement the pointer.
+ Increment the byte at the pointer.
- Decrement the byte at the pointer.
. Output the byte at the pointer.
, Input a byte and store it in the byte at the pointer.
[ Jump forward past the matching ] if the byte at the pointer is zero.
] Jump backward to the matching [ unless the byte at the pointer is zero.

与C中运算符比较一下就明白了:
> becomes ++p;
< becomes --p;
+ becomes ++*p;
- becomes --*p;
. becomes putchar(*p);
, becomes *p = getchar();
[ becomes while (*p) {
] becomes }

这是Hello World!程序
>+++++++++[<++++++++>-]<.>+++++++[<++++>-]<+.+++++++..+++.[-]>++++++++[<++++>-]<.#>+++++++++++[<+++++>-]<.>++++++++[<+++>-]<.+++.------.--------.[-]>++++++++[<++++>-]<+.[-]++++++++++.
下面这个打印字符串keke he yaoyao!,我的两个好朋友。
>>>++++++++[<+++++++++++++<+++++++++++++>>-]<<
+++.>---.<.>.
>>++++[<++++++++>-].
>>>++++++++[<+++++++++++++<+++++++++++++>>-]<---<.>.
>>++++[<++++++++>-].
>>+++++++++++[<+++++++++++>-]<.
>>++++++++++++[<++++++++>-]<+.
>>++++++++++[<+++++++++++>-]<+.
<<.>.>.
>>+++++[<++++++>-]<+++.

下面其中一个附件是我写的一个解释器,可自动扩展内存。
bf2.rar (1.65 KB, 下载次数: 3, 售价: 20 点体能)
bf.rar (81.75 KB, 下载次数: 14)

评分

1

查看全部评分

回复
分享到:

使用道具 举报

发表于 2010-12-6 14:35 | 显示全部楼层
本帖最后由 Rainyboy 于 2010-12-6 14:35 编辑

这个帖子让我想起了这些:

6个变态的C语言HelloWorld程序
http://coolshell.cn/articles/914.html
编程真难啊!
http://coolshell.cn/articles/1391.html

看之前:

看之后:


点评

赞成: 5.0
赞成: 5
是够邪恶的。。。哈哈。。。  发表于 2010-12-6 19:14
发表于 2010-12-11 15:28 | 显示全部楼层
这.....,活着真累

点评

赞成: 5.0
赞成: 5
是啊,哈哈 简单的事情弄复杂。。。不过简单了解一下虚拟机。。。  发表于 2010-12-12 18:59
发表于 2012-6-24 22:30 | 显示全部楼层
这语言名字碉堡了。
发表于 2012-6-27 14:59 | 显示全部楼层
好有趣的语言
您需要登录后才可以回帖 登录 | 我要加入

本版积分规则

QQ|小黑屋|Archiver|手机版|联系我们|声振论坛

GMT+8, 2024-4-26 00:34 , Processed in 0.156147 second(s), 24 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表