diff options
| author | Syndamia <kamen@syndamia.com> | 2022-11-29 19:02:10 +0200 |
|---|---|---|
| committer | Syndamia <kamen@syndamia.com> | 2022-11-29 19:02:10 +0200 |
| commit | 83c7854b3f6e60d6e3c430b9c3dd59b3773c4ef2 (patch) | |
| tree | 08511019dfa78f49c9ecddde864186a7fa81cf5f /src/PolishNotationParser.h | |
| parent | 6f5fe499c2ba09057f3462edaeccfee5cc6f25a4 (diff) | |
| download | arzu-interpreter-83c7854b3f6e60d6e3c430b9c3dd59b3773c4ef2.tar arzu-interpreter-83c7854b3f6e60d6e3c430b9c3dd59b3773c4ef2.tar.gz arzu-interpreter-83c7854b3f6e60d6e3c430b9c3dd59b3773c4ef2.zip | |
Added a somewhat working version of the parser
Diffstat (limited to 'src/PolishNotationParser.h')
| -rw-r--r-- | src/PolishNotationParser.h | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/src/PolishNotationParser.h b/src/PolishNotationParser.h new file mode 100644 index 0000000..1de6f26 --- /dev/null +++ b/src/PolishNotationParser.h @@ -0,0 +1,40 @@ +#ifndef ARZU_INTERPRETER_PARSER +#define ARZU_INTERPRETER_PARSER + +#include <list> +#include <deque> +#include <string> +#include <fstream> +#include "Memory.h" +using namespace std; + +struct Instruction { + string name; + unsigned argc; + void (*exec)(Memory&); + + Instruction(const char* str, unsigned argc, void (*exec)(Memory&)); +}; + +struct Atom { + bool (*isAtomChar)(char); + MemoryData* (*absorb)(ifstream&); + + Atom(bool (*isAtomChar)(char), MemoryData* (*absorb)(ifstream&)); +}; + +class PNParser { + deque<Instruction> instr; + list<Atom> atoms; + + void evaluateFunction(Memory& mem, Function* func, ifstream& inFile); + void pushToWork(Memory& mem, MemoryData* data, ifstream& inFile); + void parseScope(ifstream& inFile, Memory& mem, int start, int end); +public: + PNParser() = default; + void addInstr(Instruction); + void addAtom(Atom); + void parse(ifstream&, Memory&); +}; + +#endif |
