Anonymous user
Execute Brain****/Elena: Difference between revisions
m
no edit summary
mNo edit summary |
imported>Arakov mNo edit summary |
||
(6 intermediate revisions by 3 users not shown) | |||
Line 1:
ELENA 6.x:
<
import system'routines;
import system'dynamic'expressions;
import extensions;
import extensions'scripting;
const bf_program = "++++++++++[>+++++++>++++++++++>+++>+<<<<-]>++.>+.+++++++..+++.>++.<<+++++++++++++++.>.+++.------.--------.>+.>.";▼
class TapeAssembler
{
Stack
List<
constructor()
{
"ptr",
Expression.Constant(0)));
}
constructor load(assembly_program)
▲ <= ()
{
assembly_program(self)
}
open()
{
}
close()
{
var loop :=
new Message("at[2]"),
),
}
input()
{
new
new
)
)
)
}
output()
{
Expression.MessageCall(
▲ TapeExpression.Constant(console),
new
new
)
)
)
}
next()
{
new Message("add[2]"),
Expression.Constant(1))))
}
previous()
{
new Message("subtract[2]"),
Expression.Constant(1))))
}
increase()
{
new Message("setAt[3]"),
new Message("load[2]"),
new
Expression.MessageCall(
new Message("toInt[2]"),
new
),
Expression.Constant(1)
)
)
));
}
decrease()
{
new Message("setAt[3]"),
new Message("load[2]"),
new
Expression.MessageCall(
new Message("toInt[2]"),
new
),
Expression.Constant(1)
)
)
));
}
{
var program :=
"eval",
).compile();
▲ ^(tape){ o.eval(tape) }
}
}
▲const bf_program = "++++++++++[>+++++++>++++++++++>+++>+<<<<-]>++.>+.+++++++..+++.>++.<<+++++++++++++++.>.+++.------.--------.>+.>.";
public program()
{
var bfAssemblyProgram := new ScriptEngine() ▼
console.writeLine:bf_program;▼
▲ var bfAssemblyProgram := new ScriptEngine()
▲ .loadPath:"asmrules.es"
var bfProgram := TapeAssembler.load(bfAssemblyProgram).compiled();
▲ .eval(bf_program);
var
bfProgram(bfTape)
}</
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 180 ⟶ 204:
#define commands ::= $eof;
#define command ::= <=
#define command ::= <=
#define command ::= <=
#define command ::= <=
#define command ::= <=
#define command ::= <=
#define command ::= <=
#define command ::= <=
#define comment ::= " " comments;
Line 198 ⟶ 222:
#mode symbolic;
]]</
{{out}}
<pre>
++++++++++[>+++++++>++++++++++>+++>+<<<<-]>++.>+.+++++++..+++.>++.<<+++++++++++++++.>.+++.------.--------.>+.>.
Hello World!
|