Prepare for running

This commit is contained in:
Valk Richard Li 2019-09-25 06:54:17 -05:00 committed by GitHub
parent eaa2740d63
commit 36353389f8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 117 additions and 5 deletions

View File

@ -17,4 +17,9 @@ id();
id.id();
id.id.id();
id[0].id.id(id,"str",1,2,3,4).id[10];
id(0)[1].id;
id(0)[1].id;
var hash={
h:"hello",
parent:[id],
};
function_test([1,2,3,4,55],1,2,3,{str:"str"});

View File

@ -60,7 +60,7 @@ int main()
lex.lexer_process(prog.use_file());
lex.token_list_type_detail_edit();
pas.parse_process(lex.return_list());
// pas.gen_main_prog();
pas.parse_main_work();
pas.print_ast();
}
else if(command=="run")
@ -68,7 +68,7 @@ int main()
lex.lexer_process(prog.use_file());
lex.token_list_type_detail_edit();
pas.parse_process(lex.return_list());
// pas.gen_main_prog();
pas.parse_main_work();
pas.run();
}
else

View File

@ -10,8 +10,11 @@
#include "nasal_token_type.h"
#include "abstract_syntax_tree.h"
#include "nasal_var.h"
#include "nasal_lexer.h"
#include "nasal_parser.h"
#include "nasal_var.cpp"
#endif

View File

@ -356,8 +356,8 @@ void nasal_parser::definition_expr()
else if(this_token.type==__semi)
{
parse.push(this_token);// for semi check
++warning;
std::cout<<">>[Warning] line "<<this_token.line<<": better initializing this."<<std::endl;
// ++warning;
// std::cout<<">>[Warning] line "<<this_token.line<<": better initializing this."<<std::endl;
return;
}
get_token();
@ -799,6 +799,8 @@ void nasal_parser::call_function_expr()
case __number:number_begin_expr();break;
case __string:string_begin_expr();break;
case __id:identifier_begin_expr();break;
case __left_bracket:list_generate_expr();break;
case __left_brace:hash_generate_expr();break;
default:
++error;
std::cout<<">>[Error] line "<<this_token.line<<": incorrect token '";

53
version1.0/nasal_var.cpp Normal file
View File

@ -0,0 +1,53 @@
#ifndef __NASAL_VAR_CPP__
#define __NASAL_VAR_CPP__
var::var()
{
ptr=NULL;
type=var_null;
}
var::var(const var& temp)
{
switch(temp.type)
{
case var_null:ptr=NULL;break;
case var_number:ptr=new double;*((double*)ptr)=*((double*)temp.ptr);break;
case var_string:ptr=new std::string;*((std::string*)ptr)=*((std::string*)temp.ptr);break;
case var_list:ptr=new nasal_list;*((nasal_list*)ptr)=*((nasal_list*)temp.ptr);break;
case var_hash:ptr=new nasal_hash;*((nasal_hash*)ptr)=*((nasal_hash*)temp.ptr);break;
}
type=temp.type;
}
var::~var()
{
switch(type)
{
case var_null:break;
case var_number:delete (double*)ptr;break;
case var_string:delete (std::string*)ptr;break;
case var_list:delete (nasal_list*)ptr;break;
case var_hash:delete (nasal_hash*)ptr;break;
}
}
nasal_list::nasal_list()
{
elem.clear();
}
nasal_list::nasal_list(const nasal_list& temp)
{
elem=temp.elem;
}
nasal_hash::nasal_hash()
{
elem.clear();
elem_name.clear();
}
nasal_hash::nasal_hash(const nasal_hash& temp)
{
elem=temp.elem;
elem_name=temp.elem_name;
}
#endif

49
version1.0/nasal_var.h Normal file
View File

@ -0,0 +1,49 @@
#ifndef __NASAL_VAR_H__
#define __NASAL_VAR_H__
#include <cstring>
#include <list>
enum var_type
{
var_null=0xaa55,
var_number,
var_string,
var_list,
var_hash
};
class nasal_list;
class nasal_hash;
class var
{
private:
void* ptr;
int type;
public:
var();
var(const var&);
~var();
};
class nasal_list
{
private:
std::list<var> elem;
public:
nasal_list();
nasal_list(const nasal_list&);
};
class nasal_hash
{
private:
std::list<var> elem;
std::list<std::string> elem_name;
public:
nasal_hash();
nasal_hash(const nasal_hash&);
};
#endif