@adamsy/bhai-lang
Version:
<h1 align="center">Bhai Lang</h1> <p align="center"> <a href="https://lgtm.com/projects/g/DulLabs/bhai-lang/alerts/"><img alt="Total alerts" src="https://img.shields.io/lgtm/alerts/g/DulLabs/bhai-lang.svg?logo=lgtm&logoWidth=18"/></a> <a href="https://lgt
26 lines (20 loc) • 594 B
text/typescript
import parser from "bhai-lang-parser";
import InterpreterModule from "../module/interpreterModule";
import Scope from "./scope";
export default class Interpreter {
_parser: typeof parser;
_scope: Scope;
constructor(parserObj: typeof parser, scope: Scope) {
this._parser = parserObj;
this._scope = scope;
}
interpret(code: string) {
try {
const ast = this._parser.parse(code);
InterpreterModule.getVisitor(ast.type).visitNode(ast);
} finally {
// reset the scope for next run
InterpreterModule.setCurrentScope(new Scope(null));
}
}
}