forked from xxq250/Nasal-Interpreter
Now you cannot see lib files
This commit is contained in:
@@ -81,11 +81,15 @@ bool check_number(std::string str)
|
||||
class resource_file
|
||||
{
|
||||
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:
|
||||
void set_clear()
|
||||
{
|
||||
resource.clear();
|
||||
libsource.clear();
|
||||
totalsource.clear();
|
||||
return;
|
||||
}
|
||||
void add_lib()
|
||||
@@ -95,12 +99,34 @@ class resource_file
|
||||
if(access("lib/math.nas",0))
|
||||
std::cout<<">>[Resource] lack lib file: lib/math.nas ."<<std::endl;
|
||||
else
|
||||
input_file(lib_name);
|
||||
input_lib_file(lib_name);
|
||||
lib_name="lib/io.nas";
|
||||
if(access("lib/io.nas",0))
|
||||
std::cout<<">>[Resource] lack lib file: lib/io.nas ."<<std::endl;
|
||||
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;
|
||||
}
|
||||
void input_file(std::string filename)
|
||||
@@ -127,7 +153,12 @@ class resource_file
|
||||
}
|
||||
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()
|
||||
{
|
||||
|
||||
@@ -25,8 +25,7 @@ int main()
|
||||
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<<">> 9. [rs ] |check the source program."<<std::endl;
|
||||
std::cout<<">>10. [lib ] |add lib into resource codes."<<std::endl;
|
||||
std::cout<<">>11. [sound ] |make noise(?)."<<std::endl;
|
||||
std::cout<<">>10. [sound ] |make noise(?)."<<std::endl;
|
||||
}
|
||||
else if(command=="cls")
|
||||
{
|
||||
@@ -44,8 +43,6 @@ int main()
|
||||
lex.scanner(prog.get_resource());
|
||||
lex.print_token_list();
|
||||
}
|
||||
else if(command=="lib")
|
||||
prog.add_lib();
|
||||
else if(command=="del")
|
||||
{
|
||||
prog.set_clear();
|
||||
@@ -66,7 +63,7 @@ int main()
|
||||
{
|
||||
alert_sound();
|
||||
std::cout<<">>[Lexer] error(s) found,stop."<<std::endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if(command=="ast")
|
||||
{
|
||||
@@ -92,6 +89,7 @@ int main()
|
||||
}
|
||||
else if(command=="run")
|
||||
{
|
||||
prog.add_lib();
|
||||
lex.scanner(prog.get_resource());
|
||||
lex.generate_detail_token();
|
||||
if(!lex.get_error())
|
||||
|
||||
Reference in New Issue
Block a user