Advertisement

Parser bug: Expected expression value

Started by June 04, 2012 09:19 AM
4 comments, last by virious 12 years, 6 months ago
Let's say I have a weird script which looks like this:

int main()
{
int some_value;
if(some_value >= 3)
int a=3;

return 0;
}


It should compile, but AngelScript throws me an error:
test.as (39, 2) : ERR: Expected expression value

I think this case is omitted in asCScriptNode *asCParser::ParseExprValue() method in as_parser.cpp.

Test was performed on HEAD revision of the AngelScript smile.png.

Thanks in advance!
I'll look into this. However, is the error message really from compiling that script? The error is reported for line 39, but there are obviously not 39 lines in the script.

Regards,
Andreas

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

Advertisement
I rechecked the script, and I don't think it should compile. The error message should definitely be improved, but the problem here is the declaration of a variable in the if-case. That is not allowed.

The if condition must be followed by a statement or a statement-block, a variable declaration is not expected here.

You might argue the variable declaration should be allowed, but what is the point of allowing it, since it will immediately go out of scope after the initialization?


I'll make changes to improve the error message.

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

I know that this code is useless (just as you mentioned) but our scripter used that code, to set breakpoint at some temporary place and he wrote that piece of code and that's how we found this error thing. In C++ that code compiles without any errors so I thinkg it should be also allowed in AngelScript even though it's useless (because of variable which immediately goes out of scope).
C++ is more forgiving about user errors than I want AngelScript to be. It is actually a quite common bug in C++ to declare a local variable in an if-condition like this, but with the intention that the variable should live on beyond the scope of the condition. Usually you catch the problem when attempting to use the variable, but if the variable happen to have the same name as another in a higher scope it can be difficult to catch the error. By giving an error in the compiler I can avoid that common bug in AngelScript.

If there is a valid need to declare the variable like this then the declaration must be done within a statement block, i.e. between {}.

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

Seems fair enough for me :). Thanks!

This topic is closed to new replies.

Advertisement