1234567891011121314151617181920212223242526 |
- module.exports = class Env {
- constructor(parent = null) {
- if (parent) {
- this.data = parent.data
- } else {
- this.data = {
- '+': (a, b) => a + b,
- '-': (a, b) => a - b,
- '*': (a, b) => a * b,
- '/': (a, b) => a / b,
- }
- }
- }
-
- get(symbol) {
- if (this.data[symbol]) {
- return this.data[symbol]
- }
-
- throw `Symbol ${symbol} is not bound`
- }
-
- set(symbol, value) {
- this.data[symbol] = value
- }
- }
|