74 lines
1.3 KiB
C++
74 lines
1.3 KiB
C++
//
|
|
// interpreter.hpp
|
|
// curly
|
|
//
|
|
// Created by Bob Polis at 2020-09-05
|
|
// Copyright (c) 2020 SwiftCoder. All rights reserved.
|
|
//
|
|
|
|
#ifndef _interpreter_H_
|
|
#define _interpreter_H_
|
|
|
|
#include <iostream>
|
|
#include <string>
|
|
#include <vector>
|
|
#include <map>
|
|
|
|
class interpreter {
|
|
public:
|
|
interpreter() = default;
|
|
|
|
std::string eval(std::istream& in);
|
|
|
|
private:
|
|
std::vector<std::string> _ops;
|
|
std::map<std::string, std::vector<std::string>> _funs;
|
|
|
|
// integer operations
|
|
void add();
|
|
void sub();
|
|
void mul();
|
|
void div();
|
|
void mod();
|
|
void abs();
|
|
void neg();
|
|
void dup();
|
|
void inc();
|
|
void dec();
|
|
|
|
// string operations
|
|
void rev();
|
|
void slc();
|
|
void idx();
|
|
void cat();
|
|
void len();
|
|
void rot();
|
|
|
|
// tests
|
|
void teq();
|
|
void tne();
|
|
void tlt();
|
|
void tle();
|
|
void tgt();
|
|
void tge();
|
|
|
|
// blocks
|
|
void end();
|
|
|
|
// conditionals
|
|
void ift();
|
|
void els();
|
|
|
|
// loops
|
|
void whl();
|
|
|
|
// functions
|
|
void fun();
|
|
void run();
|
|
|
|
// solution
|
|
void sol();
|
|
};
|
|
|
|
#endif // _interpreter_H_
|