-
Notifications
You must be signed in to change notification settings - Fork 1
/
MFST.h
132 lines (113 loc) · 5.27 KB
/
MFST.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#pragma once
#include <stack>
#include "Greibach.h"
#include "LT.h"
#include <iomanip>
class my_stack_SHORT :public std::stack<short> {
public:
using std::stack<short>::c; // ñòåê àâòîìàòà
};
#define MFST_DIAGN_MAXSIZE 2*ERROR_MAXSIZE_MESSAGE
#define MFST_DIAGN_NUMBER 3
static int FST_TRACE_n = -1;
static char rbuf[205], sbuf[205], lbuf[1024];
#define MFST_TRACE_START std::cout<< std::setw(4)<<std::left<<"Øàã"<<":"\
<< std::setw(20)<<std::left<<" Ïðàâèëî"\
<< std::setw(30)<<std::left<<" Âõîäíàÿ ëåíòà"\
<< std::setw(20)<<std::left<<" Ñòåê"\
<< std::endl;
#define MFST_TRACE1 std::cout<< std::setw(4)<<std::left<<++FST_TRACE_n<<": "\
<< std::setw(20)<<std::left<<rule.getCRule(rbuf,nrulechain)\
<< std::setw(30)<<std::left<<getCLenta(lbuf,lenta_position)\
<< std::setw(20)<<std::left<<getCSt(sbuf)\
<< std::endl;
#define MFST_TRACE2 std::cout<< std::setw(4)<<std::left<<FST_TRACE_n<<": "\
<< std::setw(20)<<std::left<<" "\
<< std::setw(30)<<std::left<<getCLenta(lbuf,lenta_position)\
<< std::setw(20)<<std::left<<getCSt(sbuf)\
<< std::endl;
#define MFST_TRACE3 std::cout<< std::setw(4)<<std::left<<++FST_TRACE_n<<": "\
<< std::setw(20)<<std::left<<" "\
<< std::setw(30)<<std::left<<getCLenta(lbuf,lenta_position)\
<< std::setw(20)<<std::left<<getCSt(sbuf)\
<< std::endl;
#define MFST_TRACE4(c) std::cout<<std::setw(4)<<std::left << ++FST_TRACE_n << ": "<<std::setw(20)<< std::left <<c<<std::endl;
#define MFST_TRACE5(c) std::cout<<std::setw(4)<<std::left << FST_TRACE_n << ": "<<std::setw(20)<< std::left <<c<<std::endl;
#define MFST_TRACE6(c,k) std::cout<<std::setw(4)<<std::left << FST_TRACE_n << ": "<<std::setw(20)<< std::left << c << k <<std::endl;
#define MFST_TRACE7 std::cout<<std::setw(4)<<std::left << state.lenta_position << ": "\
<<std::setw(20)<< std::left << rule.getCRule(rbuf,state.nrulechain)\
<<std::endl;
typedef my_stack_SHORT MFSTSTSTACK;
namespace MFST
{
struct MfstState //ñîñòîÿíèå àâòîìàòà äëÿ ñîõðàíåíèÿ
{
short lenta_position; //ñîñòîÿíèå àâòîìàòà äëÿ ñîõðàíåíèÿ
short nrule; //íîìåð òåêóùåãî ïðàâèëà
short nrulechain; //íîìåð òåêóùåé öåï÷êè, òåêóùåãî ïðàâèëà
MFSTSTSTACK st; //ñòåê àâòîìàòà
MfstState();
MfstState(short pposition, MFSTSTSTACK pst, short pnrulechain); //(ïîçèöèÿ íà ëåíòå;ñòåê àâòîìàòà; íîìåð òåêóùåé öåïî÷êè òåêóùåãî ïðàâèëà)
MfstState(short pposition, MFSTSTSTACK pst, short pnrule, short pnrulechain);//(ïîçèöèÿ íà ëåíòå;ñòåê àâòîìàòà; íîìåð òåêóùåãî ïðàâèëà; íîìåð òåêóùåé öåïî÷êè òåêóùåãî ïðàâèëà)
};
struct Mfst //ìàãàçèííûé àâòîìàò
{
enum RC_STEP { //êîä âîâçðàòà ôóíêöèè step
NS_OK, //íàéäåíî ïðàâèëî è öåïî÷êà, öåïî÷êà çàïèñàíà â ñòåê
NS_NORULE, //íå íàéäåíî ïðàâèëî ãðàììàòèêè(îøèáêà â ãðàììàòèêå)
NS_NORULECHAIN, //íå íàéäåíà ïîäõîäÿùàÿ öåïî÷êà ïðàâèëà(îøèáêà â èñõîäíîì êîäå)
NS_ERROR, //íåèçâåñòâíûé íåòåðìèíàëüíûé ñèìâîë ãðàììàòèêè
TS_OK, //òåê. ñèìâîë ëåíòû == âåðøèíå ñòåêà, ïðîäâèíóëàñü ëåíòà, pop ñòåêà
TS_NOK, //òåê. ñèìâîë ëåíòû != âåðøèíå ñòåêà, ïðîäâèíóëàñü ëåíòà, pop ñòåêà
LENTA_END, //òåêóùàÿ ïîçèöèÿ ëåíòû >= lenta_size
SURPRISE, //íåîæèäàííûé êîä âîçâðàòà (îøèáêà â step)
};
struct MfstDiagnosis //äèàãíîñòèêà
{
short lenta_position; //ïîçèöèÿ íà ëåíòå
RC_STEP rc_step; //êîä çàâåðøåíèÿ øàãà
short nrule; //íîìåð ïðàâèëà
short nrule_chain; //íîìåð öåïî÷êè ïðàâèëà
MfstDiagnosis(); //==
MfstDiagnosis(short plenta_position, RC_STEP prc_step, short pnrule, short pnrule_chain);
}diagnosis[MFST_DIAGN_NUMBER]; // ïîñëåäíèå ñàìûå ãëóáîêèå ñîîáùåíèÿ
class my_stack_MfstState :public std::stack<MfstState> {
public:
using std::stack<MfstState>::c;
};
GRBALPHABET* lenta; //ïåðåêîäèðîâàííûÿ (TN/NS) ëåíòà (èç LEX)
short lenta_position; //òåêóùàÿ ïîçèöèÿ íà ëåíòå
short nrule; //íîìåð òåêóùåãî ïðàâèëà
short nrulechain; //íîìåð òåêóùåé öåïî÷êè,òåêóùåãî ïðàâèëà
short lenta_size; //ðàçìåð ëåíòû
GRB::Greibach grebach; //ãðàììàòèêà Ãðåéáàõ
LT::LexTable lex; //ðåçóëüòàò ðàáîòû ëåêñè÷åñêîãî àíàëèçàòîðà
MFSTSTSTACK st; //ñòåê àâòîìàòà
my_stack_MfstState storestate; //ñòåê äëÿ õðàíåíèÿ ñîñòîÿíèé
Mfst();
Mfst(LT::LexTable& plex, GRB::Greibach pgrebach);
char* getCSt(char* buf); //ïîëó÷èòü ñîäåðæèìîå ñòåêà
char* getCLenta(char* buf, short pos, short n = 25); //ëåíòà: n ñèìâîëîâ ñ pos
char* getDiagnosis(short n, char* buf); //ïîëó÷èòü n-þ ñòðîêó äèàãíîñòèêè èëè 0õ00
bool savestate(); //ñîõðàíèòü ñîñòîÿíèå àâòîìàòà
bool resetstate(); //âîññòàíîâèòü ñîñòîÿíèå àâòîìàòà
bool push_chain(GRB::Rule::Chain chain); //ïîìåñòèòü öåïî÷êó ïðàâèëà â ñòåê
RC_STEP step(); //âûïîëíèòü øàã àâòîìàòà
bool start(); //çàïóñòèòü àâòîìàò
bool savediagnosis(RC_STEP pprc_step); //êîä çàâåðøåíèÿ øàãà
void printrules(); //âûâåñòè ïîñëäåîâàòåëüíîñòü ïðàâèë
struct Deducation
{
short size;
short* nrules;
short* nrulechains;
Deducation()
{
size = 0;
nrules = 0;
nrulechains = 0;
};
}deducation;
bool savededucation();
};
}