Anonymous user
Execute Brain****: Difference between revisions
Removed Awk code's dependency on external programs, fixed 'ARGV too long' error
(Update to use new numeric escape sequence) |
(Removed Awk code's dependency on external programs, fixed 'ARGV too long' error) |
||
Line 164:
=={{header|AWK}}==
Expects the program (not the program file) to be the first argument to the script. Cells don't wrap (trivial if desired) and the code and arena are unbounded.
<lang AWK>BEGIN {
compile(bf)
execute()
}
# Strips non-instructions, builds the jump table.
function compile(s, i,j,k,f) {
Line 181 ⟶ 180:
if(src[i] ~ /[\-\+\[\]\<\>,\.]/)
code[j++] = src[i]
if(src[i] == "[") {
marks[j] = 1
Line 202 ⟶ 201:
}
}
function execute( pc,p,i) {
pc = p = 0
while(pc in code) {
i = code[pc]
if(i == "+")
arena[p]++
Line 219 ⟶ 218:
printf("%c", arena[p])
else if(i == ",") {
while(1) {
if (goteof) break
if (!gotline) {
arena[p] = 0 + $2▼
gotline = getline
if(!gotline) goteof = 1
if (goteof) break
line = $0
}
if (line == "") {
gotline=0
m[p]=10
break
}
if (!genord) {
for(i=1; i<256; i++)
ord[sprintf("%c",i)] = i
genord=1
}
c = substr(line, 1, 1)
line=substr(line, 2)
break
}
} else if((i == "[" && arena[p] == 0) ||
(i == "]" && arena[p] != 0))
|