-
Notifications
You must be signed in to change notification settings - Fork 0
/
MachineParser.h
43 lines (32 loc) · 1.37 KB
/
MachineParser.h
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
#pragma once
#include <iostream>
#include <algorithm>
#include "MachineBuilder.h"
using std::cout;
using std::cin;
using std::cerr;
using std::endl;
using std::getline;
using std::set_difference;
using std::istream;
typedef pair<state_pair, state_tuple> transition;
class MachineParser {
public:
MachineParser(MachineBuilder* builder = nullptr) : builder(builder) {}
void parseFromConsole();
void parseFromFile(istream&);
private:
MachineBuilder* builder;
symbol_set& parseSymbolsLine(string line);
symbol_set& parseFileSymbolsLine(string line);
void readSymbolsFromConsole(symbol_set& sigma, symbol_set& gamma, char blank_symbol);
void readStatesFromConsole(state_map&, string&, string&, unsigned);
void readTransitionsFromConsole(transitions_map&, symbol_set&, state_map&, unsigned);
transition parseTransition(symbol_set&, state_map&, size_t number, bool console, istream& is);
bool symbolSetsAreCorrect(symbol_set& sigma, symbol_set& gamma, char blank_symbol);
bool tapeIsCorrect(Tape& tape, symbol_set& gamma, char blank_symbol);
bool isLineForStartingState(string& line) { return (line.substr(0, 9) == "Starting:"); }
bool isLineForCurrentState(string& line) { return (line.substr(0, 8) == "Current:"); }
string getAfterColumn(string& s);
void printFileErrorMessage() { cerr << RED_TEXT << "Loading machine from file was not successful!" << '\n' << RESET_COLORING; }
};