AlekId / dwscript

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

var blocks with multiple variables #403

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Currently the VAR keyword only allows a single statement. Would be nice if the 
VAR statement could accept a block with multiple "name:type;" entries as in 
real Pascal and compile the following script: 

VAR
  i : integer;   
  ix : integer = 3;   
  s : string:= 'abc';   

BEGIN
  assert(ix = 3);
END;

The CONST keyword calls "ReadConstDeclBlock()" and can do it already, the VAR 
keyword needs something similar, a new "ReadVarDeclBlock()" function. To avoid 
parsing ambiguities when the VAR keyword is used inside a BEGIN..END block (an 
inline variable) then the old "ReadVarDecl()" could be called to only accept a 
single entry.

Original issue reported on code.google.com by Fighting...@gmail.com on 27 May 2013 at 5:17

GoogleCodeExporter commented 9 years ago
In script mode, variables can be declared inline and mingled with code and 
declarations (the begin/end in your snippet is unnecessary), this dictates that 
var/const have to be explicit.

However, var/const blocks are allowed when declaring a function or in "classic" 
units (units that have interface/implementation sections).

Note that units in which you omit the "interface" keyword are considered to be 
"consolidated" and follow script syntax, and can optionally have function body 
inline in classes (as in Java or C#)

Original comment by zar...@gmail.com on 27 May 2013 at 6:17

GoogleCodeExporter commented 9 years ago
Thanks for the clarification Eric. 

That sounds like it's an enhancement that can't be cleanly implemented in 
DWScript because of that mixing (which isn't a bad feature, i actually like 
that idea). 

I went ahead and implemented my own customized ReadVarDeclBlock() to allow 
var-blocks in script mode ... my implementation parses single var-statements if 
used inline (if it's inside a BEGIN..END block) and allows a block of VAR 
statements if defined outside. But obviously the drawback of my approach is 
that i then require a ttBEGIN/ttCONST/ttPROCEDURE/etc token to know when to 
exit parsing the var-block. My implementation is Pascal like grammar and it's a 
drawback that i can live with, but maybe for others it would lead to 
compatibility issues with existing scripts.

ps: i tried to reach you at your glscene.org email address about 
exception-handling issue in dwscript, did you get that email?

Original comment by Fighting...@gmail.com on 27 May 2013 at 7:35

GoogleCodeExporter commented 9 years ago
I don't think I had that email, when was it sent? 

Original comment by zar...@gmail.com on 27 May 2013 at 7:59

GoogleCodeExporter commented 9 years ago
Can you contact me privately on fightingninjasucks (gmail.com) ... i cant see 
your full email address here. The exception issue isn't really an issue, just a 
question on how to best implement a particular feature that i require. Maybe 
something you can help me with in return for some sponsorship of DWScript?

Original comment by Fighting...@gmail.com on 27 May 2013 at 8:17