From 398335c2bcda0be07938b03a3805310ba2050f7e Mon Sep 17 00:00:00 2001 From: JinweiClarkChao Date: Fri, 9 Jan 2015 21:10:31 +0800 Subject: rm useless --- HelloWorld.bf | 1 + README.md | 7 ++ brainfuck.bf | 1 - brainfuck.c | 106 +++++++++++++++++++++++ brainfuck/brainfuck.sln | 22 ----- brainfuck/brainfuck/brainfuck.vcxproj | 84 ------------------ brainfuck/brainfuck/brainfuck.vcxproj.filters | 22 ----- brainfuck/brainfuck/main.cpp | 118 -------------------------- 8 files changed, 114 insertions(+), 247 deletions(-) create mode 100644 HelloWorld.bf delete mode 100644 brainfuck.bf create mode 100644 brainfuck.c delete mode 100644 brainfuck/brainfuck.sln delete mode 100644 brainfuck/brainfuck/brainfuck.vcxproj delete mode 100644 brainfuck/brainfuck/brainfuck.vcxproj.filters delete mode 100644 brainfuck/brainfuck/main.cpp diff --git a/HelloWorld.bf b/HelloWorld.bf new file mode 100644 index 0000000..e0a8381 --- /dev/null +++ b/HelloWorld.bf @@ -0,0 +1 @@ +++++++++++[>+++++++>++++++++++>+++>+<<<<-]>++.>+.+++++++..+++.>++.<<+++++++++++++++.>.+++.------.--------.>+.>. \ No newline at end of file diff --git a/README.md b/README.md index 66b2fa1..f1f0c80 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,13 @@ brainfuck ========= +##Usage: +```bash +gcc brainfuck.c -o brainfuck +./brainfuck HelloWorld.bf +``` + +##What's brainfuck Brainfuck is represented by an array with 30,000 cells initialized to zero and a data pointer pointing at the current cell. diff --git a/brainfuck.bf b/brainfuck.bf deleted file mode 100644 index e0a8381..0000000 --- a/brainfuck.bf +++ /dev/null @@ -1 +0,0 @@ -++++++++++[>+++++++>++++++++++>+++>+<<<<-]>++.>+.+++++++..+++.>++.<<+++++++++++++++.>.+++.------.--------.>+.>. \ No newline at end of file diff --git a/brainfuck.c b/brainfuck.c new file mode 100644 index 0000000..cda6857 --- /dev/null +++ b/brainfuck.c @@ -0,0 +1,106 @@ +#include +#include +#include + +#define MAX_DATA 30000 + +typedef struct brainfuck{ + char data[MAX_DATA]; + char command[MAX_DATA]; + char *ptr; + int count; + int pos; +}bf; + +bf one; + +void init() +{ + char c; + memset(&one, 0, sizeof(one)); + one.pos = 0; + one.count = 0; + one.ptr = one.data; + + while (c = getchar()) + { + if (c == '\n') + break; + else + { + one.command[++one.count] = c; + } + } + one.command[one.count] = '\0'; +} + +void run() +{ + char c; + int i; + + while (c = one.command[++one.pos]) + { + switch (c) + { + case '+': + (*one.ptr)++; + break; + case '-': + (*one.ptr)--; + break; + case '>': + one.ptr++; + break; + case '<': + one.ptr--; + break; + case ',': + *one.ptr = getchar(); + break; + case '.': + putchar(*one.ptr); + break; + case '[': + if (*one.ptr != 0) + break; + else + { + for (i = one.pos + 1; i <= one.count; i++) + { + if (one.command[i] == ']') + { + one.pos = i; + break; + } + } + } + break; + case ']': + if (*one.ptr == 0) + break; + else + { + for (i = one.pos - 1; i >= 1; i--) + { + if (one.command[i] == '[') + { + one.pos = i; + break; + } + } + } + break; + } + } +} + +int main(int argc, char **argv) +{ + if (argc > 1) { + freopen(argv[1], "r", stdin); + } + init(); + run(); + return 0; +} \ No newline at end of file diff --git a/brainfuck/brainfuck.sln b/brainfuck/brainfuck.sln deleted file mode 100644 index 97b1599..0000000 --- a/brainfuck/brainfuck.sln +++ /dev/null @@ -1,22 +0,0 @@ - -Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 2013 -VisualStudioVersion = 12.0.30723.0 -MinimumVisualStudioVersion = 10.0.40219.1 -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "brainfuck", "brainfuck\brainfuck.vcxproj", "{3C1E6E82-6A2E-4F2C-850E-707F3A84274E}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Win32 = Debug|Win32 - Release|Win32 = Release|Win32 - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {3C1E6E82-6A2E-4F2C-850E-707F3A84274E}.Debug|Win32.ActiveCfg = Debug|Win32 - {3C1E6E82-6A2E-4F2C-850E-707F3A84274E}.Debug|Win32.Build.0 = Debug|Win32 - {3C1E6E82-6A2E-4F2C-850E-707F3A84274E}.Release|Win32.ActiveCfg = Release|Win32 - {3C1E6E82-6A2E-4F2C-850E-707F3A84274E}.Release|Win32.Build.0 = Release|Win32 - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection -EndGlobal diff --git a/brainfuck/brainfuck/brainfuck.vcxproj b/brainfuck/brainfuck/brainfuck.vcxproj deleted file mode 100644 index a5a1aca..0000000 --- a/brainfuck/brainfuck/brainfuck.vcxproj +++ /dev/null @@ -1,84 +0,0 @@ - - - - - Debug - Win32 - - - Release - Win32 - - - - {3C1E6E82-6A2E-4F2C-850E-707F3A84274E} - Win32Proj - brainfuck - - - - Application - true - v120 - Unicode - - - Application - false - v120 - true - Unicode - - - - - - - - - - - - - true - - - false - - - - - - Level3 - Disabled - WIN32;_DEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions) - - - Console - true - - - - - Level3 - - - MaxSpeed - true - true - WIN32;NDEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions) - - - Console - true - true - true - - - - - - - - - \ No newline at end of file diff --git a/brainfuck/brainfuck/brainfuck.vcxproj.filters b/brainfuck/brainfuck/brainfuck.vcxproj.filters deleted file mode 100644 index 203a71c..0000000 --- a/brainfuck/brainfuck/brainfuck.vcxproj.filters +++ /dev/null @@ -1,22 +0,0 @@ - - - - - {4FC737F1-C7A5-4376-A066-2A32D752A2FF} - cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx - - - {93995380-89BD-4b04-88EB-625FBE52EBFB} - h;hh;hpp;hxx;hm;inl;inc;xsd - - - {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} - rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms - - - - - 源文件 - - - \ No newline at end of file diff --git a/brainfuck/brainfuck/main.cpp b/brainfuck/brainfuck/main.cpp deleted file mode 100644 index 669ab0a..0000000 --- a/brainfuck/brainfuck/main.cpp +++ /dev/null @@ -1,118 +0,0 @@ -/* -+ : Increments the value at the current cell by one. -- : Decrements the value at the current cell by one. -> : Moves the data pointer to the next cell (cell on the right). -< : Moves the data pointer to the previous cell (cell on the left). -. : Prints the ASCII value at the current cell (i.e. 65 = 'A'). -, : Reads a single input character into the current cell. -[ : If the value at the current cell is zero, skips to the corresponding ] . -Otherwise, move to the next instruction. -] : If the value at the current cell is zero, move to the next instruction. -Otherwise, move backwards in the instructions to the corresponding [ . -*/ -#include -#include -#include - -#define MAX_DATA 30000 - -typedef struct brainfuck{ - char data[MAX_DATA]; - char command[MAX_DATA]; - char *ptr; - int count; - int pos; -}bf; - -bf one; - -void init() -{ - char c; - memset(&one, 0, sizeof(one)); - one.pos = 0; - one.count = 0; - one.ptr = one.data; - - while (c = getchar()) - { - if (c == '\n') - break; - else - { - one.command[++one.count] = c; - } - } - one.command[one.count] = '\0'; -} - -void run() -{ - char c; - int i; - - while (c = one.command[++one.pos]) - { - switch (c) - { - case '+': - (*one.ptr)++; - break; - case '-': - (*one.ptr)--; - break; - case '>': - one.ptr++; - break; - case '<': - one.ptr--; - break; - case ',': - *one.ptr = getchar(); - break; - case '.': - putchar(*one.ptr); - break; - case '[': - if (*one.ptr != 0) - break; - else - { - for (i = one.pos + 1; i <= one.count; i++) - { - if (one.command[i] == ']') - { - one.pos = i; - break; - } - } - } - break; - case ']': - if (*one.ptr == 0) - break; - else - { - for (i = one.pos - 1; i >= 1; i--) - { - if (one.command[i] == '[') - { - one.pos = i; - break; - } - } - } - break; - } - } -} - -int main(int argc, char **argv) -{ - if (argc > 1) { - freopen(argv[1], "r", stdin); - } - init(); - run(); - return 0; -} \ No newline at end of file -- cgit v1.2.3