From 61f5dde8c9ea0b0348cc6ac001d27430ffb643c0 Mon Sep 17 00:00:00 2001 From: Gary Gan Date: Wed, 4 Jun 2025 21:53:51 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=A0=E9=99=A4Scanner.cpp?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Scanner.cpp | 94 ------------------------------------------------- 1 file changed, 94 deletions(-) delete mode 100644 src/Scanner.cpp diff --git a/src/Scanner.cpp b/src/Scanner.cpp deleted file mode 100644 index 7387059..0000000 --- a/src/Scanner.cpp +++ /dev/null @@ -1,94 +0,0 @@ -#include "Scanner.h" -#include - -int Scanner::process_const_table(int index) { - return 0; -} - -int Scanner::process_identifier_table(int index) { - std::stringstream buffer; - int old_index = index; - if (std::isalpha(m_source_code[index])) { - buffer << m_source_code[index]; - index += 1; - while(std::isalnum(m_source_code[index])) { - buffer << m_source_code[index]; - index += 1; - } - - std::string identifier = buffer.str(); - for (const auto& key : m_tables.KeyTable) { - if (identifier == key.second) { - return 0; - } - } - - m_tables.IdTable.insert({identifier_index, identifier}); - m_token_list.push_back(Token{identifier_index, ID_TABLE}); - identifier_index++; - return index - old_index; - } else { - return 0; - } - -} - -int Scanner::process_key_table(int index) { - return 0; -} - -int Scanner::process_punct_table(int index) { - //identify the Punct in map - string s; - int n = this->m_source_code.size(); - char c1= this->m_source_code[index]; - char c2 = '@'; - char c3 = '@'; - if (index + 1 < n) c2 = this->m_source_code[index + 1]; - if (index + 2 < n) c3 = this->m_source_code[index + 2]; - if (((c1 == c2 && c2 == '<') || (c1 == c2&& c2 == '>'))&& c3 =='=') { - this->m_token_list.push_back({c1=='<'?31:32,PUNCT_TABLE}); - return 3; - } - if (c1 == c2 ) { - if (c1 =='=') { - this->m_token_list.push_back({15,PUNCT_TABLE}); - return 2; - } - if (c1 =='|') { - this->m_token_list.push_back({21,PUNCT_TABLE}); - return 2; - } - if (c1=='&') { - this->m_token_list.push_back({20,PUNCT_TABLE}); - return 2; - } - if (c1=='<') { - this->m_token_list.push_back({9,PUNCT_TABLE}); - return 2; - } - if (c1=='>') { - this->m_token_list.push_back({10,PUNCT_TABLE}); - return 2; - } - } - - string t; - t.push_back(c1); - t.push_back(c2); - for (auto e : this->m_tables.PunctTable) { - if (e.second == t) { - this->m_token_list.push_back({e.first,PUNCT_TABLE}); - return 2; - } - } - - t.pop_back(); - for (auto e : this->m_tables.PunctTable) { - if (e.second == t) { - this->m_token_list.push_back({e.first,PUNCT_TABLE}); - return 1; - } - } - return 0; -}