Brainfuck Compiler on PHP
A PHP implement for Brainfuck Compiler
<?php /** Brainfuck Compiler on PHP
Copyright 2015 Everstray Jun Sinri Edogawa **/ $bc=new BrainfuckCompiler(); $bc->compile( '++++++++++[>+++++++>++++++++++>+++>+++.>+.+++++++..+++.>++..+++.------.--------.>+.>.' ); /** 字符 含义 > 指针加一 '; public static $PTR_LEFT ='0,0=>0,1=>0); private $codes=array(); private $code_index=0; public function compile($program_code){ $this->codes=str_split($program_code); $this->code_index=0; while($this->code_index<count>codes)){ $this->process_code(); } } private function process_code(){ if(BrainfuckCompiler::$DEBUG_MODE){ echo "[DEBUG] process_code at ".$this->code_index; } $code=$this->codes[$this->code_index]; if(BrainfuckCompiler::$DEBUG_MODE){ echo " as ".$code.PHP_EOL; } if($code===BrainfuckCompiler::$PTR_RIGHT){ $this->act_ptr_right(); $this->code_index+=1; } elseif($code===BrainfuckCompiler::$PTR_LEFT){ $this->act_ptr_left(); $this->code_index+=1; } elseif($code===BrainfuckCompiler::$VAL_PLUS){ $this->act_val_plus(); $this->code_index+=1; } elseif($code===BrainfuckCompiler::$VAL_MINUS){ $this->act_val_minus(); $this->code_index+=1; } elseif($code===BrainfuckCompiler::$PTR_OUTPUT){ $this->act_ptr_output(); $this->code_index+=1; } elseif($code===BrainfuckCompiler::$PTR_INPUT){ $this->act_ptr_input($this->codes[$this->code_index+1]); $this->code_index+=2; } elseif($code===BrainfuckCompiler::$WHILE_BEGIN){ $this->act_while_begin(); } elseif($code===BrainfuckCompiler::$WHILE_END){ $this->act_while_end(); } } private function act_ptr_right(){ $this->ptr+=1; if(!isset($this->memory[$this->ptr])){ $this->memory[$this->ptr]=0; } } private function act_ptr_left(){ $this->ptr-=1; if(!isset($this->memory[$this->ptr])){ $this->memory[$this->ptr]=0; } } private function act_val_plus(){ $this->memory[$this->ptr]=($this->memory[$this->ptr]+1)%256; } private function act_val_minus(){ $this->memory[$this->ptr]=($this->memory[$this->ptr]-1)%256; } private function act_ptr_output(){ echo chr($this->memory[$this->ptr]); } private function act_ptr_input($value){ $this->memory[$this->ptr]=($value%256); } private function act_while_begin(){ if($this->memory[$this->ptr]===0){ //find the pair WHILE_END $pair=1; $i=0; for($i=$this->code_index+1;$i<count>codes);$i++){ if($this->codes[$i]===BrainfuckCompiler::$WHILE_BEGIN){ $pair+=1; }elseif($this->codes[$i]===BrainfuckCompiler::$WHILE_END){ $pair-=1; } if($pair==0){ //here it is break; } } $this->code_index=$i; }else{ $this->code_index+=1; } } private function act_while_end(){ if($this->memory[$this->ptr]!==0){ //find the pair WHILE_BEGIN $pair=1; $i=0; for($i=$this->code_index-1;$i>=0;$i--){ if($this->codes[$i]===BrainfuckCompiler::$WHILE_END){ $pair+=1; }elseif($this->codes[$i]===BrainfuckCompiler::$WHILE_BEGIN){ $pair-=1; } if($pair==0){ //here it is break; } } $this->code_index=$i+1; }else{ $this->code_index+=1; } } } ?></count></count>
版权声明:本文为博主原创文章,未经博主允许不得转载。
以上就介绍了Brainfuck Compiler on PHP,包括了方面的内容,希望对PHP教程有兴趣的朋友有所帮助。

热AI工具

Undresser.AI Undress
人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover
用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

AI Hentai Generator
免费生成ai无尽的。

热门文章

热工具

记事本++7.3.1
好用且免费的代码编辑器

SublimeText3汉化版
中文版,非常好用

禅工作室 13.0.1
功能强大的PHP集成开发环境

Dreamweaver CS6
视觉化网页开发工具

SublimeText3 Mac版
神级代码编辑软件(SublimeText3)

许多用户在选择智能手表的时候都会选择的华为的品牌,其中华为GT3pro和GT4都是非常热门的选择,不少用户都很好奇华为GT3pro和GT4有什么区别,下面就就给大家介绍一下二者。华为GT3pro和GT4有什么区别一、外观GT4:46mm和41mm,材质是玻璃表镜+不锈钢机身+高分纤维后壳。GT3pro:46.6mm和42.9mm,材质是蓝宝石玻璃表镜+钛金属机身/陶瓷机身+陶瓷后壳二、健康GT4:采用最新的华为Truseen5.5+算法,结果会更加的精准。GT3pro:多了ECG心电图和血管及安

为什么截图工具在Windows11上不起作用了解问题的根本原因有助于找到正确的解决方案。以下是截图工具可能无法正常工作的主要原因:对焦助手已打开:这可以防止截图工具打开。应用程序损坏:如果截图工具在启动时崩溃,则可能已损坏。过时的图形驱动程序:不兼容的驱动程序可能会干扰截图工具。来自其他应用程序的干扰:其他正在运行的应用程序可能与截图工具冲突。证书已过期:升级过程中的错误可能会导致此issu简单的解决方案这些适合大多数用户,不需要任何特殊的技术知识。1.更新窗口和Microsoft应用商店应用程

第1部分:初始故障排除步骤检查苹果的系统状态:在深入研究复杂的解决方案之前,让我们从基础知识开始。问题可能不在于您的设备;苹果的服务器可能会关闭。访问Apple的系统状态页面,查看AppStore是否正常工作。如果有问题,您所能做的就是等待Apple修复它。检查您的互联网连接:确保您拥有稳定的互联网连接,因为“无法连接到AppStore”问题有时可归因于连接不良。尝试在Wi-Fi和移动数据之间切换或重置网络设置(“常规”>“重置”>“重置网络设置”>设置)。更新您的iOS版本:

php提交表单通过后,弹出的对话框怎样在当前页弹出php提交表单通过后,弹出的对话框怎样在当前页弹出而不是在空白页弹出?想实现这样的效果:而不是空白页弹出:------解决方案--------------------如果你的验证用PHP在后端,那么就用Ajax;仅供参考:HTML code

Microsoft发布了VisualStudioCode的Unity扩展预览版。这个新的Unity扩展将允许您编写和调试Unity游戏。这个新的Unity扩展带来了VisualStudio和VisualStudioToolsforUnity上已经提供的一些流行功能,使VisualStudioCode中的C#更好地进行Unity开发。目前,适用于VSCode的Unity扩展提供以下内容:一个Unity调试器,用于调试您的Unity编辑器和Unity播放器。特定于Unity的C#分析器和重构。Uni

watch4pro和gt各自具有不用的特点和适用场景,如果注重功能的全面性、高性能和时尚外观,同时愿意承担较高的价格,那么Watch 4 Pro可能更适合。如果对功能要求不高,更注重电池续航和价格的合理性,那么GT系列可能更适合。最终的选择应根据个人需求、预算和喜好来决定,建议在购买前仔细考虑自己的需求,并参考各种产品的评测和比较,以做出更明智的选择。

如何使用iPadOS17.4优化iPad电池寿命延长电池续航时间是移动设备体验的关键,iPad是一个很好的例子。如果您觉得iPad电池消耗速度过快,不用担心,在iPadOS17.4中有许多技巧和调整可以显着延长设备的运行时间。本深入指南的目标不仅仅是提供信息,而是改变您使用iPad的方式,增强您的整体电池管理,并确保您可以在无需充电的情况下更长时间地依赖您的设备。通过采用此处概述的做法,您朝着更高效、更谨慎地使用技术迈出了一步,这些技术是根据您的个人需求和使用模式量身定制的。识别主要的能量消耗者

同事因为this指向的问题卡住的bug,vue2的this指向问题,使用了箭头函数,导致拿不到对应的props。当我给他介绍的时候他竟然不知道,随后也刻意的看了一下前端交流群,至今最起码还有70%以上的前端程序员搞不明白,今天给大家分享一下this指向,如果啥都没学会,请给我一个大嘴巴子。
