class Tokenizer {
public:
- explicit Tokenizer(std::istream &in) : in(in), isPutback(false) { }
+ explicit Tokenizer(std::istream &in)
+ : in(in), line(1), isPutback(false), skipComments(true) { }
~Tokenizer() { }
private:
Tokenizer(const Tokenizer &);
KEYWORD_TRUE = 't',
IDENTIFIER = 'x',
TYPE_NAME = 'n',
+ COMMENT = 'c'
};
Token() : type(UNKNOWN), number(0) { }
class LexerError: public std::runtime_error {
public:
- explicit LexerError(const std::string &msg) : std::runtime_error(msg) { }
+ LexerError(int line, const std::string &msg)
+ : std::runtime_error(msg), line(line) { }
+ int Line() const { return line; }
+ private:
+ int line;
};
bool HasMore();
Token GetNext();
const Token &Peek();
void Putback(const Token &);
+ int Line() const { return line; }
private:
+ void ScanSpace();
Token ReadToken();
Token ReadNumber();
Token ReadString();
Token ReadIdentifier();
+ Token ReadComment();
+ Token ReadMultilineComment();
+
bool CheckKeyword(Token &);
private:
std::istream ∈
Token putback;
+ int line;
bool isPutback;
+ bool skipComments;
};