-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathq2.js
44 lines (42 loc) · 890 Bytes
/
q2.js
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
/*Anthony Courchesne
* 260688650
* COMP302 ast 2
* october 2016
*/
//----------------Question 2----------------
//
// Given test function
function scanit(s) {
var sout = "";{
while (s) {
var t = scan (s ,TOKENSET);
sout += t.tokenvalue;
s = s.substr(t.tokenvalue.length);
}
}
return sout;
}
var TOKENSET = {
PSTART: true,
PEND: true,
TSTART: true,
TEND: true,
PIPE: true,
DSTART: true,
DEND: true,
INNERTEXT: true,
INNERDTEXT: true,
PNAME: true,
OUTERTEXT: true
}
//return the first token object
function scan(string, TOKENSET){
for (var possibleToken in TOKENSET){
var result = null;
var re = eval(possibleToken);
result = re.exec(string);
if (result != null){
return {token:possibleToken, tokenvalue:result[0]};
}
}
}