-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlinecode.cpp
53 lines (44 loc) · 1.36 KB
/
linecode.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
#include "linecode.h"
Order toOrder(string &str) {
if(str=="REM") return REM;
if(str=="LET") return LET;
if(str=="PRINT") return PRINT;
if(str=="INPUT") return INPUT;
if(str=="GOTO") return GOTO;
if(str=="END") return END;
if(str=="IF") return IF;
return UNDEFINED;
}
Rank Linecode::readLineno(Rank start,Rank &lineno) {
/*int no=0;
while(start<code.size()&&isdigit(code[start])){
no*=10;
no+=(code[start++])-'0';
}
lineno=no;*/
lineno=readNumber(code,start,&start);
return start;
}
Rank Linecode::readOrder(Rank start,Order &order) {
string str;
//while(start<code.size()&&code[start]==' ') start++;
while(start<code.size()&&isupper(code[start]))
str += code[start++];
order=toOrder(str);
return start;
}
/*
* After the analysis,it can be guaranteed that:
* the expression will start with letters.
*
*/
void Linecode::analyseCode() {
Rank ptr=0;
while(ptr<code.size()&&isspace(code[ptr])) ptr++;
if(ptr<code.size()&&isdigit(code[ptr])) ptr=readLineno(ptr,lineno);
else lineno=INT32_MIN;
while(ptr<code.size()&&isspace(code[ptr])) ptr++;
if(ptr<code.size()&&isupper(code[ptr])) ptr=readOrder(ptr,order);
while(ptr<code.size()&&isspace(code[ptr])) ptr++;
this->expression=string(code,ptr);
}