Execute Brain****/Elena: Difference between revisions

m
no edit summary
m (Fixed syntax highlighting.)
imported>Arakov
mNo edit summary
Line 1:
ELENA 56.0x:
<syntaxhighlight lang="elena">import system'collections;
import system'routines;
Line 11:
class TapeAssembler
{
Stack theBrackets_brackets;
List<Expression> theTape_tape;
constructor()
{
theBrackets_brackets := new Stack();
theTape_tape := new List<Expression>();
theTape_tape.append(Expression.DeclareAndAssigning(
new ScopeVariable("ptr"),
Expression.Constant(0)));
}
Line 31:
open()
{
theBrackets_brackets.push(theTape_tape);
theTape_tape := new List<Expression>();
}
Line 47:
Expression.Constant($0)
),
ExpressionCodeblockExpression.CodeBlocknew(theTape_tape.Value));
theTape_tape := theBrackets_brackets.pop();
theTape_tape.append(loop)
}
input()
{
theTape_tape.append(
Expression.MessageCall(
new Message("setAt[3]"),
Expression.Variable(new ScopeVariable("tape")),
Expression.Variable(new ScopeVariable("ptr")),
Expression.MessageCall(
new Message("readChar[1]"),
Expression.Constant(console)
)
)
)
Line 70:
output()
{
theTape_tape.append(
Expression.MessageCall(
new Message("write[2]"),
Line 76:
Expression.MessageCall(
new Message("at[2]"),
Expression.Variable(new ScopeVariable("tape")),
Expression.Variable(new ScopeVariable("ptr"))
)
)
Line 85:
next()
{
theTape_tape.append(
Expression.Assigning(
new ScopeVariable("ptr"),
Expression.MessageCall(
new Message("add[2]"),
Expression.Variable(new ScopeVariable("ptr")),
Expression.Constant(1))))
}
Line 96:
previous()
{
theTape_tape.append(
Expression.Assigning(
new ScopeVariable("ptr"),
Expression.MessageCall(
new Message("subtract[2]"),
Expression.Variable(new ScopeVariable("ptr")),
Expression.Constant(1))))
}
Line 107:
increase()
{
theTape_tape.append(
Expression.MessageCall(
new Message("setAt[3]"),
Line 134:
decrease()
{
theTape_tape.append(
Expression.MessageCall(
new Message("setAt[3]"),
Line 161:
compiled()
{
var program := DynamicSingleton.newload(
Expression.Method(
"eval",
CodeblockExpression.new ScopeVariable("tape"_tape.Value),
ExpressionScopeIdentifier.CodeBlockVariable(theTape.Value"tape"))).compiled();
).compile();
^(tape){ program.eval(tape) }
Line 188 ⟶ 189:
#grammar cf
 
#define start ::= <= system'dynamic'ClosureTape ( => command commands <= ) =>;
<=
system'dynamic'DynamicTape (
system'dynamic'AllocFunction ( "1" )
system'dynamic'LocalFunction ( "2" ) => command commands
<= ) =>;
 
#define start ::= $eof;
 
Line 195 ⟶ 202:
#define commands ::= $eof;
 
#define command ::= <= system'dynamic'MessageClosureMessageFunction ( "output[1]" ) => ".";
#define command ::= <= system'dynamic'MessageClosureMessageFunction ( "input[1]" ) => ",";
#define command ::= <= system'dynamic'MessageClosureMessageFunction ( "previous[1]" ) => "<";
#define command ::= <= system'dynamic'MessageClosureMessageFunction ( "next[1]" ) => ">";
#define command ::= <= system'dynamic'MessageClosureMessageFunction ( "increase[1]" ) => "+";
#define command ::= <= system'dynamic'MessageClosureMessageFunction ( "decrease[1]" ) => "-";
#define command ::= <= system'dynamic'MessageClosureMessageFunction ( "open[1]" ) => "[";
#define command ::= <= system'dynamic'MessageClosureMessageFunction ( "close[1]" ) => "]";
 
#define comment ::= " " comments;
Anonymous user