-
Notifications
You must be signed in to change notification settings - Fork 0
/
lexer.h
49 lines (37 loc) · 1.1 KB
/
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
#ifndef __LEXER__H__
#define __LEXER__H__
#include <vector>
#include <string>
#include "inputbuf.h"
// ------- token types -------------------
typedef enum { END_OF_FILE, INT, REAL, BOO, TR, FA, IF, WHILE, SWITCH, CASE, PUBLIC, PRIVATE, NUM, REALNUM, NOT, PLUS, MINUS, MULT, DIV, GTEQ, GREATER, LTEQ, NOTEQUAL, LESS, LPAREN, RPAREN, EQUAL, COLON, COMMA, SEMICOLON, LBRACE, RBRACE, ID, ERROR // TODO: Add labels for new token types here
} TokenType;
class Token {
public:
void Print();
std::string lexeme;
TokenType token_type;
int line_no;
};
class LexicalAnalyzer {
public:
Token GetToken();
TokenType UngetToken(Token);
LexicalAnalyzer();
private:
std::vector<Token> tokens;
int line_no;
Token tmp;
InputBuffer input;
bool SkipSpace();
bool SkipComments();
bool IsKeyword(std::string);
TokenType FindKeywordIndex(std::string);
Token ScanIdOrKeyword();
Token ScanNumber();
};
void update_Types(int LHS, int RHS);
void addList(std::string n, int lN, int t);
//void printList(void);
int Search_List(std::string n);
#endif //__LEXER__H__