-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtokens.h
70 lines (55 loc) · 916 Bytes
/
tokens.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#ifndef TOKENS_H_
#define TOKENS_H_
#include <string>
#include <iostream>
using std::istream;
using std::ostream;
using std::string;
enum TokenType
{
PRINT,
SET,
IF,
LOOP,
BEGIN,
END,
ID,
ICONST,
SCONST,
PLUS,
MINUS,
STAR,
SLASH,
LPAREN,
RPAREN,
SC,
NL,
ERR,
DONE
};
class Token
{
TokenType tt;
string lexeme;
int lnum;
public:
Token()
{
tt = ERR;
lnum = -1;
}
Token(TokenType tt, string lexeme, int line)
{
this->tt = tt;
this->lexeme = lexeme;
this->lnum = line;
}
bool operator==(const TokenType tt) const { return this->tt == tt; }
bool operator!=(const TokenType tt) const { return this->tt != tt; }
TokenType GetTokenType() const { return tt; }
string GetLexeme() const { return lexeme; }
int GetLinenum() const { return lnum; }
};
extern ostream &operator<<(ostream &out, const Token &tok);
extern Token getNextToken(istream &in, int &linenum);
#endif