aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore184
-rw-r--r--brainfuck/brainfuck.sln22
-rw-r--r--brainfuck/brainfuck/brainfuck.vcxproj84
-rw-r--r--brainfuck/brainfuck/brainfuck.vcxproj.filters22
-rw-r--r--brainfuck/brainfuck/main.cpp117
5 files changed, 429 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..d579511
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,184 @@
1## Ignore Visual Studio temporary files, build results, and
2## files generated by popular Visual Studio add-ons.
3
4# User-specific files
5*.suo
6*.user
7*.userosscache
8*.sln.docstates
9
10# Build results
11[Dd]ebug/
12[Dd]ebugPublic/
13[Rr]elease/
14[Rr]eleases/
15x64/
16x86/
17build/
18bld/
19[Bb]in/
20[Oo]bj/
21
22# Roslyn cache directories
23*.ide/
24
25# MSTest test Results
26[Tt]est[Rr]esult*/
27[Bb]uild[Ll]og.*
28
29#NUNIT
30*.VisualState.xml
31TestResult.xml
32
33# Build Results of an ATL Project
34[Dd]ebugPS/
35[Rr]eleasePS/
36dlldata.c
37
38*_i.c
39*_p.c
40*_i.h
41*.ilk
42*.meta
43*.obj
44*.pch
45*.pdb
46*.pgc
47*.pgd
48*.rsp
49*.sbr
50*.tlb
51*.tli
52*.tlh
53*.tmp
54*.tmp_proj
55*.log
56*.vspscc
57*.vssscc
58.builds
59*.pidb
60*.svclog
61*.scc
62
63# Chutzpah Test files
64_Chutzpah*
65
66# Visual C++ cache files
67ipch/
68*.aps
69*.ncb
70*.opensdf
71*.sdf
72*.cachefile
73
74# Visual Studio profiler
75*.psess
76*.vsp
77*.vspx
78
79# TFS 2012 Local Workspace
80$tf/
81
82# Guidance Automation Toolkit
83*.gpState
84
85# ReSharper is a .NET coding add-in
86_ReSharper*/
87*.[Rr]e[Ss]harper
88*.DotSettings.user
89
90# JustCode is a .NET coding addin-in
91.JustCode
92
93# TeamCity is a build add-in
94_TeamCity*
95
96# DotCover is a Code Coverage Tool
97*.dotCover
98
99# NCrunch
100_NCrunch_*
101.*crunch*.local.xml
102
103# MightyMoose
104*.mm.*
105AutoTest.Net/
106
107# Web workbench (sass)
108.sass-cache/
109
110# Installshield output folder
111[Ee]xpress/
112
113# DocProject is a documentation generator add-in
114DocProject/buildhelp/
115DocProject/Help/*.HxT
116DocProject/Help/*.HxC
117DocProject/Help/*.hhc
118DocProject/Help/*.hhk
119DocProject/Help/*.hhp
120DocProject/Help/Html2
121DocProject/Help/html
122
123# Click-Once directory
124publish/
125
126# Publish Web Output
127*.[Pp]ublish.xml
128*.azurePubxml
129# TODO: Comment the next line if you want to checkin your web deploy settings
130# but database connection strings (with potential passwords) will be unencrypted
131*.pubxml
132*.publishproj
133
134# NuGet Packages
135*.nupkg
136# The packages folder can be ignored because of Package Restore
137**/packages/*
138# except build/, which is used as an MSBuild target.
139!**/packages/build/
140# Uncomment if necessary however generally it will be regenerated when needed
141#!**/packages/repositories.config
142
143# Windows Azure Build Output
144csx/
145*.build.csdef
146
147# Windows Store app package directory
148AppPackages/
149
150# Others
151*.Cache
152ClientBin/
153[Ss]tyle[Cc]op.*
154~$*
155*~
156*.dbmdl
157*.dbproj.schemaview
158*.pfx
159*.publishsettings
160node_modules/
161bower_components/
162
163# RIA/Silverlight projects
164Generated_Code/
165
166# Backup & report files from converting an old project file
167# to a newer Visual Studio version. Backup files are not needed,
168# because we have git ;-)
169_UpgradeReport_Files/
170Backup*/
171UpgradeLog*.XML
172UpgradeLog*.htm
173
174# SQL Server files
175*.mdf
176*.ldf
177
178# Business Intelligence projects
179*.rdl.data
180*.bim.layout
181*.bim_*.settings
182
183# Microsoft Fakes
184FakesAssemblies/ \ 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 @@
1
2Microsoft Visual Studio Solution File, Format Version 12.00
3# Visual Studio 2013
4VisualStudioVersion = 12.0.30723.0
5MinimumVisualStudioVersion = 10.0.40219.1
6Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "brainfuck", "brainfuck\brainfuck.vcxproj", "{3C1E6E82-6A2E-4F2C-850E-707F3A84274E}"
7EndProject
8Global
9 GlobalSection(SolutionConfigurationPlatforms) = preSolution
10 Debug|Win32 = Debug|Win32
11 Release|Win32 = Release|Win32
12 EndGlobalSection
13 GlobalSection(ProjectConfigurationPlatforms) = postSolution
14 {3C1E6E82-6A2E-4F2C-850E-707F3A84274E}.Debug|Win32.ActiveCfg = Debug|Win32
15 {3C1E6E82-6A2E-4F2C-850E-707F3A84274E}.Debug|Win32.Build.0 = Debug|Win32
16 {3C1E6E82-6A2E-4F2C-850E-707F3A84274E}.Release|Win32.ActiveCfg = Release|Win32
17 {3C1E6E82-6A2E-4F2C-850E-707F3A84274E}.Release|Win32.Build.0 = Release|Win32
18 EndGlobalSection
19 GlobalSection(SolutionProperties) = preSolution
20 HideSolutionNode = FALSE
21 EndGlobalSection
22EndGlobal
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 @@
1<?xml version="1.0" encoding="utf-8"?>
2<Project DefaultTargets="Build" ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3 <ItemGroup Label="ProjectConfigurations">
4 <ProjectConfiguration Include="Debug|Win32">
5 <Configuration>Debug</Configuration>
6 <Platform>Win32</Platform>
7 </ProjectConfiguration>
8 <ProjectConfiguration Include="Release|Win32">
9 <Configuration>Release</Configuration>
10 <Platform>Win32</Platform>
11 </ProjectConfiguration>
12 </ItemGroup>
13 <PropertyGroup Label="Globals">
14 <ProjectGuid>{3C1E6E82-6A2E-4F2C-850E-707F3A84274E}</ProjectGuid>
15 <Keyword>Win32Proj</Keyword>
16 <RootNamespace>brainfuck</RootNamespace>
17 </PropertyGroup>
18 <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
19 <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
20 <ConfigurationType>Application</ConfigurationType>
21 <UseDebugLibraries>true</UseDebugLibraries>
22 <PlatformToolset>v120</PlatformToolset>
23 <CharacterSet>Unicode</CharacterSet>
24 </PropertyGroup>
25 <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
26 <ConfigurationType>Application</ConfigurationType>
27 <UseDebugLibraries>false</UseDebugLibraries>
28 <PlatformToolset>v120</PlatformToolset>
29 <WholeProgramOptimization>true</WholeProgramOptimization>
30 <CharacterSet>Unicode</CharacterSet>
31 </PropertyGroup>
32 <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
33 <ImportGroup Label="ExtensionSettings">
34 </ImportGroup>
35 <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
36 <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
37 </ImportGroup>
38 <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
39 <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
40 </ImportGroup>
41 <PropertyGroup Label="UserMacros" />
42 <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
43 <LinkIncremental>true</LinkIncremental>
44 </PropertyGroup>
45 <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
46 <LinkIncremental>false</LinkIncremental>
47 </PropertyGroup>
48 <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
49 <ClCompile>
50 <PrecompiledHeader>
51 </PrecompiledHeader>
52 <WarningLevel>Level3</WarningLevel>
53 <Optimization>Disabled</Optimization>
54 <PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
55 </ClCompile>
56 <Link>
57 <SubSystem>Console</SubSystem>
58 <GenerateDebugInformation>true</GenerateDebugInformation>
59 </Link>
60 </ItemDefinitionGroup>
61 <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
62 <ClCompile>
63 <WarningLevel>Level3</WarningLevel>
64 <PrecompiledHeader>
65 </PrecompiledHeader>
66 <Optimization>MaxSpeed</Optimization>
67 <FunctionLevelLinking>true</FunctionLevelLinking>
68 <IntrinsicFunctions>true</IntrinsicFunctions>
69 <PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
70 </ClCompile>
71 <Link>
72 <SubSystem>Console</SubSystem>
73 <GenerateDebugInformation>true</GenerateDebugInformation>
74 <EnableCOMDATFolding>true</EnableCOMDATFolding>
75 <OptimizeReferences>true</OptimizeReferences>
76 </Link>
77 </ItemDefinitionGroup>
78 <ItemGroup>
79 <ClCompile Include="main.cpp" />
80 </ItemGroup>
81 <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
82 <ImportGroup Label="ExtensionTargets">
83 </ImportGroup>
84</Project> \ 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 @@
1<?xml version="1.0" encoding="utf-8"?>
2<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3 <ItemGroup>
4 <Filter Include="源文件">
5 <UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
6 <Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
7 </Filter>
8 <Filter Include="头文件">
9 <UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
10 <Extensions>h;hh;hpp;hxx;hm;inl;inc;xsd</Extensions>
11 </Filter>
12 <Filter Include="资源文件">
13 <UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
14 <Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
15 </Filter>
16 </ItemGroup>
17 <ItemGroup>
18 <ClCompile Include="main.cpp">
19 <Filter>源文件</Filter>
20 </ClCompile>
21 </ItemGroup>
22</Project> \ 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 @@
1/*
2+ : Increments the value at the current cell by one.
3- : Decrements the value at the current cell by one.
4> : Moves the data pointer to the next cell (cell on the right).
5< : Moves the data pointer to the previous cell (cell on the left).
6. : Prints the ASCII value at the current cell (i.e. 65 = 'A').
7, : Reads a single input character into the current cell.
8[ : If the value at the current cell is zero, skips to the corresponding ] .
9Otherwise, move to the next instruction.
10] : If the value at the current cell is zero, move to the next instruction.
11Otherwise, move backwards in the instructions to the corresponding [ .
12*/
13#include <stdio.h>
14#include <stdlib.h>
15#include <string.h>
16
17#define MAX_DATA 30000
18
19typedef struct brainfuck{
20 char data[MAX_DATA];
21 char command[MAX_DATA];
22 char *ptr;
23 int count;
24 int pos;
25}bf;
26
27bf one;
28
29void init()
30{
31 char c;
32 memset(&one, 0, sizeof(one));
33 one.pos = 0;
34 one.count = 0;
35 one.ptr = one.data;
36
37 while (c = getchar())
38 {
39 if (c == '\n')
40 break;
41 else
42 {
43 one.command[one.count++] = c;
44 }
45 }
46}
47
48void run()
49{
50 char c;
51 int i;
52
53 while (c = one.command[one.pos++])
54 {
55 switch (c)
56 {
57 case '+':
58 (*one.ptr)++;
59 break;
60 case '-':
61 (*one.ptr)--;
62 break;
63 case '>':
64 one.ptr++;
65 break;
66 case '<':
67 one.ptr--;
68 break;
69 case ',':
70
71 break;
72 case '.':
73 putchar(*one.ptr);
74 break;
75 case '[':
76 if (*one.ptr)
77 break;
78 else
79 {
80 for (i = one.pos; i < one.count; i++)
81 {
82 if (one.command[i] == ']')
83 {
84 one.pos = i;
85 break;
86 }
87 }
88 }
89 break;
90 case ']':
91 if (*one.ptr)
92 break;
93 else
94 {
95 for (i = one.pos; i >= 0; i--)
96 {
97 if (one.command[i] == '[')
98 {
99 one.pos = i;
100 break;
101 }
102 }
103 }
104 break;
105 }
106 }
107}
108
109int main(int argc, char **argv)
110{
111 if (argc > 1) {
112 freopen(argv[1], "r", stdin);
113 }
114 init();
115 run();
116 return 0;
117} \ No newline at end of file
Powered by cgit v1.2.3 (git 2.41.0)