| CIT
594 Errata
#5 for Bugs Grammar (and Code) Spring 2008, David Matuszek |
It seems like there's no end to the corrections....
Last year in CIT594 the main project used ints. The StreamTokenizer
really wants to return doubles, so I had to cast them to int.
This year we are using doubles, so the cast needs to be removed.
I didn't think to update the Recognizer class
(or the RecognizerTest class) to take this into account, which
is why everything worked.
Was: Token nextToken() { int code; try { code = tokenizer.nextToken(); } catch (IOException e) { throw new Error(e); } // Should never happen switch (code) { case StreamTokenizer.TT_WORD: if (Token.KEYWORDS.contains(tokenizer.sval)) { return new Token(Token.Type.KEYWORD, tokenizer.sval); } else { return new Token(Token.Type.NAME, tokenizer.sval); } case StreamTokenizer.TT_NUMBER: return new Token(Token.Type.NUMBER, ((int) tokenizer.nval) + ""); case StreamTokenizer.TT_EOL: return new Token(Token.Type.EOL, "\n"); case StreamTokenizer.TT_EOF: return new Token(Token.Type.EOF, "EOF"); default: return new Token(Token.Type.SYMBOL, ((char) code) + ""); } }Now: Token nextToken() { int code; try { code = tokenizer.nextToken(); } catch (IOException e) { throw new Error(e); } // Should never happen switch (code) { case StreamTokenizer.TT_WORD: if (Token.KEYWORDS.contains(tokenizer.sval)) { return new Token(Token.Type.KEYWORD, tokenizer.sval); } else { return new Token(Token.Type.NAME, tokenizer.sval); } case StreamTokenizer.TT_NUMBER: return new Token(Token.Type.NUMBER, tokenizer.nval + ""); case StreamTokenizer.TT_EOL: return new Token(Token.Type.EOL, "\n"); case StreamTokenizer.TT_EOF: return new Token(Token.Type.EOF, "EOF"); default: return new Token(Token.Type.SYMBOL, ((char) code) + ""); } }
You should be aware that the String value returned for a number
written without a decimal point has now changed. For example, the number 5 will
now be returned by the tokenizer as 5.0.
Corrections have been made to both Recognizer.java and RecognizerTest.java.