-
Notifications
You must be signed in to change notification settings - Fork 0
/
ourPython.h
118 lines (93 loc) · 2.36 KB
/
ourPython.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
/*-------------------------------------------------------------------------*
*--- ---*
*--- ourPython.h ---*
*--- ---*
*--- This file declares types and classes needed to implement a ---*
*--- basic Python interpreter. ---*
*--- ---*
*--- ---- ---- ---- ---- ---- ---- ---- ---- ---*
*--- ---*
*--- Version 1a 2018 May 15 Joseph Phillips ---*
*--- ---*
*-------------------------------------------------------------------------*/
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <ctype.h> // For isspace()
#include <string>
#include <vector>
#include <map>
// PURPOSE: To tell the default length of C strings.
const int LINE_LEN = 256;
// PURPOSE: To distinguish among the implemented Python types.
typedef enum
{
noneType,
boolType,
intType,
floatType,
strType,
typeType
}
pythonType_ty;
// PURPOSE: To tell the printable names of the values of 'pythonType_ty'.
extern
const char* typeNameArray[];
// PURPOSE: To distinguish among the implemented Python operators.
typedef enum
{
OR_OP,
AND_OP,
NOT_OP,
LESSER_OP,
LESSER_EQUAL_OP,
GREATER_OP,
GREATER_EQUAL_OP,
EQUAL_EQUAL_OP,
NOT_EQUAL_OP,
PLUS_OP,
MINUS_OP,
STAR_OP,
SLASH_OP,
PERCENT_OP,
SLASH_SLASH_OP,
STAR_STAR_OP
}
operator_ty;
// PURPOSE: To tell the printable names of the values of 'operator_ty'.
extern
const char* operatorNameArray[];
// PURPOSE: To do 'delete(ptr)', and then set 'ptr' to 'NULL'.
template <typename T>
inline void safeDelete (T& ptr)
{
delete(ptr);
ptr = NULL;
}
class Statement;
// PURPOSE: To serve as a global temporary C-string array.
extern
char line[LINE_LEN];
// PURPOSE: To point to the root of the abstract syntax tree.
extern
Statement* programRootPtr;
// PURPOSE: TO serve as the input file.
extern
FILE* yyin;
// PURPOSE: To handle the outputing of parse-time error message 'cPtr'.
// No return value.
extern
int yyerror (const char* cPtr
);
// PURPOSE: To return the integer encoding of the next token read. No
// parameters. No return value.
extern
int yylex ();
#include "Exception.h"
#include "Object.h"
#include "Expression.h"
#include "Statement.h"
#include "VariableStore.h"
// PURPOSE: To hold the variables and their values.
extern
VariableStore variableStore;