Execute Brain****: Difference between revisions
Content added Content deleted
Not a robot (talk | contribs) (Add SETL) |
(Added Easylang) |
||
Line 3,995: | Line 3,995: | ||
=={{header|E}}== |
=={{header|E}}== |
||
[[/E|Implementation in E]]. |
[[/E|Implementation in E]]. |
||
=={{header|EasyLang}}== |
|||
<syntaxhighlight> |
|||
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 |
|||
++++++++[>+>++++<<-]>++>>+<[-[>>+<<-]+>>]>+[ |
|||
-<<<[ |
|||
->[+[-]+>++>>>-<<]<[<]>>++++++[<<+++++>>-]+<<++.[-]<< |
|||
]>.>+[>>]>+ |
|||
] |
|||
</syntaxhighlight> |
|||
=={{header|Elena}}== |
=={{header|Elena}}== |