update
This commit is contained in:
parent
418ce58cbf
commit
191f7e2ed9
|
@ -79,6 +79,13 @@ abstract_syntax_tree::abstract_syntax_tree(const abstract_syntax_tree& tmp)
|
||||||
|
|
||||||
abstract_syntax_tree::~abstract_syntax_tree()
|
abstract_syntax_tree::~abstract_syntax_tree()
|
||||||
{
|
{
|
||||||
|
node_type=__null_type;
|
||||||
|
line=0;
|
||||||
|
symbol_number=-1;
|
||||||
|
symbol_is_global=false;
|
||||||
|
var_number=0;
|
||||||
|
var_string.clear();
|
||||||
|
var_name.clear();
|
||||||
children.clear();
|
children.clear();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -117,10 +124,10 @@ void abstract_syntax_tree::print_tree_block(const int n)
|
||||||
case __string: std::cout<<": "<<var_string;break;
|
case __string: std::cout<<": "<<var_string;break;
|
||||||
case __id:
|
case __id:
|
||||||
case __dynamic_id:
|
case __dynamic_id:
|
||||||
|
case __call_hash:
|
||||||
std::cout<<": "<<var_name<<" (sym_num:"<<symbol_number<<"["<<(symbol_is_global? "global":"local")<<"])";
|
std::cout<<": "<<var_name<<" (sym_num:"<<symbol_number<<"["<<(symbol_is_global? "global":"local")<<"])";
|
||||||
break;
|
break;
|
||||||
case __call_vector:
|
case __call_vector:
|
||||||
case __call_hash:
|
|
||||||
case __call_function:break;
|
case __call_function:break;
|
||||||
default:break;
|
default:break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,6 +31,7 @@ int main()
|
||||||
std::cin>>command;
|
std::cin>>command;
|
||||||
if(command=="help")
|
if(command=="help")
|
||||||
{
|
{
|
||||||
|
std::cout<<">> be careful that this program does not support unicode(unicode will be set to \'?\')"<<std::endl;
|
||||||
std::cout<<">> [\'file\'] input a file."<<std::endl;
|
std::cout<<">> [\'file\'] input a file."<<std::endl;
|
||||||
std::cout<<">> [cls ] clear the screen."<<std::endl;
|
std::cout<<">> [cls ] clear the screen."<<std::endl;
|
||||||
std::cout<<">> [del ] clear the resource code."<<std::endl;
|
std::cout<<">> [del ] clear the resource code."<<std::endl;
|
||||||
|
|
|
@ -178,6 +178,48 @@ class nasal_lexer
|
||||||
std::list<token> token_list;
|
std::list<token> token_list;
|
||||||
std::list<token> detail_token_list;
|
std::list<token> detail_token_list;
|
||||||
int error;
|
int error;
|
||||||
|
std::string utf8_clear(std::string tmp)
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
0xxx xxxx 0x0 1 byte
|
||||||
|
110x xxxx 0xc0 2 byte
|
||||||
|
1110 xxxx 0xe0 3 byte
|
||||||
|
1111 0xxx 0xf0 4 byte
|
||||||
|
1111 10xx 0xf8 5 byte
|
||||||
|
1111 110x 0xfc 6 byte
|
||||||
|
bytes after it is:
|
||||||
|
10xx xxxx 0x80
|
||||||
|
|
||||||
|
so utf-8 format is:
|
||||||
|
0xxxxxxx
|
||||||
|
110xxxxx 10xxxxxx
|
||||||
|
1110xxxx 10xxxxxx 10xxxxxx
|
||||||
|
11110xxx 10xxxxxx 10xxxxxx 10xxxxxx
|
||||||
|
111110xx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx
|
||||||
|
1111110x 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx
|
||||||
|
*/
|
||||||
|
unsigned char utf8head[6]={0x0,0xc0,0xe0,0xf0,0xf8,0xfc};
|
||||||
|
std::string ret="";
|
||||||
|
for(int i=0;i<tmp.length();++i)
|
||||||
|
{
|
||||||
|
if(tmp[i]>=0)
|
||||||
|
ret+=tmp[i];
|
||||||
|
else
|
||||||
|
{
|
||||||
|
int utf8byte=0;
|
||||||
|
for(int j=5;j>=0;--j)
|
||||||
|
if((tmp[i] & utf8head[j])==utf8head[j])
|
||||||
|
{
|
||||||
|
utf8byte=j;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
for(int j=0;j<utf8byte;++j)
|
||||||
|
++i;
|
||||||
|
ret+='?';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
public:
|
public:
|
||||||
/*
|
/*
|
||||||
nasal_lexer();
|
nasal_lexer();
|
||||||
|
@ -350,7 +392,7 @@ class nasal_lexer
|
||||||
token new_token;
|
token new_token;
|
||||||
new_token.line=line;
|
new_token.line=line;
|
||||||
new_token.type=__token_string;
|
new_token.type=__token_string;
|
||||||
new_token.str=token_str;
|
new_token.str=utf8_clear(token_str);
|
||||||
token_list.push_back(new_token);
|
token_list.push_back(new_token);
|
||||||
}
|
}
|
||||||
++ptr;
|
++ptr;
|
||||||
|
|
|
@ -321,7 +321,7 @@ void nasal_symbol_table::symbol_table_block_generate(abstract_syntax_tree& node)
|
||||||
this->symbol_table_block_generate(*i);
|
this->symbol_table_block_generate(*i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if(node_type==__id)
|
else if((node_type==__id) || (node_type==__call_hash))
|
||||||
{
|
{
|
||||||
symbol_table_unit tmp;
|
symbol_table_unit tmp;
|
||||||
tmp.symbol_line=node.get_node_line();
|
tmp.symbol_line=node.get_node_line();
|
||||||
|
|
Loading…
Reference in New Issue