syntax bug fixed

syntax like:
var f=func(){}
(var a,b,c)=(1,2,3);
will be incorrectly recognized like:
var f=func(){}(var a,b,c)

this bug is fixed now.
This commit is contained in:
ValKmjolnir 2021-08-01 02:11:27 +08:00
parent df634cb1b2
commit 4e1a3c5f2d
2 changed files with 31 additions and 8 deletions

View File

@ -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.

View File

@ -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()