|
@@ -0,0 +1,104 @@
|
|
|
+#ifndef ALTPARSER_H
|
|
|
+#define ALTPARSER_H
|
|
|
+
|
|
|
+#include <iostream>
|
|
|
+
|
|
|
+
|
|
|
+enum class Instruction : char
|
|
|
+{
|
|
|
+ PLUS,
|
|
|
+ MINUS,
|
|
|
+ LEFT,
|
|
|
+ RIGHT,
|
|
|
+ DOT,
|
|
|
+ COMMA,
|
|
|
+ LEFT_PARAN,
|
|
|
+ RIGHT_PARAN
|
|
|
+ INVALID
|
|
|
+};
|
|
|
+
|
|
|
+
|
|
|
+struct BfIterator
|
|
|
+{
|
|
|
+ std::istream& source;
|
|
|
+ Instruction currentInst;
|
|
|
+
|
|
|
+ inline BfIterator& operator++(void)
|
|
|
+ {
|
|
|
+ while (!source.eof()) {
|
|
|
+ int chr = source.get();
|
|
|
+ switch (chr) {
|
|
|
+ case '+':
|
|
|
+ currentInst = Instruction::PLUS;
|
|
|
+ return *this;
|
|
|
+ case '-':
|
|
|
+ currentInst = Instruction::MINUS;
|
|
|
+ return *this;
|
|
|
+ case '<':
|
|
|
+ currentInst = Instruction::LEFT;
|
|
|
+ return *this;
|
|
|
+ case '>':
|
|
|
+ currentInst = Instruction::RIGHT;
|
|
|
+ return *this;
|
|
|
+ case '.':
|
|
|
+ currentInst = Instruction::PLUS;
|
|
|
+ return *this;
|
|
|
+ case ',':
|
|
|
+ currentInst = Instruction::PLUS;
|
|
|
+ return *this;
|
|
|
+ case '[':
|
|
|
+ currentInst = Instruction::LEFT_PARAN;
|
|
|
+ return *this;
|
|
|
+ case ']':
|
|
|
+ currentInst = Instruction::RIGHT_PARAN;
|
|
|
+ return *this;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ currentInst = Instruction::INVALID;
|
|
|
+ return *this;
|
|
|
+ }
|
|
|
+
|
|
|
+ inline Instruction operator*(void) const
|
|
|
+ {
|
|
|
+ return currentInst;
|
|
|
+ }
|
|
|
+
|
|
|
+ inline bool operator != (const BfIterator& other) {
|
|
|
+ return other.source.eof() != source.eof();
|
|
|
+ }
|
|
|
+};
|
|
|
+
|
|
|
+
|
|
|
+typename<template Dispatcher>
|
|
|
+struct LoopIterator
|
|
|
+{
|
|
|
+ BfIterator it;
|
|
|
+ Dispatcher& d;
|
|
|
+
|
|
|
+ LoopIterator& operator++(void)
|
|
|
+ {
|
|
|
+ d(Block());
|
|
|
+ }
|
|
|
+
|
|
|
+ // until ']'
|
|
|
+ //
|
|
|
+ // calls d.loop() and d.block()
|
|
|
+};
|
|
|
+
|
|
|
+
|
|
|
+struct BlockIterator
|
|
|
+{
|
|
|
+ BfIterator it;
|
|
|
+ // iterate, until special character
|
|
|
+};
|
|
|
+
|
|
|
+
|
|
|
+class BlockParser
|
|
|
+{
|
|
|
+public:
|
|
|
+ BfIterator
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+#endif /* ALTPARSER_H */
|