-
Notifications
You must be signed in to change notification settings - Fork 0
/
support.cc
86 lines (66 loc) · 2.37 KB
/
support.cc
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
/*********************************************************************************************
cfglp : A CFG Language Processor
--------------------------------
About:
Implemented by Uday Khedker (http://www.cse.iitb.ac.in/~uday) for
the courses cs302+cs306: Language Processors (theory and lab) at
IIT Bombay. Release date Jan 6, 2013. Copyrights reserved by Uday
Khedker. This implemenation has been made available purely for
academic purposes without any warranty of any kind.
Please see the README file for some details. A doxygen generated
documentation can be found at http://www.cse.iitb.ac.in/~uday/cfglp
***********************************************************************************************/
#include <iostream>
#include <cstdlib>
using namespace std;
/*
Invariant condition b must be satisfied at each call to procedure CHECK_INVARIANT.
If it is not satisfied, there must be some internal error. Abort the compilation.
This is different from erroneous input to our compiler.
*/
void check_Invariant_Underlying_Function(bool b, string s)
{
if (!b)
{
cerr << "\ncfglp internal error: " << s << "\n";
exit(1);
}
}
/*
If the input to our compiler is valid, condition b must be satisfied at call to
procedure report_Violation_of_Condition. If it is not satisfied, there must be
some error in the input.
This is different from an internal inconsistency of our compiler. Hence we do
not abort the compilation but try to report as many errors as possible.
*/
static bool global_error_status = false;
void report_Violation_of_Condition(bool b, string s)
{
if (!b)
{
cerr << " cfglp error: " << s << "\n";
global_error_status = true;
}
}
/*
In some cases of violation (such as unable to parse the program),
we may like to abort the compilation.
*/
void report_Violation_and_Abort(bool b, string s)
{
if (!b)
{
cerr << " cfglp error: " << s << "\n";
exit(1);
}
}
bool error_Status ()
{
return global_error_status;
}
string get_Var_Name(string arti_var)
{
int found = arti_var.find(".");
string var_name = arti_var.substr(0,found);
return var_name;
}