Scan all characters from the input stream and generate a corresponding list of tokens, whilst discarding all whitespace and comments. @return
()
| 60 | * @return |
| 61 | */ |
| 62 | public List<Token> scan() { |
| 63 | ArrayList<Token> tokens = new ArrayList<>(); |
| 64 | pos = 0; |
| 65 | |
| 66 | while (pos < input.length()) { |
| 67 | char c = input.charAt(pos); |
| 68 | |
| 69 | if (isDigit(c)) { |
| 70 | tokens.add(scanNumericLiteral()); |
| 71 | } else if (c == '"') { |
| 72 | tokens.add(scanStringLiteral()); |
| 73 | } else if (c == '\'') { |
| 74 | tokens.add(scanCharacterLiteral()); |
| 75 | } else if (isOperatorStart(c)) { |
| 76 | tokens.add(scanOperator()); |
| 77 | } else if (isLetter(c) || c == '_') { |
| 78 | tokens.add(scanIdentifier()); |
| 79 | } else if (Character.isWhitespace(c)) { |
| 80 | scanWhiteSpace(tokens); |
| 81 | } else { |
| 82 | tokens.add(new Token(Token.Kind.Unknown, "" + c, pos++)); |
| 83 | } |
| 84 | } |
| 85 | |
| 86 | return tokens; |
| 87 | } |
| 88 | |
| 89 | /** |
| 90 | * Scan a numeric constant. That is a sequence of digits which constitutes an |
no test coverage detected