12345678910111213141516171819202122232425262728293031 |
- 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,
- '=': (a, b) => a === b,
- '>': (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
- }
- }
|