-
Notifications
You must be signed in to change notification settings - Fork 0
/
program.h
154 lines (122 loc) · 3.99 KB
/
program.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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
/*
* File: program.h
* ---------------
* This interface exports a Program class for storing a BASIC
* program.
*/
#ifndef _program_h
#define _program_h
#include <string>
#include "statement.h"
using namespace std;
/*
* This class stores the lines in a BASIC program. Each line
* in the program is stored in order according to its line number.
* Moreover, each line in the program is associated with two
* components:
*
* 1. The source line, which is the complete line (including the
* line number) that was entered by the user.
*
* 2. The parsed representation of that statement, which is a
* pointer to a Statement.
*/
class Program {
public:
/*
* Constructor: Program
* Usage: Program program;
* -----------------------
* Constructs an empty BASIC program.
*/
Program();
/*
* Destructor: ~Program
* Usage: usually implicit
* -----------------------
* Frees any heap storage associated with the program.
*/
~Program();
/*
* Method: clear
* Usage: program.clear();
* -----------------------
* Removes all lines from the program.
*/
void clear();
/*
* Method: addSourceLine
* Usage: program.addSourceLine(lineNumber, line);
* -----------------------------------------------
* Adds a source line to the program with the specified line number.
* If that line already exists, the text of the line replaces
* the text of any existing line and the parsed representation
* (if any) is deleted. If the line is new, it is added to the
* program in the correct sequence.
*/
void addSourceLine(int lineNumber, std::string line);
/*
* Method: removeSourceLine
* Usage: program.removeSourceLine(lineNumber);
* --------------------------------------------
* Removes the line with the specified number from the program,
* freeing the memory associated with any parsed representation.
* If no such line exists, this method simply returns without
* performing any action.
*/
void removeSourceLine(int lineNumber);
/*
* Method: getSourceLine
* Usage: string line = program.getSourceLine(lineNumber);
* -------------------------------------------------------
* Returns the program line with the specified line number.
* If no such line exists, this method returns the empty string.
*/
std::string getSourceLine(int lineNumber);
/*
* Method: setParsedStatement
* Usage: program.setParsedStatement(lineNumber, stmt);
* ----------------------------------------------------
* Adds the parsed representation of the statement to the statement
* at the specified line number. If no such line exists, this
* method raises an error. If a previous parsed representation
* exists, the memory for that statement is reclaimed.
*/
void setParsedStatement(int lineNumber, Statement *stmt);
/*
* Method: getParsedStatement
* Usage: Statement *stmt = program.getParsedStatement(lineNumber);
* ----------------------------------------------------------------
* Retrieves the parsed representation of the statement at the
* specified line number. If no value has been set, this method
* returns NULL.
*/
Statement *getParsedStatement(int lineNumber);
/*
* Method: getFirstLineNumber
* Usage: int lineNumber = program.getFirstLineNumber();
* -----------------------------------------------------
* Returns the line number of the first line in the program.
* If the program has no lines, this method returns -1.
*/
int getFirstLineNumber();
/*
* Method: getNextLineNumber
* Usage: int nextLine = program.getNextLineNumber(lineNumber);
* ------------------------------------------------------------
* Returns the line number of the first line in the program whose
* number is larger than the specified one, which must already exist
* in the program. If no more lines remain, this method returns -1.
*/
int getNextLineNumber(int lineNumber);
bool Is_LineNumber(int lineNumber);
int getid(int lineNumber);
void excute(int k, EvalState & state);
// void help();
private:
int lin[60], nxt[60], pre[60], num;
Statement *pro[60];
string str[60];
bool fg;
};
#endif