FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
QueryParser/Scanner.cpp at master · Monaghan-Boy/QueryParser · GitHub
Monaghan-Boy
/
QueryParser
Public
Notifications
You must be signed in to change notification settings
Fork
0
Star
1
Code
Issues
0
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
QueryParser
/
Scanner.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
109 lines (104 loc) · 3.1 KB
Breadcrumbs
QueryParser
/
Scanner.cpp
Copy path
File metadata and controls
109 lines (104 loc) · 3.1 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
#
include
"
Scanner.h
"
#
include
"
tokenType.h
"
#
include
"
Token.h
"
#
include
<
fstream
>
#
include
<
sstream
>
#
include
<
iostream
>
#
include
<
cctype
>
#
include
<
vector
>
//
#define SCAN
//
#define IDREAD
//
#define SREAD
using
namespace
std
;
void
Scanner::idReader
(ifstream& inFile,
char
last){
stringstream ss;
ss << last;
char
curr;
while
(
isalnum
(inFile.
peek
())){
inFile.
get
(curr);
ss << curr;
}
string value = ss.
str
();
if
(value ==
"
Schemes
"
) tokenList.
push_back
(
Token
(
SCHEMES
, value, line));
else
if
(value ==
"
Queries
"
) tokenList.
push_back
(
Token
(
QUERIES
, value, line));
else
if
(value ==
"
Facts
"
) tokenList.
push_back
(
Token
(
FACTS
, value, line));
else
if
(value ==
"
Rules
"
) tokenList.
push_back
(
Token
(
RULES
, value, line));
else
tokenList.
push_back
(
Token
(
ID
, value, line));
total++;
}
void
Scanner::stringReader
(ifstream& inFile){
stringstream ss;
ss <<
'
\'
'
;
char
curr;
while
(inFile.
peek
() !=
'
\'
'
){
inFile.
get
(curr);
if
(curr ==
EOF
|| curr ==
'
\n
'
){
error =
true
;
return
;
}
else
ss << curr;
}
inFile.
get
(curr);
ss << curr;
string value = ss.
str
();
tokenList.
push_back
(
Token
(
STRING
, value, line));
total++;
}
void
Scanner::scan
(string fileName){
line =
1
;
error =
false
;
ifstream inFile;
inFile.
open
(fileName);
char
curr;
while
(inFile.
get
(curr) && !error){
switch
(curr){
case
'
'
:
break
;
case
'
\t
'
:
break
;
case
'
\n
'
: line++;
break
;
case
'
#
'
: inFile.
ignore
(
256
,
'
\n
'
);
line++;
break
;
case
'
,
'
: tokenList.
push_back
(
Token
(
COMMA
,
"
,
"
, line));
total++;
break
;
case
'
.
'
: tokenList.
push_back
(
Token
(
PERIOD
,
"
.
"
, line));
total++;
break
;
case
'
?
'
: tokenList.
push_back
(
Token
(
Q_MARK
,
"
?
"
, line));
total++;
break
;
case
'
(
'
: tokenList.
push_back
(
Token
(
LEFT_PAREN
,
"
(
"
, line));
total++;
break
;
case
'
)
'
: tokenList.
push_back
(
Token
(
RIGHT_PAREN
,
"
)
"
, line));
total++;
break
;
case
'
:
'
:
if
(inFile.
peek
() ==
'
-
'
) {
tokenList.
push_back
(
Token
(
COLON_DASH
,
"
:-
"
, line));
inFile.
ignore
(
1
,
'
-
'
);
total++;
}
else
{
tokenList.
push_back
(
Token
(
COLON
,
"
:
"
, line));
total++;
}
break
;
case
'
\'
'
:
stringReader
(inFile);
break
;
default
:
if
(
isalpha
(curr))
idReader
(inFile, curr);
else
error =
true
;
}
}
if
(!error){
total++;
tokenList.
push_back
(
Token
(
END
,
"
"
, line));
}
}
void
Scanner::printTokens
(string fileName){
ofstream outFile;
outFile.
open
(fileName);
for
(
unsigned
int
i =
0
; i < tokenList.
size
(); i++) {
outFile << tokenList[i].
toString
();
}
if
(error) outFile <<
"
Input Error on line
"
<< line << endl;
else
outFile <<
"
Total Tokens =
"
<< total << endl;
}
Back
|
FazBrowse Home
|
New Git URL