-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtoken.hpp
48 lines (37 loc) · 1.05 KB
/
token.hpp
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
43
44
45
46
47
48
/*
* token.hpp
*
* Created on: 10 de feb. de 2017
* Author: Ethan
*/
#ifndef TOKEN_HPP_
#define TOKEN_HPP_
#include <string>
bool isKeyword(std::string s);
int keyValue(std::string s);
enum keyword {
HASH, OPEN_PAREN, CLOSE_PAREN, STAR, PLUS, COMMA, MINUS, DOT,
COLON, COLON_EQ, SEMICOLON, LESS, LESS_EQ, EQUALS, GREATER, GREATER_EQ,
ARRAY, BEGIN, CONST, DIV, DO, ELSE, END, IF, MOD,
OF, PROGRAM, READ, RECORD, REPEAT, THEN, TYPE, UNTIL, VAR, WHILE,
WRITE, OPEN_SQUARE, CLOSE_SQUARE, EOF_TOKEN
};
struct token {
enum kind {
KEYWORD, IDENTIFIER, INTEGER
};
static const std::string KWSTR[];
kind k;
int v; //integer value or keyword value
std::string id; //identifier
int start, end;
friend std::ostream& operator<<(std::ostream&, const token&);
token(std::string id, int start, int end);
token(kind k, int v, int start, int end);
bool isKey(int key) const;
operator std::string() const;
};
token INVALID_TOKEN();
const token PLACEHOLDER_TOKEN = token(token::KEYWORD, 0, 0, 0);
void debugPrint(std::string);
#endif /* TOKEN_HPP_ */