Skip to content

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
West London Hack Night - Reworked Brainfuck interpreter in C#
namespace BrainFuckContinued
{
using System;
using System.Collections.Generic;
class Program
{
static void Main(string[] args)
{
var p = "++++++++++[>+++++++>++++++++++>+++>+<<<<-]>++.>+.+++++++..+++.>++.<<+++++++++++++++.>.+++.------.--------.>+.>.";
int ip=-1,dp=0;var f=false;var d=new char[30000];var s=new Stack<int>();
var u=new Dictionary<char,Action>{
{'>',()=>dp++},{'<',()=>dp--},{'+',()=>d[dp]++},{'-',()=>d[dp]--},
{'.',()=>Console.Write(d[dp])},{',',()=>d[dp]=Console.ReadKey().KeyChar},
{'[',()=>{if(d[dp]>0)s.Push(ip);else f=true;}},
{']',()=>{if(d[dp]>0)ip=s.Peek();else s.Pop();}}};
while (ip++<p.Length-1){if(f){f=p[ip]!=']';continue;}u[p[ip]]();}
Console.ReadKey();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.