Jump to content

  • Log In with Google      Sign In   
  • Create Account

Interested in a FREE copy of HTML5 game maker Construct 2?

We'll be giving away three Personal Edition licences in next Tuesday's GDNet Direct email newsletter!

Sign up from the right-hand sidebar on our homepage and read Tuesday's newsletter for details!


We're also offering banner ads on our site from just $5! 1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


- - - - -

Parser bug: Expected expression value


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
5 replies to this topic

#1 virious   Members   -  Reputation: 181

Like
0Likes
Like

Posted 04 June 2012 - 03:19 AM

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 Posted Image.

Thanks in advance!

Sponsor:

#2 Andreas Jonsson   Moderators   -  Reputation: 3413

Like
0Likes
Like

Posted 04 June 2012 - 08:45 AM

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

#3 Andreas Jonsson   Moderators   -  Reputation: 3413

Like
0Likes
Like

Posted 04 June 2012 - 08:50 AM

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

#4 virious   Members   -  Reputation: 181

Like
0Likes
Like

Posted 04 June 2012 - 09:01 AM

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

#5 Andreas Jonsson   Moderators   -  Reputation: 3413

Like
0Likes
Like

Posted 04 June 2012 - 10:16 AM

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

#6 virious   Members   -  Reputation: 181

Like
0Likes
Like

Posted 05 June 2012 - 01:41 AM

Seems fair enough for me :). Thanks!




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS