Forum
Var declaration checking - Printable Version

+- Forum (https://www.boriel.com/forum)
+-- Forum: Compilers and Computer Languages (https://www.boriel.com/forum/forumdisplay.php?fid=12)
+--- Forum: ZX Basic Compiler (https://www.boriel.com/forum/forumdisplay.php?fid=11)
+---- Forum: Wishlist (https://www.boriel.com/forum/forumdisplay.php?fid=14)
+---- Thread: Var declaration checking (/showthread.php?tid=515)



Var declaration checking - wilco2009 - 12-18-2012

Please, Could be possible to add an command option to require declare all variables.
I think, not declared variables is the source of bugs more difficult to find.
The problem is worse when you consider that BASIC is case sensitive.


Re: Var declaration checking - boriel - 12-21-2012

This is "pending" task; it will eventually be implemented. It's the flag Explicit (see -lang qb)
<!-- m --><a class="postlink" href="http://www.freebasic.net/wiki/wikka.php?wakka=KeyPgOptionexplicit">http://www.freebasic.net/wiki/wikka.php ... onexplicit</a><!-- m -->

I will implement it both as
#pragma option explicit

and as a command line flag: --option explicit

What do you think?


Re: Var declaration checking - wilco2009 - 12-21-2012

Perfect!
I think the sintaxis is very clear.
When you have the option implemented, I'll start using it.
As Pascal enthusiast, I think it should be active by default.


Re: Var declaration checking - boriel - 12-22-2012

wilco2009 Wrote:Perfect!
I think the sintaxis is very clear.
When you have the option implemented, I'll start using it.
As Pascal enthusiast, I think it should be active by default.
So do I. ZX BASIC started as a project with high Sinclair BASIC compatibility, but with the time I started to diverge in order to achieve higher performance. For compatibility, people should always use the --sinclair flag.


Re: Var declaration checking - boriel - 12-22-2012

Okay, I think I've implemented this one. Download 1.3.0s959.
Use:
Code:
zxb --explicit <yourprogram.bas>
To compile it.
The following program:
Code:
LET a = 5
Should trigger an error if you compile it with --explicit option.
You can also use #pragmas in source code, which is a way to change compiling options from within the source code.
Code:
REM The following line will override command line parameters
#pragma explicit = True
LET a = 5
NOTE: The OPTION command won't be implemented (it's being deprecated even in FreeBASIC). #pragmas are used in C/C++ compilers, and FreeBASIC. So ZXBASIC will support them too.


Re: Var declaration checking - wilco2009 - 12-22-2012

It's great!

Many thanks. Both options are checked and are working perfectly.