Exemplo n.º 1
0
_production_ast handle_production(string& input, Production& p, Chart& chart)
{
  int64_t setIndex;
  size_t stateIndex;
  Production production;
  _production_ast out = _production_ast();
  //No cases so no switch
  //non_terminal option ws ":=" ws rhs

  tie(setIndex, stateIndex) = p.symbolInfo(0);
  production = chart.getState(setIndex, stateIndex).first;
  _non_terminal_ast name = handle_non_terminal(input, production, chart);

  out.name_ = name;

  tie(setIndex, stateIndex) = p.symbolInfo(1);
  if(setIndex > 0) { //If it has a negative setIndex it was skipped
    production = chart.getState(setIndex, stateIndex).first;
    _option_ast option = handle_option(input, production, chart);

    if (option == "nullable") {
      out.nullable_ = true;
    } else {
      out.nullable_ = false;
    }
  }

  tie(setIndex, stateIndex) = p.symbolInfo(5);
  production = chart.getState(setIndex, stateIndex).first;
  _rhs_ast rhs = handle_rhs(input, production, chart);

  out.sub_productions_ = rhs;

  return out;
}
Exemplo n.º 2
0
_file_ast handle_file(string& input, Production& p, Chart& chart)
{
  int64_t setIndex;
  size_t stateIndex;
  Production production;
  _production_ast p_ast;
  _file_ast out;
  switch (p.number()){
    case 0: //production ws ";" ws file
      //production
      tie(setIndex, stateIndex) = p.symbolInfo(0);
      production = chart.getState(setIndex, stateIndex).first;
      p_ast = handle_production(input, production, chart);
      //We don't care about whitespace or the symbol in this case
      tie(setIndex, stateIndex) = p.symbolInfo(4);
      production = chart.getState(setIndex, stateIndex).first;
      out = handle_file(input, production, chart);
      out.push_back(p_ast);
      return out;
    case 1: // production ws ";" ws
      //This is the terminal file make a new
      //production
      tie(setIndex, stateIndex) = p.symbolInfo(0);
      production = chart.getState(setIndex, stateIndex).first;
      p_ast = handle_production(input, production, chart);
      out = _file_ast({p_ast});
      return out;
    default:
      break;
  }
  return _file_ast{};
}
Exemplo n.º 3
0
_sub_production_ast handle_sub_production(string& input, Production& p, Chart& chart)
{
  int64_t setIndex;
  size_t stateIndex;
  Production production;
  _sub_production_ast out;
  _symbol_ast symbol;
  switch(p.number()){
    case 0: //symbol ws sub_production
      tie(setIndex, stateIndex) = p.symbolInfo(0);
      production = chart.getState(setIndex, stateIndex).first;
      symbol = handle_symbol(input, production, chart);

      //Skip ws
      tie(setIndex, stateIndex) = p.symbolInfo(2);
      production = chart.getState(setIndex, stateIndex).first;
      out = handle_sub_production(input, production, chart);

      out.insert(out.begin(), symbol);
      return out;
    case 1: //symbol
      tie(setIndex, stateIndex) = p.symbolInfo(0);
      production = chart.getState(setIndex, stateIndex).first;
      symbol = handle_symbol(input, production, chart);

      out.push_back(symbol);

      return out;
    default:;
  }
  return out;
}
Exemplo n.º 4
0
_rhs_ast handle_rhs(string& input, Production& p, Chart& chart)
{
  int64_t setIndex;
  size_t stateIndex;
  Production production;
  _rhs_ast out;
  _sub_production_ast subProd;
  switch(p.number()){
    case 0: //sub_production ws "|" ws rhs | sub_production
      tie(setIndex, stateIndex) = p.symbolInfo(0);
      production = chart.getState(setIndex, stateIndex).first;
      subProd = handle_sub_production(input, production, chart);

      tie(setIndex, stateIndex) = p.symbolInfo(4);
      production = chart.getState(setIndex, stateIndex).first;
      out = handle_rhs(input, production, chart);

      out.push_back(subProd);
      return out;
    case 1:
      tie(setIndex, stateIndex) = p.symbolInfo(0);
      production = chart.getState(setIndex, stateIndex).first;
      subProd = handle_sub_production(input, production, chart);

      out.push_back(subProd);
      return out;
    default:;
  }
  return out;
}
Exemplo n.º 5
0
//Handle symbols
_symbol_ast handle_symbol(string& input, Production& p, Chart& chart)
{
  int64_t setIndex;
  size_t stateIndex;
  Production production;
  _symbol_ast out;
  tie(setIndex, stateIndex) = p.symbolInfo(0);
  production = chart.getState(setIndex, stateIndex).first;
  out.value_ = handle_non_terminal(input, production, chart);
  switch(p.number()){
    case 0:
      out.type_ = _symbol_ast::type::NON_TERMINAL;
      break;
    case 1:
      out.type_ = _symbol_ast::type::TERMINAL;
      break;
    case 2:
      out.type_ = _symbol_ast::type::REGEX;
      break;
    default:;
  }
  return out;
}