From aa4637fb18c7023dbc9b1281d36bf37da2757337 Mon Sep 17 00:00:00 2001 From: JinweiClarkChao Date: Thu, 8 Jan 2015 20:35:54 +0800 Subject: init --- .gitignore | 184 ++++++++++++++++++++++++++ brainfuck/brainfuck.sln | 22 +++ brainfuck/brainfuck/brainfuck.vcxproj | 84 ++++++++++++ brainfuck/brainfuck/brainfuck.vcxproj.filters | 22 +++ brainfuck/brainfuck/main.cpp | 117 ++++++++++++++++ 5 files changed, 429 insertions(+) create mode 100644 .gitignore create mode 100644 brainfuck/brainfuck.sln create mode 100644 brainfuck/brainfuck/brainfuck.vcxproj create mode 100644 brainfuck/brainfuck/brainfuck.vcxproj.filters create mode 100644 brainfuck/brainfuck/main.cpp diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d579511 --- /dev/null +++ b/.gitignore @@ -0,0 +1,184 @@ +## Ignore Visual Studio temporary files, build results, and +## files generated by popular Visual Studio add-ons. + +# User-specific files +*.suo +*.user +*.userosscache +*.sln.docstates + +# Build results +[Dd]ebug/ +[Dd]ebugPublic/ +[Rr]elease/ +[Rr]eleases/ +x64/ +x86/ +build/ +bld/ +[Bb]in/ +[Oo]bj/ + +# Roslyn cache directories +*.ide/ + +# MSTest test Results +[Tt]est[Rr]esult*/ +[Bb]uild[Ll]og.* + +#NUNIT +*.VisualState.xml +TestResult.xml + +# Build Results of an ATL Project +[Dd]ebugPS/ +[Rr]eleasePS/ +dlldata.c + +*_i.c +*_p.c +*_i.h +*.ilk +*.meta +*.obj +*.pch +*.pdb +*.pgc +*.pgd +*.rsp +*.sbr +*.tlb +*.tli +*.tlh +*.tmp +*.tmp_proj +*.log +*.vspscc +*.vssscc +.builds +*.pidb +*.svclog +*.scc + +# Chutzpah Test files +_Chutzpah* + +# Visual C++ cache files +ipch/ +*.aps +*.ncb +*.opensdf +*.sdf +*.cachefile + +# Visual Studio profiler +*.psess +*.vsp +*.vspx + +# TFS 2012 Local Workspace +$tf/ + +# Guidance Automation Toolkit +*.gpState + +# ReSharper is a .NET coding add-in +_ReSharper*/ +*.[Rr]e[Ss]harper +*.DotSettings.user + +# JustCode is a .NET coding addin-in +.JustCode + +# TeamCity is a build add-in +_TeamCity* + +# DotCover is a Code Coverage Tool +*.dotCover + +# NCrunch +_NCrunch_* +.*crunch*.local.xml + +# MightyMoose +*.mm.* +AutoTest.Net/ + +# Web workbench (sass) +.sass-cache/ + +# Installshield output folder +[Ee]xpress/ + +# DocProject is a documentation generator add-in +DocProject/buildhelp/ +DocProject/Help/*.HxT +DocProject/Help/*.HxC +DocProject/Help/*.hhc +DocProject/Help/*.hhk +DocProject/Help/*.hhp +DocProject/Help/Html2 +DocProject/Help/html + +# Click-Once directory +publish/ + +# Publish Web Output +*.[Pp]ublish.xml +*.azurePubxml +# TODO: Comment the next line if you want to checkin your web deploy settings +# but database connection strings (with potential passwords) will be unencrypted +*.pubxml +*.publishproj + +# NuGet Packages +*.nupkg +# The packages folder can be ignored because of Package Restore +**/packages/* +# except build/, which is used as an MSBuild target. +!**/packages/build/ +# Uncomment if necessary however generally it will be regenerated when needed +#!**/packages/repositories.config + +# Windows Azure Build Output +csx/ +*.build.csdef + +# Windows Store app package directory +AppPackages/ + +# Others +*.Cache +ClientBin/ +[Ss]tyle[Cc]op.* +~$* +*~ +*.dbmdl +*.dbproj.schemaview +*.pfx +*.publishsettings +node_modules/ +bower_components/ + +# RIA/Silverlight projects +Generated_Code/ + +# Backup & report files from converting an old project file +# to a newer Visual Studio version. Backup files are not needed, +# because we have git ;-) +_UpgradeReport_Files/ +Backup*/ +UpgradeLog*.XML +UpgradeLog*.htm + +# SQL Server files +*.mdf +*.ldf + +# Business Intelligence projects +*.rdl.data +*.bim.layout +*.bim_*.settings + +# Microsoft Fakes +FakesAssemblies/ \ No newline at end of file diff --git a/brainfuck/brainfuck.sln b/brainfuck/brainfuck.sln new file mode 100644 index 0000000..97b1599 --- /dev/null +++ b/brainfuck/brainfuck.sln @@ -0,0 +1,22 @@ + +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 new file mode 100644 index 0000000..a5a1aca --- /dev/null +++ b/brainfuck/brainfuck/brainfuck.vcxproj @@ -0,0 +1,84 @@ + + + + + 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 new file mode 100644 index 0000000..203a71c --- /dev/null +++ b/brainfuck/brainfuck/brainfuck.vcxproj.filters @@ -0,0 +1,22 @@ + + + + + {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 new file mode 100644 index 0000000..b1e0afa --- /dev/null +++ b/brainfuck/brainfuck/main.cpp @@ -0,0 +1,117 @@ +/* ++ : 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; + } + } +} + +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 ',': + + break; + case '.': + putchar(*one.ptr); + break; + case '[': + if (*one.ptr) + break; + else + { + for (i = one.pos; i < one.count; i++) + { + if (one.command[i] == ']') + { + one.pos = i; + break; + } + } + } + break; + case ']': + if (*one.ptr) + break; + else + { + for (i = one.pos; i >= 0; 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