Now you cannot see lib files

This commit is contained in:
Valk Richard Li
2019-11-21 11:17:21 +08:00
committed by GitHub
parent a1f2e5bb1c
commit 2e2c4a96cd
2 changed files with 38 additions and 9 deletions
+35 -4
View File
@@ -81,11 +81,15 @@ bool check_number(std::string str)
class resource_file class resource_file
{ {
private: private:
std::list<char> resource; std::list<char> libsource; // place for lib code
std::list<char> resource; // place for user code
std::list<char> totalsource; // link lib and user code
public: public:
void set_clear() void set_clear()
{ {
resource.clear(); resource.clear();
libsource.clear();
totalsource.clear();
return; return;
} }
void add_lib() void add_lib()
@@ -95,12 +99,34 @@ class resource_file
if(access("lib/math.nas",0)) if(access("lib/math.nas",0))
std::cout<<">>[Resource] lack lib file: lib/math.nas ."<<std::endl; std::cout<<">>[Resource] lack lib file: lib/math.nas ."<<std::endl;
else else
input_file(lib_name); input_lib_file(lib_name);
lib_name="lib/io.nas"; lib_name="lib/io.nas";
if(access("lib/io.nas",0)) if(access("lib/io.nas",0))
std::cout<<">>[Resource] lack lib file: lib/io.nas ."<<std::endl; std::cout<<">>[Resource] lack lib file: lib/io.nas ."<<std::endl;
else else
input_file(lib_name); input_lib_file(lib_name);
return;
}
void input_lib_file(std::string filename)
{
std::ifstream fin(filename,std::ios::binary);
if(fin.fail())
{
std::cout<<">>[Resource] cannot find a file named \'"<<filename<<"\' ."<<std::endl;
return;
}
char c;
while(!fin.eof())
{
c=fin.get();
if(fin.eof())
break;
if(0<=c && c<128)
libsource.push_back(c);
else
libsource.push_back(' ');
}
libsource.push_back('\n');
return; return;
} }
void input_file(std::string filename) void input_file(std::string filename)
@@ -127,7 +153,12 @@ class resource_file
} }
std::list<char>& get_resource() std::list<char>& get_resource()
{ {
return resource; totalsource.clear();
for(std::list<char>::iterator i=libsource.begin();i!=libsource.end();++i)
totalsource.push_back(*i);
for(std::list<char>::iterator i=resource.begin();i!=resource.end();++i)
totalsource.push_back(*i);
return totalsource;
} }
void print_file() void print_file()
{ {
+2 -4
View File
@@ -25,8 +25,7 @@ int main()
std::cout<<">> 7. [del ] |delete program in memory."<<std::endl; std::cout<<">> 7. [del ] |delete program in memory."<<std::endl;
std::cout<<">> 8. [run ] |run the programme in stack. (-lexer -parser)"<<std::endl; std::cout<<">> 8. [run ] |run the programme in stack. (-lexer -parser)"<<std::endl;
std::cout<<">> 9. [rs ] |check the source program."<<std::endl; std::cout<<">> 9. [rs ] |check the source program."<<std::endl;
std::cout<<">>10. [lib ] |add lib into resource codes."<<std::endl; std::cout<<">>10. [sound ] |make noise(?)."<<std::endl;
std::cout<<">>11. [sound ] |make noise(?)."<<std::endl;
} }
else if(command=="cls") else if(command=="cls")
{ {
@@ -44,8 +43,6 @@ int main()
lex.scanner(prog.get_resource()); lex.scanner(prog.get_resource());
lex.print_token_list(); lex.print_token_list();
} }
else if(command=="lib")
prog.add_lib();
else if(command=="del") else if(command=="del")
{ {
prog.set_clear(); prog.set_clear();
@@ -92,6 +89,7 @@ int main()
} }
else if(command=="run") else if(command=="run")
{ {
prog.add_lib();
lex.scanner(prog.get_resource()); lex.scanner(prog.get_resource());
lex.generate_detail_token(); lex.generate_detail_token();
if(!lex.get_error()) if(!lex.get_error())