声振论坛

 找回密码
 我要加入

QQ登录

只需一步,快速开始

声振论坛 展示 基础理论 查看内容

BrainFuck语言简介

2011-3-18 16:19| 发布者: 雪缘| 查看: 981| 评论: 0|来自: 振动论坛

摘要: 在上一个帖子里面说到了BrainFuck,BrainFuck就是一个最小化的图灵机抽象,语法简单,发明者是Urban Müller。这里简单介绍一下,增加对编程的兴趣,也可以简单了解一下解释性语言解释器是什么样子,大家可以用自己擅 ...
在上一个帖子里面说到了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!,我的两个好朋友。
>>>++++++++[<+++++++++++++<+++++++++++++>>-]<<
+++.>---.<.>.
>>++++[<++++++++>-].
>>>++++++++[<+++++++++++++<+++++++++++++>>-]<---<.>.
>>++++[<++++++++>-].
>>+++++++++++[<+++++++++++>-]<.
>>++++++++++++[<++++++++>-]<+.
>>++++++++++[<+++++++++++>-]<+.
<<.>.>.
>>+++++[<++++++>-]<+++.

下面其中一个附件是我写的一个解释器,可自动扩展内存。
[attach]48157[/attach]
[attach]48156[/attach]

本文内容由 wqsong 提供

最新评论

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

GMT+8, 2024-5-20 10:51 , Processed in 0.076170 second(s), 15 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

返回顶部