diff parser.h @ 12:894be158b32d

define parser as a class and eliminate some global variables
author John W. Eaton <jwe@octave.org>
date Thu, 23 May 2019 17:57:20 -0400
parents 0e154787183d
children d179b0bb85e4
line wrap: on
line diff
--- a/parser.h	Thu May 23 13:42:57 2019 -0400
+++ b/parser.h	Thu May 23 17:57:20 2019 -0400
@@ -1,14 +1,40 @@
 #if ! defined (calc_parse_h)
 #define calc_parse_h 1
 
-namespace parser
+namespace calc
 {
-  extern bool beg_of_stmt;
+  class interpreter;
+
+  class parser
+  {
+  public:
+
+    parser (interpreter&);
+
+    parser (const parser&) = delete;
+
+    parser& operator = (const parser&) = delete;
+
+    ~parser (void);
 
-  extern void init (void);
-  extern void fini (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;
 
-  extern int parse_and_execute (const std::string& line);
+    void emit_result (double value) const;
+
+  private:
+
+    interpreter& m_interpreter;
+
+    void *m_parser_state;
+
+    bool m_beg_of_stmt;
+  };
 }
 
 #endif