Anonymous user
Execute Brain****/Elena: Difference between revisions
m
no edit summary
mNo edit summary |
mNo edit summary |
||
Line 1:
<lang elena>import system'collections;
import system'routines;
import system'dynamic'expressions;
import extensions;
import extensions'scripting;
const bf_program = "++++++++++[>+++++++>++++++++++>+++>+<<<<-]>++.>+.+++++++..+++.>++.<<+++++++++++++++.>.+++.------.--------.>+.>.";▼
class TapeAssembler
{
Stack
List<
constructor()
{
theBrackets := new Stack();
theTape := new List<
theTape.append(
new ScopeVariable("ptr"),
Expression.Constant(0)));
}
constructor load(assembly_program)
▲ <= ()
{
assembly_program(self)
}
open()
{
theBrackets.push(theTape);
theTape := new List<
}
close()
{
var loop :=
new Message("at[2]"),
),
theTape := theBrackets.pop();
theTape.append(loop)
}
input()
{
theTape.append
new
Expression.Variable(new
new
)
)
)
}
output()
{
theTape.append
Expression.MessageCall(
▲ TapeExpression.Constant(console),
new
new
Expression.Variable(new
)
)
)
}
next()
{
theTape.append
new Message("add[2]"),
Expression.Constant(1))))
}
previous()
{
theTape.append
new Message("subtract[2]"),
Expression.Constant(1))))
}
increase()
{
theTape.append
new Message("setAt[3]"),
new Message("load[2]"),
new
Expression.MessageCall(
new Message("toInt[2]"),
new
),
Expression.Constant(1)
)
)
));
}
decrease()
{
theTape.append
new Message("setAt[3]"),
new Message("load[2]"),
new
Expression.MessageCall(
new Message("toInt[2]"),
new
),
Expression.Constant(1)
)
)
));
}
{
var program :=
"eval",
}
}
▲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();
var
bfProgram(bfTape)
}</lang>
The grammar:
<lang elena>[[
#grammar
#grammar cf
#define start ::= <= system'dynamic'ClosureTape (
#define start ::= $eof;
#define commands ::= command commands;
Line 180 ⟶ 194:
#define commands ::= $eof;
#define command ::= <=
#define command ::= <=
#define command ::= <=
#define command ::= <=
#define command ::= <=
#define command ::= <=
#define command ::= <=
#define command ::= <=
#define comment ::= " " comments;
Line 201 ⟶ 215:
{{out}}
<pre>
++++++++++[>+++++++>++++++++++>+++>+<<<<-]>++.>+.+++++++..+++.>++.<<+++++++++++++++.>.+++.------.--------.>+.>.
Hello World!
|