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 | /**
* @file Scanner.h
*
* @author <a href="mailto:mellmann@informatik.hu-berlin.de">Heinrich Mellmann</a>
* Implementation of class Scanner
*/
#include "Scanner.h"
bool Scanner::endOfFile()<--- Technically the member function 'Scanner::endOfFile' can be const. [+]The member function 'Scanner::endOfFile' can be made a const function. Making this function 'const' should not cause compiler errors. Even though the function can be made const function technically it may not make sense conceptually. Think about your design and the task of the function first - is it a function that must not change object internal state?
{
return nextChar == EOF;
}//end eof
void Scanner::getNextToken()
{
skipSpace();
bufferLength = 0;
if(nextChar == EOF)
{
buffer[bufferLength++] = nextChar;
buffer[bufferLength] = '\0';
return;
}//end if
if(!isTokenChar(nextChar))
{
buffer[bufferLength++] = nextChar;
buffer[bufferLength] = '\0';
getNextChar();
return;
}//end if
while(isTokenChar(nextChar))
{
buffer[bufferLength++] = nextChar;
buffer[bufferLength] = '\0';
getNextChar();
}//end while
}//end getNextToken
/*
* Return true if c is a token character,
* i.e., 0-1, a-z, A-Z, or one of the character '.','-' or '_'
*/
bool Scanner::isTokenChar(char c)
{
return isalnum(c) || c == '.' || c == '-' || c == '_';
}//end isTolenChar
bool Scanner::isToken(std::string token)<--- Technically the member function 'Scanner::isToken' can be const. [+]The member function 'Scanner::isToken' can be made a const function. Making this function 'const' should not cause compiler errors. Even though the function can be made const function technically it may not make sense conceptually. Think about your design and the task of the function first - is it a function that must not change object internal state? <--- Function parameter 'token' should be passed by reference. [+]Parameter 'token' is passed by value. It could be passed as a (const) reference which is usually faster and recommended in C++.
{
return token == buffer;
}//end isToken
bool Scanner::eof()<--- Technically the member function 'Scanner::eof' can be const. [+]The member function 'Scanner::eof' can be made a const function. Making this function 'const' should not cause compiler errors. Even though the function can be made const function technically it may not make sense conceptually. Think about your design and the task of the function first - is it a function that must not change object internal state?
{
return nextChar == EOF;
}//end eof
void Scanner::skipSpace()
{
while(isspace(nextChar) || nextChar == '#')
{
if(nextChar == '\n')
lineNumber++;
if(nextChar == '#')
skipLine();
else
getNextChar();
}
}//end skipSpace
void Scanner::skipLine()
{
while(nextChar != EOF && nextChar != '\n')
{
getNextChar();
}//end while
getNextChar();
lineNumber++;
}//end skipLine
void Scanner::getNextChar()
{
if(inputStream.good())
nextChar = (char) inputStream.get();
else
nextChar = EOF;
}//end getNextChar
int Scanner::getLineNumber()<--- Technically the member function 'Scanner::getLineNumber' can be const. [+]The member function 'Scanner::getLineNumber' can be made a const function. Making this function 'const' should not cause compiler errors. Even though the function can be made const function technically it may not make sense conceptually. Think about your design and the task of the function first - is it a function that must not change object internal state?
{
return lineNumber;
}//end getLineNumber
|