pine

The pine programming language.


pine

/

src

/

pine.hh

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115
#ifndef OB_PINE_HH
#define OB_PINE_HH

#include <cmath>
#include <chrono>
#include <thread>
#include <limits>
#include <regex>
#include <map>
#include <functional>
#include <memory>
#include <fstream>
#include <sstream>
#include <iostream>
#include <vector>
#include <string>

namespace OB
{
class Regex : public std::regex
{
public:
  Regex(const char* cstr) : std::regex {cstr}, str_ {cstr} {}
  Regex(std::string str) : std::regex {str}, str_ {std::move(str)} {}

  bool operator<(const Regex &rhs) const noexcept
  {
    return str_ < rhs.str_;
  }

  std::string str() const
  {
    return str_;
  }

  friend std::ostream& operator<<(std::ostream& os, const Regex& obj);

private:
  std::string str_;
}; // class Regex

inline std::ostream& operator<<(std::ostream& os, const Regex& obj)
{
  os << obj.str_;
  return os;
}

class Pine
{
public:
  struct Debug
  {
    bool all {false};
    bool cmt {false};
    bool map {false};
    bool stk {false};
    bool lbl {false};
    bool flg {false};
    bool jmp {false};
    bool rgx {false};
    bool lne {false};
  };

  struct Return
  {
    bool now {false};
    int lne = 0;
  };

  struct Jump
  {
    bool now {false};
    std::string lbl;
  };

  struct Flags
  {
    Return ret;
    Jump jmp;
    Debug dbg;
    int cmp {0};
  };

  struct Label
  {
    int line {0};
  };

  struct Instruction
  {
    std::string key;
    std::string value;
    std::string type;
  };

  Pine();
  ~Pine();

  void set_file(std::string const _file);
  int run();

private:
  std::string file_main_;

  Flags flg;
  std::vector<Instruction> stk;
  std::vector<int> cst;
  std::map<std::string, Label> lbl;
  std::map<std::string, Instruction> smap;

};

} // namespace OB

#endif // OB_PINE_HH
Back to Top