view parser.h @ 13:d179b0bb85e4

make lexer a member function in parser class and eliminate some more global variables
author John W. Eaton <jwe@octave.org>
date Thu, 23 May 2019 18:26:35 -0400
parents 894be158b32d
children
line wrap: on
line source

#if ! defined (calc_parse_h)
#define calc_parse_h 1

namespace calc
{
  class interpreter;

  class parser
  {
  public:

    parser (interpreter&);

    parser (const parser&) = delete;

    parser& operator = (const parser&) = delete;

    ~parser (void);

    bool beg_of_stmt (void) const { return m_beg_of_stmt; }

    void beg_of_stmt (bool flag) { m_beg_of_stmt = flag; }

    int parse_and_execute (const std::string& line);

    void emit_error (const char *msg) const;

    void emit_result (double value) const;

  private:

    int lexer (double& token_value);

    interpreter& m_interpreter;

    void *m_parser_state;

    bool m_beg_of_stmt;

    // Auxiliary variables for lexing.
    size_t m_bufptr = 0;
    size_t m_chunk_size = 0;
    const char *m_buf;
  };
}

#endif