diff --git a/README.md b/README.md index 28e1518..9425c52 100644 --- a/README.md +++ b/README.md @@ -71,11 +71,7 @@ The interpreter's interactive mode will do this automatically,so you don't need LL(k) parser. ```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); ``` @@ -83,6 +79,32 @@ These two expressions have the same first set,so LL(1) is useless for this langu Maybe in the future i can refactor it to LL(1) with special checks. +Problems mentioned above have been solved for a long time, but recently i found a new problem here: + +```javascript +var f=func(x,y,z){return x+y+z} +(a,b,c)=(0,1,2); +``` + +This will be recognized as this: + +```javascript +var f=func(x,y,z){return x+y+z}(a,b,c) +=(0,1,2); +``` + +and causes fatal syntax error. +And i tried this program in flightgear nasal console. +It also found this is a syntax error. +I think this is a serious design fault. +To avoid this syntax error, change program like this, just add a semicolon: + +```javascript +var f=func(x,y,z){return x+y+z}; + ^ here +(a,b,c)=(0,1,2); +``` + ### version 1.0(last update 2019/10/14) First fully functional version of nasal_parser. diff --git a/nasal_parse.h b/nasal_parse.h index e8bd46b..7def769 100644 --- a/nasal_parse.h +++ b/nasal_parse.h @@ -658,15 +658,16 @@ nasal_ast nasal_parse::scalar() die(error_line,"expected scalar"); return node; } - if(is_call(tok_list[ptr].type)) + // check call and avoid ambiguous syntax + if(is_call(tok_list[ptr].type) && !(tok_list[ptr].type==tok_lcurve && tok_list[ptr+1].type==tok_var)) { nasal_ast tmp=std::move(node); node.set_line(tok_list[ptr].line); node.set_type(ast_call); node.add_child(std::move(tmp)); + while(is_call(tok_list[ptr].type)) + node.add_child(call_scalar()); } - while(is_call(tok_list[ptr].type)) - node.add_child(call_scalar()); return node; } nasal_ast nasal_parse::call_scalar()