Data update
This commit is contained in:
parent
35bcdeebf8
commit
74c69a0df6
2427 changed files with 31826 additions and 3468 deletions
76
Task/Execute-Brain-/EasyLang/execute-brain-.easy
Normal file
76
Task/Execute-Brain-/EasyLang/execute-brain-.easy
Normal file
|
|
@ -0,0 +1,76 @@
|
|||
proc exec code$ . .
|
||||
len mem[] 100
|
||||
dp = 1
|
||||
code$[] = strchars code$
|
||||
ip = 1
|
||||
while ip <= len code$[]
|
||||
if dp > len mem[]
|
||||
len mem[] len mem[] + 100
|
||||
.
|
||||
if dp < 1
|
||||
print "programm error"
|
||||
return
|
||||
.
|
||||
c$ = code$[ip]
|
||||
if c$ = "+"
|
||||
mem[dp] += 1
|
||||
elif c$ = "-"
|
||||
mem[dp] -= 1
|
||||
elif c$ = ">"
|
||||
dp += 1
|
||||
elif c$ = "<"
|
||||
dp -= 1
|
||||
elif c$ = "."
|
||||
write strchar mem[dp]
|
||||
elif c$ = ","
|
||||
print "input not implemented"
|
||||
elif c$ = "["
|
||||
if mem[dp] = 0
|
||||
br = 1
|
||||
repeat
|
||||
ip += 1
|
||||
if code$[ip] = "["
|
||||
br += 1
|
||||
elif code$[ip] = "]"
|
||||
br -= 1
|
||||
.
|
||||
until br = 0
|
||||
.
|
||||
else
|
||||
br[] &= ip
|
||||
.
|
||||
elif c$ = "]"
|
||||
ip = br[len br[]] - 1
|
||||
len br[] -1
|
||||
.
|
||||
ip += 1
|
||||
.
|
||||
.
|
||||
func syntax code$ .
|
||||
for i to len code$
|
||||
h$ = substr code$ i 1
|
||||
if h$ = "["
|
||||
br += 1
|
||||
elif h$ = "]"
|
||||
br -= 1
|
||||
.
|
||||
if br < 0
|
||||
return 0
|
||||
.
|
||||
.
|
||||
return if br = 0
|
||||
.
|
||||
repeat
|
||||
inp$ = input
|
||||
until inp$ = ""
|
||||
code$ &= inp$
|
||||
.
|
||||
if syntax code$ <> 1
|
||||
print "syntax error"
|
||||
return
|
||||
.
|
||||
exec code$
|
||||
#
|
||||
input_data
|
||||
++++++++[>++++[>++>+++>+++>+<<<<-]>+>+>->>+[<]<-]>>.>
|
||||
---.+++++++..+++.>>.<-.<.+++.------.--------.>>+.>++.
|
||||
50
Task/Execute-Brain-/R/execute-brain-.r
Normal file
50
Task/Execute-Brain-/R/execute-brain-.r
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
bf <- function(code) {
|
||||
instructions <- strsplit(code, "")[[1]]
|
||||
tape <- c()
|
||||
visited <- c()
|
||||
|
||||
pset <- function(n) {
|
||||
if (n %in% visited)
|
||||
p <<- n
|
||||
else {
|
||||
visited[length(visited)+1] <<- n
|
||||
tape[as.character(n)] <<- 0
|
||||
pset(n)
|
||||
}
|
||||
}
|
||||
|
||||
bracket <- function(b1, b2, x) {
|
||||
nest <- 1
|
||||
j <- i + x
|
||||
while (nest != 0) {
|
||||
if (instructions[j] == b1)
|
||||
nest <- nest + 1
|
||||
if (instructions[j] == b2)
|
||||
nest <- nest - 1
|
||||
j <- j + x
|
||||
}
|
||||
i <<- j
|
||||
}
|
||||
|
||||
pset(0)
|
||||
i <- 1
|
||||
while (i <= length(instructions)) {
|
||||
p_ <- as.character(p)
|
||||
c <- instructions[i]
|
||||
switch(c,
|
||||
">" = pset(p + 1),
|
||||
"<" = pset(p - 1),
|
||||
"+" = tape[p_] <- tape[p_] + 1,
|
||||
"-" = tape[p_] <- tape[p_] - 1,
|
||||
"." = cat(intToUtf8(tape[p_])),
|
||||
# TODO: IMPLEMENT ","
|
||||
"[" = if (tape[p_] == 0) {
|
||||
bracket("[", "]", 1)
|
||||
i <- i - 1 # off by one error
|
||||
},
|
||||
"]" = bracket("]", "[", -1))
|
||||
i <- i + 1
|
||||
}
|
||||
}
|
||||
|
||||
bf("++++++++++[>+>+++>+++++++>++++++++++<<<<-]>>>++.>+.+++++++..+++.<<++.>+++++++++++++++.>.+++.------.--------.<<+.<.")
|
||||
71
Task/Execute-Brain-/SETL/execute-brain-.setl
Normal file
71
Task/Execute-Brain-/SETL/execute-brain-.setl
Normal file
|
|
@ -0,0 +1,71 @@
|
|||
program brainfuck;
|
||||
if command_line(1) = om then
|
||||
print("error: no program file given");
|
||||
stop;
|
||||
end if;
|
||||
|
||||
if (f := open(command_line(1), "r")) = om then
|
||||
print("error: cannot open file");
|
||||
stop;
|
||||
end if;
|
||||
|
||||
[pgm, loopmap] := read_program(f);
|
||||
close(f);
|
||||
|
||||
mem_left := [];
|
||||
mem_right := [];
|
||||
mem_cur := 0;
|
||||
pc := 1;
|
||||
loop while pc <= #pgm do
|
||||
case pgm(pc) of
|
||||
("+"): mem_cur +:= 1;
|
||||
mem_cur mod:= 256;
|
||||
("-"): mem_cur -:= 1;
|
||||
mem_cur mod:= 256;
|
||||
(">"): mem_left with:= mem_cur;
|
||||
mem_cur frome mem_right;
|
||||
mem_cur ?:= 0;
|
||||
("<"): mem_right with:= mem_cur;
|
||||
mem_cur frome mem_left;
|
||||
mem_cur ?:= 0;
|
||||
("."): putchar(char mem_cur);
|
||||
(","): mem_cur := ichar (getchar ? '\x00');
|
||||
("["): if mem_cur = 0 then pc := loopmap(pc); end if;
|
||||
("]"): if mem_cur /= 0 then pc := loopmap(pc); end if;
|
||||
end case;
|
||||
pc +:= 1;
|
||||
end loop;
|
||||
|
||||
proc read_program(f);
|
||||
pgm := [];
|
||||
loop doing ch := getc(f); while ch /= om do
|
||||
if ch in "+-<>.,[]" then
|
||||
pgm with:= ch;
|
||||
end if;
|
||||
end loop;
|
||||
|
||||
stack := [];
|
||||
loopmap := {};
|
||||
loop for i in [1..#pgm] do
|
||||
case pgm(i) of
|
||||
("["):
|
||||
stack with:= i;
|
||||
("]"):
|
||||
j frome stack;
|
||||
if j=om then
|
||||
print("mismatched brackets");
|
||||
stop;
|
||||
end if;
|
||||
loopmap(i) := j;
|
||||
loopmap(j) := i;
|
||||
end case;
|
||||
end loop;
|
||||
|
||||
if stack /= [] then
|
||||
print("mismatched brackets");
|
||||
stop;
|
||||
end if;
|
||||
|
||||
return [pgm, loopmap];
|
||||
end proc;
|
||||
end program;
|
||||
Loading…
Add table
Add a link
Reference in a new issue