-
Notifications
You must be signed in to change notification settings - Fork 0
/
lexer.h
55 lines (45 loc) · 1.01 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
50
51
52
53
54
55
/*
* Copyright (C) Rida Bazzi, 2017
*
* 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,
VAR, FOR, IF, WHILE, SWITCH, CASE, DEFAULT, INPUT, OUTPUT, ARRAY,
PLUS, MINUS, DIV, MULT,
EQUAL, COLON, COMMA, SEMICOLON,
LBRAC, RBRAC, LPAREN, RPAREN, LBRACE, RBRACE,
NOTEQUAL, GREATER, LESS,
NUM, ID, 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();
int FindKeywordIndex(std::string);
Token ScanIdOrKeyword();
Token ScanNumber();
};
#endif //__LEXER__H__