renan-guimaraes / dwscript

Automatically exported from code.google.com/p/dwscript
0 stars 0 forks source link

Global variable declarations require "var" on every line #292

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
The following script will fail with 
Syntax Error: Unknown name "s" [line: 2, column: 3]

//**************
var i : Integer;
  s : string;

s := 'DWS';
PrintLn(s);
for i:=1 to 10 do
   PrintLn(IntToStr(i));
//**************

The var is not required on every line within a procedure or function.
Is a fix possible? We have lots of scripts that are being converted to DWS.

Many Thanks!

Tom

Original issue reported on code.google.com by tom.robe...@gmail.com on 6 Aug 2012 at 7:07

GoogleCodeExporter commented 9 years ago
Isolated variables declarations are not blocks in scripting or mixed-mode, as 
the syntax would be ambiguous otherwise, f.i.

  var i := 123; // declares a new variable i and assigns it 123
  j := 456; // assigns 456 to existing variable j

If you want variable blocks, you can use a unit structure (unit / interface / 
implementation) or place them in blocks at the beginning of procedure 
declarations.

Original comment by zar...@gmail.com on 6 Aug 2012 at 7:56