-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathScanner.hpp
More file actions
42 lines (38 loc) · 1.11 KB
/
Scanner.hpp
File metadata and controls
42 lines (38 loc) · 1.11 KB
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
#pragma once
#include <iostream>
#include <string>
#include <fstream>
#include <cstring>
#include <cctype>
#include <algorithm>
#include "Symbol.h"
using namespace std;
class Scanner
{
private:
char ch; // current character
string line;
string word[11]; // reserved words
Symbol ssym[256]; // single character symbols
Symbol wsym[11]; // reserved words symbols
ifstream *input_file; // 输入文件流
public:
int line_length; // length of the current line
int char_position; // position of current character in the line
int line_number; // current line number
Symbol sym; // current symbol
string id; // current identifier
int num; // current number
string str_val; // current string literal
Scanner();
Scanner(ifstream &file);
~Scanner();
void getch();
void getsym();
void matchKeywordOrIdentifier();
void matchNumber();
void matchOpertor();
void matchString(); // 新增:匹配字符串字面量
private:
void initializeSymbols(); // 初始化符号表
};