add test file
This commit is contained in:
parent
4e1a3c5f2d
commit
91771297d3
29
README.md
29
README.md
|
@ -485,15 +485,15 @@ running time:
|
|||
|
||||
Nasal has 6 value types.Number,string,vector,hash,function,nil.
|
||||
|
||||
Number has 3 formats.Dec,hex and oct;
|
||||
__Number__ has 3 formats.Dec,hex and oct;
|
||||
|
||||
String has 3 formats.But the third one is often used to declare a character.
|
||||
__String__ has 3 formats.But the third one is often used to declare a character.
|
||||
|
||||
Vector has unlimited length and can store all types of values.
|
||||
__Vector__ has unlimited length and can store all types of values.
|
||||
|
||||
Hash is a hashmap that stores values with strings/identifiers as the key.
|
||||
__Hash__ is a hashmap that stores values with strings/identifiers as the key.
|
||||
|
||||
Function is also a value type in nasal.
|
||||
__Function__ is also a value type in nasal.
|
||||
|
||||
```javascript
|
||||
var spc=nil;
|
||||
|
@ -591,25 +591,19 @@ var (a,b,c)=(0,1,2);
|
|||
```javascript
|
||||
(a,b[0],c.d)=[0,1,2];
|
||||
(a,b[1],c.e)=(0,1,2);
|
||||
(a,b)=(b,a);
|
||||
```
|
||||
|
||||
### conditional expression
|
||||
|
||||
```javascript
|
||||
if(1)
|
||||
{
|
||||
if(1){
|
||||
;
|
||||
}
|
||||
elsif(2)
|
||||
{
|
||||
}elsif(2){
|
||||
;
|
||||
}
|
||||
else if(3)
|
||||
{
|
||||
}else if(3){
|
||||
;
|
||||
}
|
||||
else
|
||||
{
|
||||
}else{
|
||||
;
|
||||
}
|
||||
```
|
||||
|
@ -849,3 +843,6 @@ You will get an error of 'undefined symbol', instead of nothing happening in mos
|
|||
|
||||
This change is __controversial__ among FGPRC's members.
|
||||
So maybe in the future i will use dynamic analysis again to cater to the habits of senior programmers.
|
||||
|
||||
In this new interpreter, function doesn't put dynamic arguments into vector 'arg' automatically.
|
||||
So if you use 'arg' without definition, you'll get an error of 'undefined symbol'.
|
||||
|
|
3
main.cpp
3
main.cpp
|
@ -67,8 +67,7 @@ void execute(std::string& file,std::string& command)
|
|||
die("lexer",file);
|
||||
return;
|
||||
}
|
||||
parse.set_toklist(lexer.get_token_list());
|
||||
parse.main_process();
|
||||
parse.main_process(lexer.get_token_list());
|
||||
if(parse.get_error())
|
||||
{
|
||||
die("parse",file);
|
||||
|
|
|
@ -90,7 +90,7 @@ struct token
|
|||
int line;
|
||||
int type;
|
||||
std::string str;
|
||||
token(int l=0,int t=tok_null,std::string s=""){line=l;type=t;str=s;return;}
|
||||
token(int l=0,int t=tok_null,std::string s=""){line=l;type=t;str=s;}
|
||||
};
|
||||
|
||||
class nasal_lexer
|
||||
|
|
|
@ -99,12 +99,12 @@ private:
|
|||
nasal_ast ret_expr();
|
||||
public:
|
||||
int get_error(){return error;}
|
||||
void set_toklist(std::vector<token>& toks){tok_list=toks;}
|
||||
void main_process();
|
||||
void main_process(std::vector<token>&);
|
||||
nasal_ast& get_root(){return root;}
|
||||
};
|
||||
void nasal_parse::main_process()
|
||||
void nasal_parse::main_process(std::vector<token>& toks)
|
||||
{
|
||||
tok_list=toks;
|
||||
ptr=in_function=in_loop=error=0;
|
||||
root.clear();
|
||||
error_token.clear();
|
||||
|
|
|
@ -0,0 +1,18 @@
|
|||
# Y combinator by ValKmjolnir
|
||||
|
||||
import("lib.nas");
|
||||
var count=0;
|
||||
var fib=func(f){
|
||||
return f(f);
|
||||
}(
|
||||
func(f){
|
||||
return func(x){
|
||||
count+=1;
|
||||
if(x<2) return x;
|
||||
return f(f)(x-1)+f(f)(x-2);
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
for(var i=1;i<=20;i+=1)
|
||||
println(fib(i));
|
Loading…
Reference in New Issue