Anonymous user
Execute Brain****/Elena: Difference between revisions
m
no edit summary
No edit summary |
imported>Arakov mNo edit summary |
||
(7 intermediate revisions by 3 users not shown) | |||
Line 1:
ELENA 6.x:
<syntaxhighlight lang="elena">import system'
import system'
import system'dynamic'expressions;
import extensions
import extensions'
const bf_program = "++++++++++[>+++++++>++++++++++>+++>+<<<<-]>++.>+.+++++++..+++.>++.<<+++++++++++++++.>.+++.------.--------.>+.>."
class TapeAssembler
{
constructor
Expression.Constant(0)));
constructor
assembly_program(self)
[▼
}
▲ ]
open()
close()
var loop :=
new Message("
),
input()
Expression.MessageCall(
TapeExpression Variable("tape"),▼
new
new
)
)
output()
new
Expression.Constant(console),
new
)
next()
new Message("add[2]"),
▲ ]
previous()
new Message("subtract[2]"),
Expression.Constant(1))))
▲ ]
increase()
new Message("setAt[3]"),
▲ TapeExpression MessageCall(
new Message("load[2]"),
new
Expression.MessageCall(
new Message("toInt[2]"),
new
),
▲ ]
Expression.Constant(1)
)
)
));
decrease()
new Message("setAt[3]"),
Expression.Variable("ptr"),
▲ TapeExpression MessageCall(
new Message("load[2]"),
new
Expression.MessageCall(
new Message("toInt[2]"),
new
),
Expression.Constant(1)
▲ ]
)
)
));
}▼
var program :=
"eval",
).compile();
▲ ]
}
▲const bf_program = "++++++++++[>+++++++>++++++++++>+++>+<<<<-]>++.>+.+++++++..+++.>++.<<+++++++++++++++.>.+++.------.--------.>+.>.".
{
▲program =
writeLine:bf_program.▼
▲ var bfAssemblyProgram := scriptEngine
▲ load path:"asmrules.es";
▲ eval(bf_program).
▲ var bfProgram := TapeAssembler new(bfAssemblyProgram); get.
▲ var bfTape := Array new:1024; populate(:n)<int>($0).
bfProgram(bfTape)
}</syntaxhighlight>
The grammar:
<
#grammar
#grammar cf
#define start ::=
<=
system'dynamic'DynamicTape (
system'dynamic'AllocFunction ( "1" )
system'dynamic'LocalFunction ( "2" ) => command commands
<= ) =>;
#define start ::= $eof;
#define commands ::= command commands;
Line 181 ⟶ 204:
#define commands ::= $eof;
#define command ::= <=
#define command ::= <=
#define command ::= <=
#define command ::= <=
#define command ::= <=
#define command ::= <=
#define command ::= <=
#define command ::= <=
#define comment ::= " " comments;
Line 199 ⟶ 222:
#mode symbolic;
]]</
{{out}}
<pre>
++++++++++[>+++++++>++++++++++>+++>+<<<<-]>++.>+.+++++++..+++.>++.<<+++++++++++++++.>.+++.------.--------.>+.>.
Hello World!
|