Example #1
0
std::set<int> getValues(Lexer& p, int first, int last, const int altstring)
{
  int mod = 1;
  set<int> values;

  if (p.token == "*")
    {
      p.nextToken();
      if (p.token == "/")
        {
          p.nextToken();
          mod = p.getInt();
          if (mod <= 0)
            throw Exception("Range", string("Modulo value invalid ") + to_string(mod));
        }
      for (int i = first; i <= last; i += mod)
        values.insert(i);
    }
  else
    {
      int s = getNr(p, altstring);
      if (s < first || s > last)
        throw Exception("Range", "value out of range");
      if (p.token != "-")
        values.insert(s);
      else
        {
          p.nextToken();
          // cout << p.token << endl;
          int e =  getNr(p, altstring);
          if (e < s || e > last)
            throw Exception("Range", "end value out of range");
          if (p.token == "/")
            {
              p.nextToken();
              mod = p.getInt();
            }
          for (int i = s; i <= e; i += mod)
            values.insert(i);
        }
    }
  return values;
}
Example #2
0
int getNr(Lexer& p, int altstring)
{
  if (p.type == Lexer::integer)
    return p.getInt();
  else if (altstring != 0 && p.type == Lexer::identifier)
    {
      string w = p.getWord();
      int res = getNr(w, altstring == 1 ? weekDayString : monthString);
      return res;
    }
  else
    throw Exception("getNr", "int or identifier expected");
}