Пример #1
0
fp_t ast_fun_call_expr::eval(symbol_table& sym)
{
  list<fp_t> args;
  for (auto _ex : *_exs)
    args.push_back(_ex->eval(sym));

  sym.open_scope();

  ptr<ast_fun_def> _fd = sym.get_fun_def(_id);
  
  auto arg_it = args.begin();
  for (auto _param_id : *(_fd->_ids))
    sym.set_var(_param_id, *arg_it++);

  maybe_fp_t ret = _fd->_bl->exec(sym);

  sym.close_scope();

  if (not ret.is_valid)
  {
    // runtime error
    cerr << MYLANGA_RUNTIME_ERROR << " | " << \
      "La función \'" << *_id << "\' se ejecutó sin retornar un valor." << endl;
    MYLANGA_END_ABRUPTLY();
  }

  return ret.value;
}
Пример #2
0
void ast_plot_cmd::plot(symbol_table& sym)
{
  sym.open_scope();

  fp_t range_from = _ex1->eval(sym),
  range_step = _ex2->eval(sym),
  range_to = _ex3->eval(sym);

  for (fp_t x = range_from; x <= range_to; x += range_step)
  {
    sym.set_var(_id, x);

    fp_t x_value = _ex_x->eval(sym),
    y_value = _ex_y->eval(sym);

    cout << x_value << " " << y_value << endl;

  }

  sym.close_scope();
}
Пример #3
0
maybe_fp_t ast_var_assign_stmt::exec(symbol_table& sym)
{
  sym.set_var(_id, _ex->eval(sym));

  return maybe_fp_t();
}