1.添加Tbs的对象在Tbs.h和Tbs.cpp中 , Tbs对象含有常量表和标识符表的两个map
2. 添加Scanner的scan模板 , scan中参数为string源码和Tbs对象 , Tbs对象含有常量表和标识符表的两个map 3. Scanner_test的测试文件将测试扫描后 , Tbs的两个map的情况
This commit is contained in:
parent
30a491aa4c
commit
be8a523bf1
@ -11,13 +11,17 @@ include_directories(${CMAKE_SOURCE_DIR}/include)
|
||||
|
||||
file(GLOB SOURCES ${CMAKE_SOURCE_DIR}/src/*.cpp)
|
||||
|
||||
add_executable(Hydrogen ${SOURCES})
|
||||
add_executable(Hydrogen ${SOURCES}
|
||||
src/scanner.cpp
|
||||
src/Tbs.cpp)
|
||||
|
||||
file(GLOB TEST_SOURCES ${CMAKE_SOURCE_DIR}/unit/*.cpp)
|
||||
|
||||
foreach(TEST_SOURCE ${TEST_SOURCES})
|
||||
get_filename_component(TEST_NAME ${TEST_SOURCE} NAME_WE)
|
||||
add_executable(${TEST_NAME} ${TEST_SOURCE} ${SOURCES})
|
||||
add_executable(${TEST_NAME} ${TEST_SOURCE} ${SOURCES}
|
||||
include/scanner.h
|
||||
include/Tbs.h)
|
||||
add_test(NAME ${TEST_NAME} COMMAND ${TEST_NAME})
|
||||
endforeach(TEST_SOURCE ${TEST_SOURCES})
|
||||
|
||||
|
9
include/Scanner.h
Normal file
9
include/Scanner.h
Normal file
@ -0,0 +1,9 @@
|
||||
# pragma once
|
||||
#include "stdc++.h"
|
||||
#include "Token.h"
|
||||
#include "Tbs.h"
|
||||
class Scanner {
|
||||
public:
|
||||
bool scan(std::string org_s,Tbs& t);
|
||||
|
||||
};
|
9
include/Tbs.h
Normal file
9
include/Tbs.h
Normal file
@ -0,0 +1,9 @@
|
||||
# pragma once
|
||||
|
||||
#include "stdc++.h"
|
||||
using std::unordered_map,std::string;
|
||||
class Tbs {
|
||||
public:
|
||||
unordered_map<int,string> ConstTable;
|
||||
unordered_map<int,string> IdTable;
|
||||
};
|
18
src/Scanner.cpp
Normal file
18
src/Scanner.cpp
Normal file
@ -0,0 +1,18 @@
|
||||
#include "Scanner.h"
|
||||
|
||||
using std::vector,std::string;
|
||||
|
||||
bool Scanner::scan(std::string org_s,Tbs& t) {
|
||||
string tmp;
|
||||
int cnt = 0;
|
||||
for (auto e : org_s) {
|
||||
if (e==' ') {
|
||||
t.ConstTable[++cnt] =tmp;
|
||||
tmp = "";
|
||||
}
|
||||
else {
|
||||
tmp += e;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
1
src/Tbs.cpp
Normal file
1
src/Tbs.cpp
Normal file
@ -0,0 +1 @@
|
||||
#include "Tbs.h"
|
Loading…
Reference in New Issue
Block a user