Exemplo n.º 1
0
/*
 * Fa il parsing della RHS della regola
 */
list<PredicateCall>
Parser::parse_rule_rhs(list<Token> token_list) {
  list<Token>::iterator token_iterator = token_list.begin();
  list<Token> predicate_tokens;
  list<PredicateCall> rhs;
  uint32_t read_tokens = 0;

  if (token_iterator == token_list.end())
    throw ParseError("empty right hand side");

  while (token_iterator != token_list.end()) {
    predicate_tokens = BUILD_TOKEN_BLOCK(token_iterator, string(1, LNG_STMT_END).c_str(), TKN_OPERATOR, token_list.end());
    Predicate pred = this->parse_predicate(predicate_tokens, predicate_tokens.begin(), &read_tokens);
    token_iterator = this->advance_iterator(token_iterator, read_tokens);
    ++token_iterator;
    read_tokens = 0;

    if ((token_iterator->get_type() == TKN_OPERATOR) &&
        (!token_iterator->get_value().compare(string(1, LNG_STMT_END)))) {
      ++token_iterator;
    } else if (token_iterator == token_list.end()) {
      throw ParseError("expected ; as predicate separator", (*(--token_iterator)).get_line_no());
    }

    PredicateCall call;
    call.set_name(pred.get_name());
    call.set_parameters(pred.get_parameters());
    rhs.push_back(call);
  }
  return rhs;
};
Exemplo n.º 2
0
/* Estra i nomi delle variabili da un predicato */
queue<string>
_extract_variables(Predicate p) {
  vector<PredicateParam> parameters = p.get_parameters();
  queue<string> varnames;
  unsigned int i;

  for (i = 0; i < parameters.size(); i++) {
    if (parameters[i].get_type() == PARAM_VAR)
      varnames.push(parameters[i].get());
  }

  return varnames;
};