expression-evaluation
Version:
Expression Evaluation
32 lines (31 loc) • 863 B
JavaScript
import { Node } from '../Node.js';
import { typeBoolean } from '../Type.js';
export class LoopNode extends Node {
_cnode;
_subnode;
constructor(frame, _cnode, _subnode) {
super(frame);
this._cnode = _cnode;
this._subnode = _subnode;
}
get type() {
return this._subnode.type;
}
compile(type) {
this._cnode = this._cnode.compile(typeBoolean);
this._subnode = this._subnode.compile(type);
return this;
}
evaluate() {
let value;
while (this._cnode.evaluate()) {
value = this._subnode.evaluate();
}
return value;
}
toString(ident = 0) {
return `${super.toString(ident)} loop node`
+ `, cnode:\n${this._cnode.toString(ident + 1)}`
+ `, subnode:\n${this._subnode.toString(ident + 1)}`;
}
}