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

no edit summary
No edit summary
No edit summary
Line 1:
<lang elena>#define system.
#define system'routines.
#define extensions'text.
 
// --- Tape ---
 
#class TapeBFTape
{
#field theArray.
#field thePointer.
 
#constructor new &type'length:aLength
[
thePointer := Integer new:0.
 
theArray := ArrayarrayControl new &type'length:aLength &functioneach: &&:n [ Integer new:0 ].
]
 
#method type'tapebf_tape = $self.
 
#method append
Line 40 ⟶ 41:
#method input
[
(theArray@thePointer) write &type'int:(console readChar).
]
Line 69 ⟶ 70:
]
#method type'tapebf_tape = theTape type'tapebf_tape.
 
#method append
Line 103 ⟶ 104:
#method repeatUntil
[
theTape run: &&:aTape [ interpreter'Interpreter new:aTape eval:theLoopBody ].
^ theTape.
Line 125 ⟶ 126:
]
#method eval &type'widestrliteral:aLiteral
[
control foreach:aLiteral &do:$self.
]
 
#method eval &widecharchar:aChar
[
aChar =>
Line 148 ⟶ 149:
#symbol program =
[
('program'arguments Countlength == 1)?
[ console write:"Please provide the path to the file to interpret". #throw BreakException new. ].
textFileControl forEachLine:('program'arguments@1) &do:(Interpreter new:(TapeBFTape new &type'length:1024)).
].</lang>
</lang>
Anonymous user