update
This commit is contained in:
parent
368baa0561
commit
e2a50a61e6
|
@ -27,11 +27,11 @@ void help()
|
||||||
|
|
||||||
void logo()
|
void logo()
|
||||||
{
|
{
|
||||||
std::cout<<" __ _ "<<std::endl;
|
std::cout<<" __ _ \n";
|
||||||
std::cout<<" /\\ \\ \\__ _ ___ __ _| | "<<std::endl;
|
std::cout<<" /\\ \\ \\__ _ ___ __ _| | \n";
|
||||||
std::cout<<" / \\/ / _` / __|/ _` | | "<<std::endl;
|
std::cout<<" / \\/ / _` / __|/ _` | | \n";
|
||||||
std::cout<<" / /\\ / (_| \\__ \\ (_| | | "<<std::endl;
|
std::cout<<" / /\\ / (_| \\__ \\ (_| | | \n";
|
||||||
std::cout<<" \\_\\ \\/ \\__,_|___/\\__,_|_|"<<std::endl;
|
std::cout<<" \\_\\ \\/ \\__,_|___/\\__,_|_|\n";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -41,13 +41,13 @@ void del_func()
|
||||||
lexer.clear();
|
lexer.clear();
|
||||||
parse.clear();
|
parse.clear();
|
||||||
inputfile="null";
|
inputfile="null";
|
||||||
std::cout<<">> [Delete] complete."<<std::endl;
|
std::cout<<">> [Delete] complete.\n";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
void die(std::string stage,std::string filename)
|
void die(std::string stage,std::string filename)
|
||||||
{
|
{
|
||||||
std::cout<<">> ["<<stage<<"] in <\""<<filename<<"\">: error(s) occurred,stop."<<std::endl;
|
std::cout<<">> ["<<stage<<"] in <\""<<filename<<"\">: error(s) occurred,stop.\n";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -180,19 +180,19 @@ int main()
|
||||||
#endif
|
#endif
|
||||||
logo();
|
logo();
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
std::cout<<">> [system] Windows system."<<std::endl;
|
std::cout<<">> [system] Windows system.\n";
|
||||||
#endif
|
#endif
|
||||||
#ifdef _linux_
|
#ifdef _linux_
|
||||||
std::cout<<">> [system] Linux system."<<std::endl;
|
std::cout<<">> [system] Linux system.\n";
|
||||||
#endif
|
#endif
|
||||||
#ifdef TARGET_OS_MAC
|
#ifdef TARGET_OS_MAC
|
||||||
std::cout<<">> [system] MacOS system."<<std::endl;
|
std::cout<<">> [system] MacOS system.\n";
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
std::cout<<">> Nasal interpreter ver 3.0 ."<<std::endl;
|
std::cout<<">> Nasal interpreter ver 3.0 .\n";
|
||||||
std::cout<<">> Code: https://github.com/ValKmjolnir/Nasal-Interpreter"<<std::endl;
|
std::cout<<">> Code: https://github.com/ValKmjolnir/Nasal-Interpreter\n";
|
||||||
std::cout<<">> Info: http://wiki.flightgear.org/Nasal_scripting_language"<<std::endl;
|
std::cout<<">> Info: http://wiki.flightgear.org/Nasal_scripting_language\n";
|
||||||
std::cout<<">> Input \"help\" to get help ."<<std::endl;
|
std::cout<<">> Input \"help\" to get help .\n";
|
||||||
while(1)
|
while(1)
|
||||||
{
|
{
|
||||||
std::cout<<">> ";
|
std::cout<<">> ";
|
||||||
|
@ -238,7 +238,7 @@ int main()
|
||||||
std::ifstream fin(command);
|
std::ifstream fin(command);
|
||||||
if(fin.fail())
|
if(fin.fail())
|
||||||
{
|
{
|
||||||
std::cout<<">> [file] cannot open file \""<<command<<"\"."<<std::endl;
|
std::cout<<">> [file] cannot open file \""<<command<<"\".\n";
|
||||||
inputfile="null";
|
inputfile="null";
|
||||||
}
|
}
|
||||||
fin.close();
|
fin.close();
|
||||||
|
|
|
@ -207,34 +207,40 @@ std::string nasal_lexer::string_gen(std::vector<char>& res,int& ptr,int& line)
|
||||||
{
|
{
|
||||||
int res_size=res.size();
|
int res_size=res.size();
|
||||||
std::string token_str="";
|
std::string token_str="";
|
||||||
char str_begin=res[ptr];
|
char str_begin=res[ptr++];
|
||||||
++ptr;
|
|
||||||
if(ptr>=res_size) return token_str;
|
if(ptr>=res_size) return token_str;
|
||||||
while(ptr<res_size && res[ptr]!=str_begin)
|
while(ptr<res_size && res[ptr]!=str_begin)
|
||||||
{
|
{
|
||||||
token_str+=res[ptr];
|
|
||||||
if(res[ptr]=='\n') ++line;
|
if(res[ptr]=='\n') ++line;
|
||||||
if(res[ptr]=='\\' && ptr+1<res.size())
|
if(res[ptr]=='\\' && ptr+1<res.size())
|
||||||
{
|
{
|
||||||
++ptr;
|
++ptr;
|
||||||
switch(res[ptr])
|
switch(res[ptr])
|
||||||
{
|
{
|
||||||
case '\\':token_str.pop_back();token_str.push_back('\\');break;
|
case 'a':token_str.push_back('\a');break;
|
||||||
case 'r': token_str.pop_back();token_str.push_back('\r');break;
|
case 'b':token_str.push_back('\b');break;
|
||||||
case 't': token_str.pop_back();token_str.push_back('\t');break;
|
case 'f':token_str.push_back('\f');break;
|
||||||
case 'n': token_str.pop_back();token_str.push_back('\n');break;
|
case 'n':token_str.push_back('\n');break;
|
||||||
case '\'':token_str.pop_back();token_str.push_back('\'');break;
|
case 'r':token_str.push_back('\r');break;
|
||||||
case '\"':token_str.pop_back();token_str.push_back('\"');break;
|
case 't':token_str.push_back('\t');break;
|
||||||
|
case 'v':token_str.push_back('\v');break;
|
||||||
|
case '?':token_str.push_back('\?');break;
|
||||||
|
case '0':token_str.push_back('\0');break;
|
||||||
|
case '\\':token_str.push_back('\\');break;
|
||||||
|
case '\'':token_str.push_back('\'');break;
|
||||||
|
case '\"':token_str.push_back('\"');break;
|
||||||
default: token_str.push_back(res[ptr]);break;
|
default: token_str.push_back(res[ptr]);break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
token_str+=res[ptr];
|
||||||
++ptr;
|
++ptr;
|
||||||
}
|
}
|
||||||
// check if this string ends with a " or '
|
// check if this string ends with a " or '
|
||||||
if(ptr>=res_size)
|
if(ptr>=res_size)
|
||||||
{
|
{
|
||||||
++error;
|
++error;
|
||||||
std::cout<<">> [lexer] line "<<line<<": this string must have a \' "<<str_begin<<" \' as its end."<<std::endl;
|
std::cout<<">> [lexer] line "<<line<<": get EOF when generating string.\n";
|
||||||
}
|
}
|
||||||
++ptr;
|
++ptr;
|
||||||
return token_str;
|
return token_str;
|
||||||
|
|
Loading…
Reference in New Issue