<commit_before>/**
\file translation_control.hpp
\brief Defines class TranslationControl and its methods.
\author <NAME>
*/
#ifndef CTF_TRANSLATION_CONTROL
#define CTF_TRANSLATION_CONTROL

#include "lexical_analyzer.hpp"
#include "ll_table.hpp"
#include "translation_grammar.hpp"

namespace ctf {
/**
\brief Abstract class for syntax driven translation control.
*/
class TranslationControl {
 protected:
  /**
  \brief Alias for TranslationGrammar::Rule
  */
  using Rule = TranslationGrammar::Rule;

  /**
  \brief Lexical analyzer for getting tokens from input.
  */
  LexicalAnalyzer *lexicalAnalyzer_ = nullptr;
  /**
  \brief Translation grammar defining the input and output languages.
  */
  const TranslationGrammar *translationGrammar_ = nullptr;
  /**
  \brief Tstack of input symbols.
  */
  tstack<Symbol> input_;
  /**
  \brief Tstack of output symbols.
  */
  tstack<Symbol> output_;
  /**
  \brief Error flag.
  */
  bool errorFlag_ = false;
  /**
  \brief Returns the next token obtained from lexicalAnalyzer_.
  */
  Symbol next_token() { return lexicalAnalyzer_->get_token(); }

 public:
  virtual ~TranslationControl() = default;

  /**
  \brief Resets translation state.
  */
  void reset() noexcept { clear_error(); }
  virtual bool error() const { return errorFlag_; }
  /**
  \brief Clears the error flag.
  */
  virtual void clear_error() noexcept { errorFlag_ = false; }
  /**
  \returns String with appropriate error message. Is only to be called when
  error() is true.
  */
  virtual string error_message() { return "Something went wrong.\n"; }
  /**
  \brief Sets lexical analyzer.
  \param[in] la LexicalAnalyzer to be set.
  */
  virtual void set_lexical_analyzer(LexicalAnalyzer &la) {
    lexicalAnalyzer_ = &la;
  }
  /**
  \brief Sets translation grammar.
  \param[in] tg Translation grammar to be set.
  */<commit_msg>next_token made virtual in translation_control<commit_after>/**
\file translation_control.hpp
\brief Defines class TranslationControl and its methods.
\author <NAME>
*/
#ifndef CTF_TRANSLATION_CONTROL
#define CTF_TRANSLATION_CONTROL

#include "lexical_analyzer.hpp"
#include "ll_table.hpp"
#include "translation_grammar.hpp"

namespace ctf {
/**
\brief Abstract class for syntax driven translation control.
*/
class TranslationControl {
 protected:
  /**
  \brief Alias for TranslationGrammar::Rule
  */
  using Rule = TranslationGrammar::Rule;

  /**
  \brief Lexical analyzer for getting tokens from input.
  */
  LexicalAnalyzer *lexicalAnalyzer_ = nullptr;
  /**
  \brief Translation grammar defining the input and output languages.
  */
  const TranslationGrammar *translationGrammar_ = nullptr;
  /**
  \brief Tstack of input symbols.
  */
  tstack<Symbol> input_;
  /**
  \brief Tstack of output symbols.
  */
  tstack<Symbol> output_;
  /**
  \brief Error flag.
  */
  bool errorFlag_ = false;
  /**
  \brief Returns the next token obtained from lexicalAnalyzer_.
  */
  virtual Symbol next_token() { return lexicalAnalyzer_->get_token(); }

 public:
  virtual ~TranslationControl() = default;

  /**
  \brief Resets translation state.
  */
  void reset() noexcept { clear_error(); }
  virtual bool error() const { return errorFlag_; }
  /**
  \brief Clears the error flag.
  */
  virtual void clear_error() noexcept { errorFlag_ = false; }
  /**
  \returns String with appropriate error message. Is only to be called when
  error() is true.
  */
  virtual string error_message() { return "Something went wrong.\n"; }
  /**
  \brief Sets lexical analyzer.
  \param[in] la LexicalAnalyzer to be set.
  */
  virtual void set_lexical_analyzer(LexicalAnalyzer &la) {
    lexicalAnalyzer_ = &la;
  }
  /**
  \brief Sets translation grammar.
  \param[in] tg Translation grammar to be set.
  */
{'fraction_non_alphanumeric': 0.10829554547879434, 'fraction_numerical': 0.0, 'mean_word_length': 3.5509708737864076, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '896517', 'n_tokens_mistral': 1176, 'n_tokens_neox': 1135, 'n_words': 357}