-
Notifications
You must be signed in to change notification settings - Fork 0
/
lexer.h
30 lines (24 loc) · 631 Bytes
/
lexer.h
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
#ifndef __LEXER_H__
#define __LEXER_H__
#include <iostream>
#include <string>
#include <fstream>
#include "tokens.h"
class Lexer
{
public:
Lexer(std::istream& input): input(input) {}
std::string getText() { return text; }
int getNextChar() { return input.get(); }
void ungetChar(int ch) { input.unget(); }
void reportError(int ch) {
std::cerr << "Error: Invalid character: '" << ch << "'\n";
}
Token getNextToken();
static const char *tokenToString(Token tk);
static Token findKeyword(const std::string& str);
private:
std::string text;
std::istream& input;
};
#endif