-
Notifications
You must be signed in to change notification settings - Fork 0
/
Syntaxlib.h
132 lines (116 loc) · 2.27 KB
/
Syntaxlib.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
#ifndef SYNTAXLIB_H
#define SYNTAXLIB_H
using namespace std;
#include "interpretlib.h"
#include <vector>
#include <stack>
#define STL_STACK
#ifndef STL_STACK
template <class T, int max_size > class stack{
T s[max_size];
int top;
public:
stack(){top = 0;}
void reset() { top = 0; }
void push(T i);
T pop();
bool is_empty(){ return top == 0; }
bool is_full() { return top == max_size; }
};
template <class T, int max_size >
void stack <T, max_size >::push(T i){
if ( !is_full() ){
s[top] = i;
++top;
}
else
throw "Stack_is_full";
}
template <class T, int max_size >
T stack <T, max_size >::pop(){
if ( !is_empty() ){
--top;
return s[top];
}
else
throw "Stack_is_empty";
}
#endif
struct error_msg{
string message;
Lexem error_lex;
error_msg(string msg,Lexem& er_l){
message=msg;
error_lex=er_l;
}
};
class ex_error{
public:
string err;
ex_error(string s){
err = s;
}
};
class Parser{
Lexem current_lexem;
Lexem cur_poliz_lexem;
int cur_value;
Scanner scan;
//procedures of recursive descent parser//
void sentence(); //syntax
void function();
void operat();
void block();
void var_definition();
void expression();
void simple_expression();
void prefix();
void infix();
void condition();
void cycle();
void transition();
void alert();
void read();
void function_call();
//semantic
void dec (type_of_lexem type);
void udec ();
void check_id ();
void check_op ();
void eq_type ();
void eq_bool ();
// void check_id_in_read ();
//interpretation
public:
int cur_string_number;
type_of_lexem cur_type;
vector<Lexem> Poliz;
vector<type_of_lexem> vc_lex;
stack <int> st_int;
stack <int> st_loc;
stack <type_of_lexem> st_lex;
void get_lexem(){
current_lexem = scan.get_lex(&cur_string_number);
cur_type = current_lexem.get_type();
cur_value = current_lexem.get_value();
}
// Poliz prog;
Parser(const char* program):scan(program){
Poliz.reserve(1000);
cur_string_number = 1;
}
void analyze();
void execute();
void interpretation();
Scanner get_scanner(){
return scan;
}
void print_vec(vector<type_of_lexem> v) const
{
cout << "variable types: " << endl;
for (vector<type_of_lexem>::const_iterator i = v.begin(); i != v.end(); i++)
cout << *i << ' ';
cout << endl << endl;
}
};
#endif