VaKeR CYBER ARMY
Logo of a company Server : Apache/2.4.41 (Ubuntu)
System : Linux absol.cf 5.4.0-198-generic #218-Ubuntu SMP Fri Sep 27 20:18:53 UTC 2024 x86_64
User : www-data ( 33)
PHP Version : 7.4.33
Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
Directory :  /var/www/html/libs/absol-full/dist/js/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /var/www/html/libs/absol-full/dist/js/mdls__absol-form__js__sclang__SCExpressionCaller.js
/*** module: node_modules/absol-form/js/sclang/SCExpressionCaller.js ***/
"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.evalSCExpression = evalSCExpression;
exports.default = void 0;

var _SCBinaryOperators = require("./SCBinaryOperators");

var _SCParser = _interopRequireDefault(require("./SCParser"));


/***
 *
 * @param {{}} ast
 * @param {{}}env
 * @constructor
 */
function SCExpressionCaller(ast, env) {
  this.ast = ast;
  this.env = {};

  if (env instanceof Array) {
    env.reduce(function (ac, subEnv) {
      Object.assign(ac, subEnv);
      return ac;
    });
  } else {
    Object.assign(this.env, env);
  }
}

SCExpressionCaller.prototype.exec = function () {
  return this.accept(this.ast);
};

SCExpressionCaller.prototype.accept = function (node) {
  var vf = this.visitor[node.type];

  if (vf) {
    return vf(node, this);
  } else {
    console.error("Node error:", node);
  }
};

SCExpressionCaller.prototype.visitor = {
  NumericLiteral: function (node, caller) {
    return parseFloat(node.value);
  },
  BinaryExpression: function (node, caller) {
    var leftValue = caller.accept(node.left);
    var rightValue = caller.accept(node.right);
    var fun = caller.binaryOperator2Function[node.operator];
    return fun(leftValue, rightValue);
  },
  UnaryExpression: function (node, caller) {
    var fun = caller.unaryOperator2Function[node.operator];
    var arg = caller.accept(node.argument);
    return fun(arg);
  },
  Identifier: function (node, caller) {
    return caller.env[node.name];
  },
  CallExpression: function (node, caller) {
    var calleeFunction = caller.accept(node.callee);
    var argumentValues = node.arguments.map(function (exp) {
      return caller.accept(exp);
    });
    return calleeFunction.apply(null, argumentValues);
  }
};
SCExpressionCaller.prototype.binaryOperator2Function = {
  '+': _SCBinaryOperators.ADD,
  '-': _SCBinaryOperators.SUB,
  '*': _SCBinaryOperators.MUL,
  '/': _SCBinaryOperators.DIV
};
SCExpressionCaller.prototype.unaryOperator2Function = {
  '+': _SCBinaryOperators.POSITIVE,
  '-': _SCBinaryOperators.NEGATIVE
};

function evalSCExpression(code, env) {
  var parsed = _SCParser.default.parse(code, 'exp');

  var caller;

  if (parsed.ast) {
    caller = new SCExpressionCaller(parsed.ast, env);
    return caller.exec();
  } else {
    throw parsed.error;
  }
}

var _default = SCExpressionCaller;
exports.default = _default;

VaKeR 2022