source: trunk/StudioModules/LDModuleBrainfuck/UBrainfuckCode.pas

Last change on this file was 16, checked in by chronos, 12 years ago
  • Modified: Definition of text source file moved to new package Basic.
File size: 2.1 KB
Line 
1unit UBrainfuckCode;
2
3{$mode delphi}{$H+}
4
5interface
6
7uses
8 Classes, SysUtils, USource, SpecializedList;
9
10type
11 TBrainFuckCommand = (cmNoOperation, cmInc, cmDec, cmPointerInc, cmPointerDec,
12 cmOutput, cmInput, cmLoopStart, cmLoopEnd, cmDebug);
13
14 { TSourceBrainFuck }
15
16 TSourceBrainFuck = class(TSource)
17 Code: TListByte;
18 constructor Create;
19 destructor Destroy; override;
20 end;
21
22 { TConvertorTextToBF }
23
24 TConvertorTextToBF = class(TConvertor)
25 constructor Create; override;
26 procedure Convert(Input, Output: TSourceList); override;
27 end;
28
29
30implementation
31
32uses
33 ULDModuleBasic;
34
35{ TSourceBrainFuck }
36
37constructor TSourceBrainFuck.Create;
38begin
39 Code := TListByte.Create;
40end;
41
42destructor TSourceBrainFuck.Destroy;
43begin
44 Code.Free;
45 inherited Destroy;
46end;
47
48{ TConvertorTextToBF }
49
50constructor TConvertorTextToBF.Create;
51begin
52 inherited Create;
53 Name := 'TextToBF';
54 InputType := TSourceText;
55 OutputType := TSourceBrainFuck;
56end;
57
58procedure TConvertorTextToBF.Convert(Input, Output: TSourceList);
59var
60 I: Integer;
61 Code: string;
62 Index: Integer;
63begin
64 inherited;
65 //DebugSteps.Clear;
66 TSourceBrainFuck(Output).Code.Clear;
67 Index := 0;
68 Code := TSourceText(Input).Content.Text;
69 for I := 1 to Length(Code) do begin
70 case Code[I] of
71 '+': begin
72 TSourceBrainFuck(Output).Code.Add(Byte(cmInc));
73 end;
74 '-': begin
75 TSourceBrainFuck(Output).Code.Add(Byte(cmDec));
76 end;
77 '>': begin
78 TSourceBrainFuck(Output).Code.Add(Byte(cmPointerInc));
79 end;
80 '<': begin
81 TSourceBrainFuck(Output).Code.Add(Byte(cmPointerDec));
82 end;
83 ',': begin
84 TSourceBrainFuck(Output).Code.Add(Byte(cmInput));
85 end;
86 '.': begin
87 TSourceBrainFuck(Output).Code.Add(Byte(cmOutput));
88 end;
89 '[': begin
90 TSourceBrainFuck(Output).Code.Add(Byte(cmLoopStart));
91 end;
92 ']': begin
93 TSourceBrainFuck(Output).Code.Add(Byte(cmLoopEnd));
94 end
95 end;
96 end;
97end;
98
99end.
100
Note: See TracBrowser for help on using the repository browser.