OBJECT Codeunit 60000 Brainfuck Interpreter { OBJECT-PROPERTIES { Date=18-06-08; Time=[ 2:23:56 ]; Modified=Yes; Version List=; } PROPERTIES { OnRun=BEGIN CASE STRMENU('1. hello,2. i/o,3. reverse,4. mibuso,5. my birthday') OF 1: MESSAGE(Execute(Text001)); 2: MESSAGE(Execute(Text002)); 3: MESSAGE(Execute(Text003)); 4: HYPERLINK(Execute(Text004)); 5: MESSAGE(Execute(Text005)); END; END; } CODE { VAR Text001@1150000 : TextConst 'ENU=++++++++++[>+++++++>++++++++++>+++>+<<<<-]>++.>+.+++++++..+++.>++.<<+++++++++++++++.>.+++.------.--------.>+.>.'; Text002@1150001 : TextConst 'ENU=,[.>]'; Text003@1150002 : TextConst 'ENU=,[.>]<[.<]'; Text004@1150003 : TextConst 'ENU=+++++++++++[>++++++++++<-]>-.----.-------.<++[>++++++++++<-]>-.--.----.>+++++++++[>+++++<-]>+.<<------------.++++++++++++.--.'; Text005@1150004 : TextConst 'ENU=+++++[>+++++++++>+++++++++<<-]>++>+++++.-.<.>-.++++++.<.>+..'; PROCEDURE Execute@1150000(strCode@1150000 : Text[1024]) strResult : Text[1024]; VAR ip@1150001 : Integer; mem@1150002 : ARRAY [1024] OF Integer; d@1150004 : Dialog; i@1150005 : Integer; s@1150006 : Text[250]; c@1150007 : Char; offset@1150003 : Integer; BEGIN // clear .. ip := 1; offset := 1; CLEAR(mem); // interpretation .. WHILE ip <= STRLEN(strCode) DO BEGIN CASE strCode[ip] OF '>': offset := offset + 1; '<': offset := offset - 1; '+': mem[offset] := mem[offset] + 1; '-': mem[offset] := mem[offset] - 1; '.': BEGIN c := mem[offset]; strResult := strResult + FORMAT(c); END; ',': BEGIN CLEAR(s); d.OPEN('Input#1##############'); d.INPUT(1,s); d.CLOSE; FOR i := 1 TO STRLEN(s) DO mem[offset+i-1] := s[i]; END; '[': BEGIN IF offset IN [1..1024] THEN IF mem[offset] = 0 THEN WHILE (strCode[ip] <> ']') AND (ip IN [1..1023]) DO ip := ip + 1; END; ']': BEGIN IF (offset >= 1) AND (offset <= 1024) THEN IF mem[offset] <> 0 THEN WHILE (strCode[ip] <> '[') AND (ip IN [2..1024]) DO ip := ip - 1; END; END; ip := ip + 1; END; END; BEGIN END. } }
Comments
MVP - Dynamics NAV
My BLOG
NAVERTICA a.s.
Yes, Turing-complete language
http://en.wikipedia.org/wiki/Brainfuck
:roll:
=D>
Tino Ruijs
Microsoft Dynamics NAV specialist
** SI ** Bert Van Gestel **
**********************