Пример #1
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{};
}
Пример #2
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;
}
Пример #3
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;
}
Пример #4
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;
}
Пример #5
0
_option_ast handle_option(string& input, Production& p, Chart& chart)
{
  if (p.number() == 0) return "nullable";
  return "";
}