在上一个帖子里面说到了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] |
GMT+8, 2024-11-24 18:49 , Processed in 0.030499 second(s), 15 queries , Gzip On.
Powered by Discuz! X3.4
Copyright © 2001-2021, Tencent Cloud.