Пример #1
0
bool ast_fun_def::is_valid(symbol_table& sym)
{
  bool res = true;

  if (sym.get_fun_def(_id) != nullptr)
  {
    cerr << MYLANGA_PARSE_ERROR(_ln) << " | " << \
      "La función \'" << *_id << "\' ya está definida." << endl;
    res = false;
  }

  if (has_repeated_elements(_ids))
  {
    cerr << MYLANGA_PARSE_ERROR(_ln) << " | " << \
      "La función \'" << *_id << "\' contiene parámetros repetidos en su definición." << endl;
    res = false;
  }

  // para soportar recursión
  sym.define_fun(shared_from_this());
  sym.open_scope();

  for (auto _id : *_ids)
    sym.declare_var(_id);

  res = _bl->is_valid(sym) and res;

  sym.close_scope();
  sym.undefine_fun(shared_from_this());

  return res;
}
Пример #2
0
bool ast_var_assign_stmt::is_valid(symbol_table& sym)
{
  bool res = true;
  res = _ex->is_valid(sym) and res;

  sym.declare_var(_id);

  return res;
}
Пример #3
0
bool ast_plot_cmd::is_valid(symbol_table& sym)
{
  bool res = true;

  sym.open_scope();

  do
  {
    res = _ex1->is_valid(sym) and res;
    res = _ex2->is_valid(sym) and res;
    res = _ex3->is_valid(sym) and res;
    if (not res) break;

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

    if (not (range_from <= range_to and 0 < range_step))
    {
      cerr << MYLANGA_PARSE_ERROR(_ln) << " | " << \
        "En la instrucción de plot, el rango de evaluación es inválido; un rango válido a..d..b debe cumplir a <= b y 0 < d." << endl;
      res = false;
    }

    if (not (_ex_x->is_plottable() and _ex_y->is_plottable()))
    {
      cerr << MYLANGA_PARSE_ERROR(_ln) << " | " << \
        "En la instrucción de plot, las expresiones a evaluar deben ser de tipo llamado a función." << endl;
      res = false;
    }

    sym.declare_var(_id);

    res = _ex_x->is_valid(sym) and res;
    res = _ex_y->is_valid(sym) and res;

  } while (false);

  sym.close_scope();

  return res;
}