Professional Documents
Culture Documents
Scan Method Pseudo Code Revisited
Scan Method Pseudo Code Revisited
n = prog.length()
index = 0
lineNumber = 1
ch = prog.charAt(index)
// only one of the following six methods calls can be "not null" or "true"
for a character
whiteSpace = isWhiteSpace(ch)
newline = isLineBreak(ch)
sym = getSymbol(ch)
op = getOp(ch)
letter = isLetter(ch)
digit = isDigit(c)
index ++
continue
word = ""
word += ch
index ++
while (index < n) { // use this while loop to identify e.g. the
variable name
ch = prog.charAt(index)
if (ch is a letter) {
word += ch
index ++
}
else { break }
}
// the word can be variable name (i.e. IDENTIFIER) or keyword (e.g.,
KEYWORD_INT) or Klingon method (e.g., KLINGON_ADD)
// how to decide?
print lineNumber, token type, word
continue
number = ""
number += ch
index ++
while (index < n) {
ch = prog.charAt(index)
if (ch is a digit) {
number += ch
index ++
}
else { break }
}
print ...
continue
str = ""
str += ch
index ++
} else {