diff --git a/README.md b/README.md index 9425c52..0d7272d 100644 --- a/README.md +++ b/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'. diff --git a/main.cpp b/main.cpp index 0e751a2..ff61bef 100644 --- a/main.cpp +++ b/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); diff --git a/nasal_lexer.h b/nasal_lexer.h index 5b330db..e97ee8c 100644 --- a/nasal_lexer.h +++ b/nasal_lexer.h @@ -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 diff --git a/nasal_parse.h b/nasal_parse.h index 7def769..07e60ca 100644 --- a/nasal_parse.h +++ b/nasal_parse.h @@ -99,12 +99,12 @@ private: nasal_ast ret_expr(); public: int get_error(){return error;} - void set_toklist(std::vector& toks){tok_list=toks;} - void main_process(); + void main_process(std::vector&); nasal_ast& get_root(){return root;} }; -void nasal_parse::main_process() +void nasal_parse::main_process(std::vector& toks) { + tok_list=toks; ptr=in_function=in_loop=error=0; root.clear(); error_token.clear(); diff --git a/test/ycombinator.nas b/test/ycombinator.nas new file mode 100644 index 0000000..e1ab01f --- /dev/null +++ b/test/ycombinator.nas @@ -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)); \ No newline at end of file