Some doubts

Some doubts

#1
in:
var x = 10;
output(string(x));
var x = 5;
free(x);
out:
10
error:
line 3: x has already been declared

#2
in:
var x = 10;
output(string(x));
out:
10
error:
line 1: x is not free

#3
in:
var x = 10;
output(string(x + 2));
x + 3;
sqrt(3 + 4);
string(x);
output(string(x));
out:
12
error:
line 3: invalid expression

#4
in:
var x = 10;
var y;
output(string(x + 2));
output(string(y));
out:
12
error:
line 4: y is used before its value is set

With line numbers. thanks, john_e_lille,Minh-Nhut Hong.

写字楼里写字间,写字间里程序员
程序人员写程序,又拿程序换酒钱
酒醒只在网上坐,酒醉还来网下眠
酒醉酒醒日复日,网上网下年复年
4 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

Quoting

#2
in:
var x = 10;
output(string(x));
out:
10
error:
x is not free

I think it is not error. You don't have to free all variables.

Another variant:

var x = 10;
output(string(x));

free(x);

free(x);

Error. Invalid expression in free.

#4 should be a syntax error:var y;It is not allowed to have uninitialized variables.Also it is required to output the line number on error messages, i think

The spec states that "Syntax errors should stop the execution with an error indicating the line number and the statement that caused the syntax error."

Leave a Comment

Please sign in to add a comment. Not a member? Join today