mirror of
https://github.com/ValKmjolnir/Nasal-Interpreter.git
synced 2026-07-26 21:08:45 +08:00
Update
This commit is contained in:
@@ -1,15 +1,14 @@
|
|||||||
#ifndef __ABSTRACT_SYNTAX_TREE_CPP__
|
#ifndef __ABSTRACT_SYNTAX_TREE_CPP__
|
||||||
#define __ABSTRACT_SYNTAX_TREE_CPP__
|
#define __ABSTRACT_SYNTAX_TREE_CPP__
|
||||||
|
|
||||||
balloon_scope global;
|
|
||||||
int exit_type=0;
|
int exit_type=0;
|
||||||
var abstract_syntax_tree::call_id()
|
var abstract_syntax_tree::call_id()
|
||||||
{
|
{
|
||||||
var temp;
|
var temp;
|
||||||
if(children.empty())
|
if(children.empty())
|
||||||
{
|
{
|
||||||
if(global.search_var(name))
|
if(scope.search_var(name))
|
||||||
temp=global.get_var(name);
|
temp=scope.get_var(name);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
std::cout<<">>[Runtime-error] cannot find a var named \'"<<name<<"\'."<<std::endl;
|
std::cout<<">>[Runtime-error] cannot find a var named \'"<<name<<"\'."<<std::endl;
|
||||||
@@ -59,7 +58,7 @@ var abstract_syntax_tree::get_value()
|
|||||||
}
|
}
|
||||||
void abstract_syntax_tree::run_root()
|
void abstract_syntax_tree::run_root()
|
||||||
{
|
{
|
||||||
global.set_clear();
|
scope.set_clear();
|
||||||
int beg_time,end_time;
|
int beg_time,end_time;
|
||||||
exit_type=__process_exited_successfully;
|
exit_type=__process_exited_successfully;
|
||||||
beg_time=time(NULL);
|
beg_time=time(NULL);
|
||||||
@@ -70,10 +69,10 @@ void abstract_syntax_tree::run_root()
|
|||||||
var new_var;
|
var new_var;
|
||||||
std::list<abstract_syntax_tree>::iterator j=i->children.begin();
|
std::list<abstract_syntax_tree>::iterator j=i->children.begin();
|
||||||
std::string _name=j->name;
|
std::string _name=j->name;
|
||||||
if(!global.search_var(_name))
|
if(!scope.search_var(_name))
|
||||||
{
|
{
|
||||||
new_var.set_name(_name);
|
new_var.set_name(_name);
|
||||||
global.add_var(new_var);
|
scope.add_new_var(new_var);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -87,7 +86,7 @@ void abstract_syntax_tree::run_root()
|
|||||||
else if(i->type==__string)
|
else if(i->type==__string)
|
||||||
std::cout<<i->str<<std::endl;
|
std::cout<<i->str<<std::endl;
|
||||||
else if(i->type==__id)
|
else if(i->type==__id)
|
||||||
i->call_id();
|
std::cout<<i->call_id().get_name()<<std::endl;
|
||||||
else if(i->type==__while)
|
else if(i->type==__while)
|
||||||
{
|
{
|
||||||
;
|
;
|
||||||
@@ -96,14 +95,32 @@ void abstract_syntax_tree::run_root()
|
|||||||
{
|
{
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(exit_type!=__process_exited_successfully)
|
if(exit_type!=__process_exited_successfully)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
end_time=time(NULL);
|
end_time=time(NULL);
|
||||||
|
std::cout<<"-------------------------------------------------------------------------------------------"<<std::endl;
|
||||||
std::cout<<">>[Runtime] process exited after "<<end_time-beg_time<<" sec(s) with returned state \'";
|
std::cout<<">>[Runtime] process exited after "<<end_time-beg_time<<" sec(s) with returned state \'";
|
||||||
print_exit_type(exit_type);
|
print_exit_type(exit_type);
|
||||||
std::cout<<"\'."<<std::endl;
|
std::cout<<"\'."<<std::endl;
|
||||||
|
scope.set_clear();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
void abstract_syntax_tree::run_func()
|
||||||
|
{
|
||||||
|
scope.add_new_block_scope();
|
||||||
|
scope.add_new_local_scope();
|
||||||
|
|
||||||
|
scope.pop_last_block_scope();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
void abstract_syntax_tree::run_block(int block_type)
|
||||||
|
{
|
||||||
|
scope.add_new_local_scope();
|
||||||
|
|
||||||
|
scope.pop_last_local_scope();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -111,5 +128,4 @@ void abstract_syntax_tree::run_root()
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -194,6 +194,8 @@ class abstract_syntax_tree
|
|||||||
var call_id();
|
var call_id();
|
||||||
var get_value();
|
var get_value();
|
||||||
void run_root();
|
void run_root();
|
||||||
|
void run_func();
|
||||||
|
void run_block(int);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -68,6 +68,7 @@ class var
|
|||||||
};
|
};
|
||||||
|
|
||||||
var error_var;
|
var error_var;
|
||||||
|
|
||||||
void var::set_type(int _type)
|
void var::set_type(int _type)
|
||||||
{
|
{
|
||||||
type=_type;
|
type=_type;
|
||||||
|
|||||||
+5
-3
@@ -1,9 +1,11 @@
|
|||||||
#include "balloon.h"
|
#include "balloon.h"
|
||||||
|
|
||||||
|
resource_file prog;
|
||||||
|
balloon_lexer lex;
|
||||||
|
balloon_parse pas;
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
resource_file prog;
|
|
||||||
balloon_lexer lex;
|
|
||||||
balloon_parse pas;
|
|
||||||
std::string command;
|
std::string command;
|
||||||
std::cout<<">> Balloon interpreter by ValKmjolnir"<<std::endl;
|
std::cout<<">> Balloon interpreter by ValKmjolnir"<<std::endl;
|
||||||
std::cout<<">> Input [help] to find help."<<std::endl;
|
std::cout<<">> Input [help] to find help."<<std::endl;
|
||||||
|
|||||||
@@ -0,0 +1,23 @@
|
|||||||
|
var a=1;
|
||||||
|
var b=2;
|
||||||
|
var c="string";
|
||||||
|
var d='str';
|
||||||
|
var e=[];
|
||||||
|
var f={};
|
||||||
|
var g=[0,'str',[],{}];
|
||||||
|
var h={
|
||||||
|
va1:1,
|
||||||
|
va2:"str",
|
||||||
|
va3:'s',
|
||||||
|
va4:[],
|
||||||
|
va5:{fuck:0}
|
||||||
|
};
|
||||||
|
a=2;
|
||||||
|
b=3;
|
||||||
|
c="hello world!";
|
||||||
|
var i=func(v1,v2,v3){return [0,0,0];};
|
||||||
|
107374;
|
||||||
|
"str";
|
||||||
|
'fuck';
|
||||||
|
a;
|
||||||
|
z;
|
||||||
Reference in New Issue
Block a user