Some doubts

Some doubts

imagem de 邓辉

#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
Último post
Para obter mais informações sobre otimizações de compiladores, consulte Aviso sobre otimizações.
imagem de oshapovalov
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.

imagem de john_e_lilley

#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

imagem de Minh-Nhut Hong

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

Faça login para deixar um comentário.