update
This commit is contained in:
parent
9fe7a86a3b
commit
7a93f5b89b
21
README.md
21
README.md
|
@ -34,13 +34,13 @@ Better choose the latest update of the interpreter.
|
||||||
|
|
||||||
MUST USE -O2/-O3 if want to optimize the interpreter!
|
MUST USE -O2/-O3 if want to optimize the interpreter!
|
||||||
|
|
||||||
Also remember to use g++ and clang++.
|
Also remember to use g++ or clang++.
|
||||||
|
|
||||||
> g++ | clang++ -std=c++11 -O2 main.cpp -o nasal.exe
|
> [cpp compiler] -std=c++11 -O2 main.cpp -o nasal.exe
|
||||||
|
|
||||||
Or use this in linux/macOS/Unix
|
Or use this in linux/macOS/Unix
|
||||||
|
|
||||||
> g++ | clang++ -std=c++11 -O2 main.cpp -o nasal
|
> [cpp compiler] -std=c++11 -O2 main.cpp -o nasal
|
||||||
|
|
||||||
## How to Use?
|
## How to Use?
|
||||||
|
|
||||||
|
@ -71,7 +71,11 @@ The interpreter's interactive mode will do this automatically,so you don't need
|
||||||
LL(k) parser.
|
LL(k) parser.
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
(var a,b,c)=[{b:nil},[1,2],func{return 0;}];
|
(var a,b,c)=[
|
||||||
|
{b:nil},
|
||||||
|
[1,2],
|
||||||
|
func{return 0;}
|
||||||
|
];
|
||||||
(a.b,b[0],c)=(1,2,3);
|
(a.b,b[0],c)=(1,2,3);
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -485,7 +489,13 @@ var b="another string";
|
||||||
var b=`c`;
|
var b=`c`;
|
||||||
|
|
||||||
var c=[];
|
var c=[];
|
||||||
var c=[0,nil,{},[],func(){return 0;}];
|
var c=[
|
||||||
|
0,
|
||||||
|
nil,
|
||||||
|
{},
|
||||||
|
[],
|
||||||
|
func(){return 0;}
|
||||||
|
];
|
||||||
append(c,0,1,2);
|
append(c,0,1,2);
|
||||||
|
|
||||||
var d={
|
var d={
|
||||||
|
@ -690,6 +700,7 @@ nasal_val* builtin_print(std::vector<nasal_val*>& local_scope,nasal_gc& gc)
|
||||||
case vm_hash: i->ptr.hash->print(); break;
|
case vm_hash: i->ptr.hash->print(); break;
|
||||||
case vm_func: std::cout<<"func(...){...}"; break;
|
case vm_func: std::cout<<"func(...){...}"; break;
|
||||||
}
|
}
|
||||||
|
std::cout<<std::flush;
|
||||||
// if a nasal value is not in use,use gc::del_reference to delete it
|
// if a nasal value is not in use,use gc::del_reference to delete it
|
||||||
// generate return value,use gc::gc_alloc(type) to make a new value
|
// generate return value,use gc::gc_alloc(type) to make a new value
|
||||||
// or use reserved reference gc.nil_addr/gc.one_addr/gc.zero_addr
|
// or use reserved reference gc.nil_addr/gc.one_addr/gc.zero_addr
|
||||||
|
|
|
@ -124,6 +124,7 @@ nasal_val* builtin_print(std::vector<nasal_val*>& local_scope,nasal_gc& gc)
|
||||||
case vm_hash: i->ptr.hash->print(); break;
|
case vm_hash: i->ptr.hash->print(); break;
|
||||||
case vm_func: std::cout<<"func(...){...}"; break;
|
case vm_func: std::cout<<"func(...){...}"; break;
|
||||||
}
|
}
|
||||||
|
std::cout<<std::flush;
|
||||||
// generate return value
|
// generate return value
|
||||||
return gc.nil_addr;
|
return gc.nil_addr;
|
||||||
}
|
}
|
||||||
|
|
|
@ -68,7 +68,7 @@ private:
|
||||||
nasal_ast func_gen();
|
nasal_ast func_gen();
|
||||||
nasal_ast args_gen();
|
nasal_ast args_gen();
|
||||||
nasal_ast expr();
|
nasal_ast expr();
|
||||||
nasal_ast exprs_gen();
|
nasal_ast exprs();
|
||||||
nasal_ast calc();
|
nasal_ast calc();
|
||||||
nasal_ast or_expr();
|
nasal_ast or_expr();
|
||||||
nasal_ast and_expr();
|
nasal_ast and_expr();
|
||||||
|
@ -362,7 +362,7 @@ nasal_ast nasal_parse::func_gen()
|
||||||
node.add_child(args_gen());
|
node.add_child(args_gen());
|
||||||
else
|
else
|
||||||
node.add_child(null_node_gen());
|
node.add_child(null_node_gen());
|
||||||
node.add_child(exprs_gen());
|
node.add_child(exprs());
|
||||||
return node;
|
return node;
|
||||||
}
|
}
|
||||||
nasal_ast nasal_parse::args_gen()
|
nasal_ast nasal_parse::args_gen()
|
||||||
|
@ -476,7 +476,7 @@ nasal_ast nasal_parse::expr()
|
||||||
}
|
}
|
||||||
return node;
|
return node;
|
||||||
}
|
}
|
||||||
nasal_ast nasal_parse::exprs_gen()
|
nasal_ast nasal_parse::exprs()
|
||||||
{
|
{
|
||||||
if(tok_list[ptr].type==tok_eof)
|
if(tok_list[ptr].type==tok_eof)
|
||||||
{
|
{
|
||||||
|
@ -875,7 +875,7 @@ nasal_ast nasal_parse::while_loop()
|
||||||
match(tok_lcurve);
|
match(tok_lcurve);
|
||||||
node.add_child(calc());
|
node.add_child(calc());
|
||||||
match(tok_rcurve);
|
match(tok_rcurve);
|
||||||
node.add_child(exprs_gen());
|
node.add_child(exprs());
|
||||||
return node;
|
return node;
|
||||||
}
|
}
|
||||||
nasal_ast nasal_parse::for_loop()
|
nasal_ast nasal_parse::for_loop()
|
||||||
|
@ -921,7 +921,7 @@ nasal_ast nasal_parse::for_loop()
|
||||||
else
|
else
|
||||||
node.add_child(calc());
|
node.add_child(calc());
|
||||||
match(tok_rcurve);
|
match(tok_rcurve);
|
||||||
node.add_child(exprs_gen());
|
node.add_child(exprs());
|
||||||
return node;
|
return node;
|
||||||
}
|
}
|
||||||
nasal_ast nasal_parse::forei_loop()
|
nasal_ast nasal_parse::forei_loop()
|
||||||
|
@ -945,7 +945,7 @@ nasal_ast nasal_parse::forei_loop()
|
||||||
die(error_line,"expected vector");
|
die(error_line,"expected vector");
|
||||||
node.add_child(calc());
|
node.add_child(calc());
|
||||||
match(tok_rcurve);
|
match(tok_rcurve);
|
||||||
node.add_child(exprs_gen());
|
node.add_child(exprs());
|
||||||
return node;
|
return node;
|
||||||
}
|
}
|
||||||
nasal_ast nasal_parse::new_iter_gen()
|
nasal_ast nasal_parse::new_iter_gen()
|
||||||
|
@ -976,7 +976,7 @@ nasal_ast nasal_parse::conditional()
|
||||||
match(tok_lcurve);
|
match(tok_lcurve);
|
||||||
tmp.add_child(calc());
|
tmp.add_child(calc());
|
||||||
match(tok_rcurve);
|
match(tok_rcurve);
|
||||||
tmp.add_child(exprs_gen());
|
tmp.add_child(exprs());
|
||||||
node.add_child(std::move(tmp));
|
node.add_child(std::move(tmp));
|
||||||
// end of if-expression
|
// end of if-expression
|
||||||
while(tok_list[ptr].type==tok_elsif)
|
while(tok_list[ptr].type==tok_elsif)
|
||||||
|
@ -986,14 +986,14 @@ nasal_ast nasal_parse::conditional()
|
||||||
match(tok_lcurve);
|
match(tok_lcurve);
|
||||||
tmp.add_child(calc());
|
tmp.add_child(calc());
|
||||||
match(tok_rcurve);
|
match(tok_rcurve);
|
||||||
tmp.add_child(exprs_gen());
|
tmp.add_child(exprs());
|
||||||
node.add_child(std::move(tmp));
|
node.add_child(std::move(tmp));
|
||||||
}
|
}
|
||||||
if(tok_list[ptr].type==tok_else)
|
if(tok_list[ptr].type==tok_else)
|
||||||
{
|
{
|
||||||
nasal_ast tmp(tok_list[ptr].line,ast_else);
|
nasal_ast tmp(tok_list[ptr].line,ast_else);
|
||||||
match(tok_else);
|
match(tok_else);
|
||||||
tmp.add_child(exprs_gen());
|
tmp.add_child(exprs());
|
||||||
node.add_child(std::move(tmp));
|
node.add_child(std::move(tmp));
|
||||||
}
|
}
|
||||||
return node;
|
return node;
|
||||||
|
|
Loading…
Reference in New Issue