-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJackTokeniser.h
42 lines (31 loc) · 1.29 KB
/
JackTokeniser.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
31
32
33
34
35
36
37
38
39
40
41
42
#ifndef JACK_TOKENISER_H
#define JACK_TOKENISER_H
#include <string>
// List of tokens returned by Tokeniser, eof is returned when there is no more input
enum jacktoken { keyword, symbol, integerConstant, stringConstant, identifier, eof };
// Removes all comments and whitespace from the input stream and breaks it
// into Jack language tokens, as specified by the Jack grammar
class JackTokeniser
{
public:
// Reads the next token from standard input
static jacktoken nextToken();
static std::string tokenName; // Stoers the current token's name
static jacktoken token; // Stores the current token as an enum
static std::string tokenString; // Stores token as a string
static int lineNo; // Stores current line number
// Returns true if token is a keyword
bool checkKeyword(std::string token);
private:
// Returns the type of the current token
std::string tokenType(std::string token);
// Returns true if token is a symbol
bool checkSymbol(std::string token);
// Returns true if token is a identifier
bool checkIdentifier(std::string token);
// Returns true if token is a integer constant
bool checkIntConst(std::string token);
// Returns true if token is a string constant
bool checkStringConst(std::string token);
};
#endif // JACK_TOKENISER_H