|
@@ -0,0 +1,59 @@
|
|
|
+#ifndef ZP_PARSER_H
|
|
|
+#define ZP_PARSER_H
|
|
|
+
|
|
|
+#include <iostream>
|
|
|
+#include <vector>
|
|
|
+#include <memory>
|
|
|
+
|
|
|
+namespace zp
|
|
|
+{
|
|
|
+ struct Instruction;
|
|
|
+ struct UnaryInstruction;
|
|
|
+ struct Loop;
|
|
|
+
|
|
|
+ class Parser;
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+struct zp::Instruction
|
|
|
+{
|
|
|
+ virtual ~Instruction(void) = default;
|
|
|
+};
|
|
|
+
|
|
|
+
|
|
|
+struct zp::UnaryInstruction :
|
|
|
+ public Instruction
|
|
|
+{
|
|
|
+ enum class Type : char
|
|
|
+ {
|
|
|
+ INC,
|
|
|
+ DEC,
|
|
|
+ LEFT,
|
|
|
+ RIGHT,
|
|
|
+ POINT,
|
|
|
+ COMMA
|
|
|
+ };
|
|
|
+
|
|
|
+ Type type;
|
|
|
+};
|
|
|
+
|
|
|
+
|
|
|
+struct zp::Loop :
|
|
|
+ public Instruction
|
|
|
+{
|
|
|
+ std::vector<std::unique_ptr<Instruction>> instructions;
|
|
|
+};
|
|
|
+
|
|
|
+
|
|
|
+class zp::Parser
|
|
|
+{
|
|
|
+ std::istream& in;
|
|
|
+ Loop program;
|
|
|
+public:
|
|
|
+ Parser(std::istream& in);
|
|
|
+
|
|
|
+ void parse(void);
|
|
|
+};
|
|
|
+
|
|
|
+#endif /* ZP_PARSER_H */
|
|
|
+
|