-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlexer.h
53 lines (43 loc) · 950 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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/*
* Copyright (C) Rida Bazzi, 2019
*
* Do not share this file with anyone
*/
#ifndef __LEXER__H__
#define __LEXER__H__
#include <vector>
#include <string>
#include "inputbuf.h"
// ------- token types -------------------
typedef enum { END_OF_FILE = 0,
POLY, START, INPUT, EQUAL, LPAREN,
RPAREN, ID, COMMA, POWER, NUM,
PLUS, MINUS, SEMICOLON, ERROR
} TokenType;
class Token {
public:
void Print();
std::string lexeme;
TokenType token_type;
int line_no;
};
class LexicalAnalyzer {
public:
Token GetToken();
void UngetToken(int);
Token peek(int);
LexicalAnalyzer();
private:
std::vector<Token> tokenList;
Token GetTokenMain();
int line_no;
int index;
Token tmp;
InputBuffer input;
bool SkipSpace();
bool IsKeyword(std::string);
TokenType FindKeywordIndex(std::string);
Token ScanNumber();
Token ScanIdOrKeyword();
};
#endif //__LEXER__H__