<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>WhiteSpace | 酷 壳 - CoolShell</title>
	<atom:link href="https://coolshell.cn/tag/whitespace/feed" rel="self" type="application/rss+xml" />
	<link>https://coolshell.cn</link>
	<description>享受编程和技术所带来的快乐 - Coding Your Ambition</description>
	<lastBuildDate>Tue, 12 Apr 2011 07:15:31 +0000</lastBuildDate>
	<language>zh-CN</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.2</generator>
	<item>
		<title>BT雷人的程序语言</title>
		<link>https://coolshell.cn/articles/1142.html</link>
					<comments>https://coolshell.cn/articles/1142.html#comments</comments>
		
		<dc:creator><![CDATA[陈皓]]></dc:creator>
		<pubDate>Sun, 12 Jul 2009 03:07:03 +0000</pubDate>
				<category><![CDATA[编程语言]]></category>
		<category><![CDATA[轶事趣闻]]></category>
		<category><![CDATA[brainfuck]]></category>
		<category><![CDATA[LOLCODE]]></category>
		<category><![CDATA[programming language]]></category>
		<category><![CDATA[WhiteSpace]]></category>
		<guid isPermaLink="false">http://coolshell.cn/?p=1142</guid>

					<description><![CDATA[<p>这个世界从来都不会缺少另类的东西，人类自然世界如此，计算机世界也一样。编程语言方面，看过本站《6个变态的C语言Hello World程序》的朋友们一定对BT和另...</p>
<p class="read-more"><a class="btn btn-default" href="https://coolshell.cn/articles/1142.html"> Read More<span class="screen-reader-text">  Read More</span></a></p>
The post <a href="https://coolshell.cn/articles/1142.html">BT雷人的程序语言</a> first appeared on <a href="https://coolshell.cn">酷 壳 - CoolShell</a>.]]></description>
										<content:encoded><![CDATA[<p><script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-3415450859608158"
     crossorigin="anonymous"></script>这个世界从来都不会缺少另类的东西，人类自然世界如此，计算机世界也一样。编程语言方面，看过本站《<a title="6个变态的C语言Hello World程序 - 661次点击" href="../?p=914">6个变态的C语言Hello World程序</a>》的朋友们一定对BT和另类不会陌生，但那都是些小儿科，真正的BT和另类要是从语言级上来完成。让我们来看看其中一个比较另类的语言BrainFuck。看到这个程序语言的名字，请不要以为这是一个搞笑的语言，这是一个“严肃事情”，请大家用“最虔诚的态度”来阅读本文。</p>
<h4>BF语言介绍</h4>
<p><strong>Brainfuck</strong>，是一种极小化的计算机语言，它是由Urban Müller在1993年创建的。由于“绿王八”的原因，这种语言有时被称为<strong>brainf**k</strong>或<strong>brainf***</strong>，甚至被简称为<strong>BF</strong>。这种 语言，是一种按照“Turing complete（完整图灵机）”思想设计的语言，它的主要设计思路是：用最小的概念实现一种“简单”的语言，BrainF**k 语言只有八种符号，所有的操作都由这八种符号的组合来完成。</p>
<p>BF基于一个简单的机器模型，除了八个指令，这个机器还包括：一个以字节为单位、被初始化为零的数组、一个指向该数组的指针(初始时指向数组的第一个字节)、以及用于输入输出的两个字节流。</p>
<p>下面是这八种指令的描述，其中每个指令由一个字符标识：</p>
<p><span id="more-1142"></span></p>
<table border="0">
<tbody>
<tr>
<th>字符</th>
<th>含义</th>
</tr>
<tr>
<td><code>&gt;</code></td>
<td>指针加一</td>
</tr>
<tr>
<td><code>&lt;</code></td>
<td>指针减一</td>
</tr>
<tr>
<td><code>+</code></td>
<td>指针指向的字节的值加一</td>
</tr>
<tr>
<td><code>-</code></td>
<td>指针指向的字节的值减一</td>
</tr>
<tr>
<td><code>.</code></td>
<td>输出指针指向的单元内容（ASCII码）</td>
</tr>
<tr>
<td><code>,</code></td>
<td>输入内容到指针指向的单元（ASCII码）</td>
</tr>
<tr>
<td><code>[</code></td>
<td>如果指针指向的单元值为零，向后跳转到对应的<code>]</code>指令的次一指令处</td>
</tr>
<tr>
<td><code>]</code></td>
<td>如果指针指向的单元值不为零，向前跳转到对应的<code>[</code>指令的次一指令处</td>
</tr>
</tbody>
</table>
<p>（按照更节省时间的简单说法，<code>]</code>也可以说成“向后跳转到对应的<code>[</code>状态”。这两解释是一样的。）</p>
<p>（第三种同价的说法，<code>[</code>意思是&#8221;向前跳转到对应的<code>]</code>&#8220;，<code>]</code>意思是&#8221;向后跳转到对应的<code>[</code>指令的次一指令处，如果指针指向的字节非零。&#8221;）</p>
<p>Brainfuck程序可以用下面的替换方法翻译成C语言（假设<code>ptr</code>是<code>char*</code>类型）：</p>
<table border="0">
<tbody>
<tr>
<th>Brainfuck</th>
<th>C</th>
</tr>
<tr>
<td align="center"><code>&gt;</code></td>
<td><code>++ptr;</code></td>
</tr>
<tr>
<td align="center"><code>&lt;</code></td>
<td><code>--ptr;</code></td>
</tr>
<tr>
<td align="center"><code>+</code></td>
<td><code>++*ptr;</code></td>
</tr>
<tr>
<td align="center"><code>-</code></td>
<td><code>--*ptr;</code></td>
</tr>
<tr>
<td align="center"><code>.</code></td>
<td><code>putchar(*ptr);</code></td>
</tr>
<tr>
<td align="center"><code>,</code></td>
<td><code>*ptr =getchar();</code></td>
</tr>
<tr>
<td align="center"><code>[</code></td>
<td><code>while (*ptr) {</code></td>
</tr>
<tr>
<td align="center"><code>]</code></td>
<td><code>}</code></td>
</tr>
</tbody>
</table>
<h4>BF解释器</h4>
<p>因为 BrainFuck 只有八种指令，并且没有关键字，也不允许自定义标识符，因此它的编译器实现起来非常简单，初学 C 语言不久的人都可以自己编出来，尽管在座的各位每人都可以自己编一个，不过为了引起大家的兴趣，我这里还是给出大家一个官方发布的版本。这个程序只有短短 50 多行，并且完全由 ANSI C 写成，因此你随便找个 C 语言编译器，把它编译一下。</p>
<pre data-enlighter-language="c" class="EnlighterJSRAW">
#include &lt;stdio.h&gt;;

int  p, r, q;
char a[5000], f[5000], b, o, *s=f;

void interpret(char *c)
{
    char *d;

    r++;
    while( *c ) {
        //if(strchr(&quot;&lt;&gt;;+-,.[]\n&quot;,*c))printf(&quot;%c&quot;,*c);
        switch(o=1,*c++) {
            case &#039;&lt;&#039;: p--;        break;
            case &#039;&gt;;&#039;: p++;       break;
            case &#039;+&#039;: a[p]++;     break;
            case &#039;-&#039;: a[p]--;     break;
            case &#039;.&#039;: putchar(a[p]); fflush(stdout); break;
            case &#039;,&#039;: a[p]=getchar();fflush(stdout); break;
            case &#039;[&#039;:
                for( b=1,d=c; b &amp;&amp; *c; c++ )
                b+=*c==&#039;[&#039;, b-=*c==&#039;]&#039;;
                if(!b) {
                    c[-1]=0;
                    while( a[p] )
                    interpret(d);
                    c[-1]=&#039;]&#039;;
                    break;
                }
            case &#039;]&#039;:
                puts(&quot;UNBALANCED BRACKETS&quot;), exit(0);
            case &#039;#&#039;:
                if(q&gt;;2)
                printf(&quot;%2d %2d %2d %2d %2d %2d %2d %2d %2d %2d\n%*s\n&quot;,
                *a,a[1],a[2],a[3],a[4],a[5],a[6],a[7],a[8],a[9],3*p+2,&quot;^&quot;);
                break;
            default: o=0;
        }
        if( p&lt;0 || p&gt;;100)
            puts(&quot;RANGE ERROR&quot;), exit(0);
    }
    r--;
    //        chkabort();
}

main(int argc,char *argv[])
{
    FILE *z;

    q=argc;

    if(z=fopen(argv[1],&quot;r&quot;)) {
        while( (b=getc(z))&gt;;0 )
            *s++=b;
        *s=0;
        interpret(f);
    }
}
</pre>
<p>当然，如果你觉得用C语言来实现BrainFuck语言的解释器是对BrainFuck这种语言的一种侮辱的话，我们的BrainFuck社区是绝对不能容忍你有这种想法的。因为我们有一个使用100%纯brainfuck写成的一个编译器<strong>awib</strong>：<a href="http://code.google.com/p/awib/" target="_blank">http://code.google.com/p/awib/ </a></p>
<h4>Hello World</h4>
<pre>++++++++++[&gt;+++++++&gt;++++++++++&gt;+++&gt;+&lt;&lt;&lt;&lt;-]
&gt;++.&gt;+.+++++++..+++.&gt;++.&lt;&lt;+++++++++++++++.
&gt;.+++.------.--------.&gt;+.&gt;.</pre>
<p>怎么？看不懂吗？下面是解释：</p>
<pre>+++ +++ +++ +           initialize counter (cell #0) to 10
[                       use loop to set the next four cells to 70/100/30/10
    &gt; +++ +++ +             add  7 to cell #1
    &gt; +++ +++ +++ +         add 10 to cell #2
    &gt; +++                   add  3 to cell #3
    &gt; +                     add  1 to cell #4
    &lt;&lt;&lt; &lt; -                 decrement counter (cell #0)
]
&gt;++ .                   print 'H'
&gt;+.                     print 'e'
+++ +++ +.              print 'l'
.                       print 'l'
+++ .                   print 'o'
&gt;++ .                   print ' '
&lt;&lt;+ +++ +++ +++ +++ ++. print 'W'
&gt;.                      print 'o'
+++ .                   print 'r'
--- --- .               print 'l'
--- --- --.             print 'd'
&gt;+.                     print '!'
&gt;.                      print '\n'</pre>
<p><strong>相关链接</strong>：</p>
<ul>
<li>BF的官网：<a href="http://www.muppetlabs.com/~breadbox/bf/">http://www.muppetlabs.com/~breadbox/bf/</a>。</li>
<li>BF的Wikipedia：<a href="http://en.wikipedia.org/wiki/Brainfuck">http://en.wikipedia.org/wiki/Brainfuck</a>。</li>
</ul>
<h4>其它另类语言</h4>
<p>如果你要觉得BF已经很BT了，那么你就错了，下面这些程序语言更BT。</p>
<p><strong>WhiteSpace语言</strong></p>
<p style="padding-left: 30px;">这是一种只用空白字符（空格，TAB和回车）编程的语言，而其它可见字符统统为注释。下面是它的一个示例：</p>
<p style="padding-left: 30px;">&nbsp;</p>
<pre style="padding-left: 60px;">  		 	
	
  	
  
	
</pre>
<p style="padding-left: 30px;">什么？你什么也没有看见，这就对了，因为这正是这门语言的独特之处。访问下面这个链接查看<a href="http://compsoc.dur.ac.uk/whitespace/hworld.ws" target="_blank">Hello,World示例</a>。记得按Ctrl+A来查看程序。</p>
<p style="padding-left: 30px;">官网：<a href="http://compsoc.dur.ac.uk/whitespace/index.php">http://compsoc.dur.ac.uk/whitespace/index.php</a>。</p>
<p><strong>LOLCODE语言</strong></p>
<p style="padding-left: 30px;">LOLCODE是一种建立在高度缩写的网络英语之上的编程语言，一般来说如果一个人能理解这种网络英语就能在未经训练的情况下读懂LOLCODE程序源代码。下面是其Hello,World例程：</p>
<pre style="padding-left: 60px;">HAI
CAN HAS STDIO?
VISIBLE "HAI WORLD!"
KTHXBYE</pre>
<p style="padding-left: 30px;">翻译成中文就是：</p>
<pre style="padding-left: 60px;">嗨
我可以用 STDIO 么？
显示一下 “HAI WORLD!”
谢谢啊，再见</pre>
<p style="padding-left: 30px;">&nbsp;</p>
<p style="padding-left: 30px;">官网：<a href="http://lolcode.com/">http://lolcode.com/</a></p>
<p><strong>中文编程语言</strong></p>
<p style="padding-left: 30px;">不要以为只有老外才那么BT，咱们中国也有自己的BT编程语言。</p>
<p style="padding-left: 30px;"><strong>中文Basic</strong></p>
<table border="0">
<tbody>
<tr>
<td>中文指令</td>
<td></td>
<td>对应于的Applesoft BASIC</td>
</tr>
<tr>
<td><tt>10 卜=0</tt></td>
<td></td>
<td><tt>10 Y=0</tt></td>
</tr>
<tr>
<td><tt>20 <span>入</span> 水, 火</tt></td>
<td></td>
<td><tt>20 INPUT E, F</tt></td>
</tr>
<tr>
<td><tt>30 <span>從</span> 日 = 水 <span>到</span> 火</tt></td>
<td></td>
<td><tt>30 FOR A = E TO F</tt></td>
</tr>
<tr>
<td><tt>40 卜 = 卜+<span>對數</span>(日)</tt></td>
<td></td>
<td><tt>40 Y = Y + LOG (A)</tt></td>
</tr>
<tr>
<td><tt>50 <span>下一</span> 日</tt></td>
<td></td>
<td><tt>50 NEXT A</tt></td>
</tr>
<tr>
<td><tt>60 <span>印</span> 卜</tt></td>
<td></td>
<td><tt>60 PRINT Y</tt></td>
</tr>
</tbody>
</table>
<p style="padding-left: 60px;">官网无法访问了，只能看看Wikipedia了：<a href="http://en.wikipedia.org/wiki/Chinese_BASIC">http://en.wikipedia.org/wiki/Chinese_BASIC</a></p>
<p style="padding-left: 30px;"><strong>中蟒语言（中文Python）</strong></p>
<p style="padding-left: 60px;">下面的程序是不是很Cool？</p>
<pre style="padding-left: 60px;">#!/usr/local/bin/cpython
回答 = 读入('你认为中文程式语言有存在价值吗 ? (有/没有)')
如 回答 == '有':
写 '好吧, 让我们一起努力!'
不然 回答 == '没有':
写 '好吧,中文并没有作为程式语言的价值.'
否则:
写 '请认真考虑后再回答.'</pre>
<p style="padding-left: 60px;">官网：<a href="http://www.chinesepython.org/cgi_bin/cgb.cgi/home.html">http://www.chinesepython.org/</a></p>
<p>差不多了，该结束了，再次说明，这是一篇很严肃的文章。</p>
<p>(<strong>全文完</strong>)<!--



<p align="center"><a href= target=_blank><img decoding="async" src=""></a></p>





<p align="center"><img decoding="async" src="https://coolshell.cn/wp-content/uploads/2020/03/coolshell.weixin.jpg"> <img decoding="async" loading="lazy" src="https://coolshell.cn/wp-content/uploads/2020/03/coolshell.mini_.jpg" width="300" height="300"> <br />关注CoolShell微信公众账号和微信小程序</p>

 

--></p>
<div style="margin-top: 15px; font-size: 16px;color: #cc0000;">
<p align="center"><strong>（转载本站文章请注明作者和出处 <a href="https://coolshell.cn/">酷 壳 &#8211; CoolShell</a> ，请勿用于任何商业用途）</strong></p>
</div>

<div class="wp_rp_wrap  wp_rp_vertical_m" id="wp_rp_first"><div class="wp_rp_content"><h3 class="related_post_title">相关文章</h3><ul class="related_post wp_rp"><li ><a href="https://coolshell.cn/articles/6639.html" class="wp_rp_thumbnail"><img src="https://coolshell.cn/wp-content/uploads/2012/02/programming-language-150x150.jpg" alt="千万别惹程序员 " width="150" height="150" /></a><a href="https://coolshell.cn/articles/6639.html" class="wp_rp_title">千万别惹程序员 </a></li><li ><a href="https://coolshell.cn/articles/4626.html" class="wp_rp_thumbnail"><img src="https://coolshell.cn/wp-content/plugins/wordpress-23-related-posts-plugin/static/thumbs/14.jpg" alt="读书笔记：对线程模型的批评" width="150" height="150" /></a><a href="https://coolshell.cn/articles/4626.html" class="wp_rp_title">读书笔记：对线程模型的批评</a></li><li ><a href="https://coolshell.cn/articles/4458.html" class="wp_rp_thumbnail"><img src="https://coolshell.cn/wp-content/plugins/wordpress-23-related-posts-plugin/static/thumbs/10.jpg" alt="BT雷人的程序语言（大全）" width="150" height="150" /></a><a href="https://coolshell.cn/articles/4458.html" class="wp_rp_title">BT雷人的程序语言（大全）</a></li><li ><a href="https://coolshell.cn/articles/3385.html" class="wp_rp_thumbnail"><img src="https://coolshell.cn/wp-content/uploads/2010/12/rank_scatter1-150x150.png" alt="编程语言流行度" width="150" height="150" /></a><a href="https://coolshell.cn/articles/3385.html" class="wp_rp_title">编程语言流行度</a></li><li ><a href="https://coolshell.cn/articles/3100.html" class="wp_rp_thumbnail"><img src="https://coolshell.cn/wp-content/uploads/2010/10/language-evolution-150x150.jpg" alt="编程语言进化" width="150" height="150" /></a><a href="https://coolshell.cn/articles/3100.html" class="wp_rp_title">编程语言进化</a></li><li ><a href="https://coolshell.cn/articles/2724.html" class="wp_rp_thumbnail"><img src="https://coolshell.cn/wp-content/uploads/2010/07/aboutprogramming04.eng_-150x150.jpg" alt="计算机编程简史图" width="150" height="150" /></a><a href="https://coolshell.cn/articles/2724.html" class="wp_rp_title">计算机编程简史图</a></li></ul></div></div>The post <a href="https://coolshell.cn/articles/1142.html">BT雷人的程序语言</a> first appeared on <a href="https://coolshell.cn">酷 壳 - CoolShell</a>.]]></content:encoded>
					
					<wfw:commentRss>https://coolshell.cn/articles/1142.html/feed</wfw:commentRss>
			<slash:comments>32</slash:comments>
		
		
			</item>
	</channel>
</rss>
