-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsemantic.cpp
58 lines (51 loc) · 1.18 KB
/
semantic.cpp
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
#include <iostream>
#include <fstream>
#include <string>
#include "interpretlib.h"
using namespace std;
void Parser::dec ( type_of_lexem type ){
int i;
while ( !st_int.empty()){
i = st_int.top();
st_int.pop();
if ( TID[i].get_declare() )
throw "twice declaration";
else
{
TID[i].set_declare();
TID[i].set_type(type);
vc_lex.push_back(type); //vector of types
}
}
}
void Parser::udec ()
{
int i;
while( !st_loc.empty() ){
i = st_loc.top();
st_loc.pop();
if (i == LEX_FIN ) break; //out of the block
if ( !TID[i].get_declare() )
throw "try to undeclare undeclared";
else
TID[i].undeclare();
}
}
void Parser::check_id(){
if ( TID[cur_value].get_declare() )
st_lex.push(TID[cur_value].get_type());
else
throw "not declared";
}
void Parser::eq_bool (){
if ( st_lex.top() == LEX_STRING )
throw "expression is not boolean";
st_lex.pop();
}
/*
need to add read(id);
void Parser::check_id_in_read (){
if ( !TID [cur_value].get_declare() )
throw "not declared";
}
*/