NameCheck
Re: NameCheck
OK, look forward to seeing your finished product.
--
All things QL - https://dilwyn.theqlforum.com
All things QL - https://dilwyn.theqlforum.com
Re: NameCheck
After thinking on this, it looks like perl is the best option over awk or text utilities (the GNU text utils don't have all that I was hoping for). Here is the perl script that will take a SuperBASIC file (with or without line numbers), generate a list of variables (assuming that all variables will be part of an assignment), and then compare that list of variables with a list of SuperBasic keywords.
Run it on the QL like this:
EXEC perl;"namecheck_pl < program_bas"
The program expects the file keywords_txt to be in the DATA_USE location. The file vars_txt will be created in the DATA_USE location. I start the work under LIinux and tested on the QL with SMSQmulator.
Tim
--------------------------------------------------------------------------------------------------
# PART 2 - Compare variables with keywords
Run it on the QL like this:
EXEC perl;"namecheck_pl < program_bas"
The program expects the file keywords_txt to be in the DATA_USE location. The file vars_txt will be created in the DATA_USE location. I start the work under LIinux and tested on the QL with SMSQmulator.
Tim
--------------------------------------------------------------------------------------------------
Code: Select all
#!/usr/bin/perl
# namecheck_pl
# PART 1 - get list of variables from SuperBASIC program
open(OUT,">var_txt") || die "failed to open var_txt";
while (<STDIN>) {
$str = " ".$_;
$a = index($str,"=");
if ($a != 0) {
$str = substr($str,0,$a);
if (substr($str,length($str)-1,1) eq " ") {
chop $str;
}
$str = reverse($str);
$a = index($str," ");
$str = substr($str,0,$a);
$str = reverse($str);
print OUT $str,"\n";
}
}
close(OUT);
Code: Select all
@words = "";
open(FILE,"keywords_txt") || die "Failed to open keywords_txt";
while (<FILE>) {
chop ($_);
push (@words,$_);
}
close(FILE);
open(IN,"var_txt") || die "failed to open var_txt";
while (<IN>) {
chop($_);
$_ =~ tr/a-z/A-Z/;
foreach $word (@words) {
if ($_ eq $word) {
print $_,"\n";
}
}
}
close(IN);
Re: NameCheck
It looks like the indenting was taking out of the program, but it should still work since Perl does not use white space for managing blocks of code.
Tim
Tim
- NormanDunbar
- Forum Moderator
- Posts: 2470
- Joined: Tue Dec 14, 2010 9:04 am
- Location: Buckie, Scotland
- Contact:
Re: NameCheck
Tim,
Fixed it for you Tim. (Admin privs rule!) -- hope you don't mind.
When posting code, use the "Code" button above the editor to create code markers, then type/paste your code between them. That keeps your formatting.
Useful for bigger bits. No good for inlining code as it always starts on a new line.
[/code]
HTH
Perl: is a "worn" language. Write once, read never!
Cheers,
Norm.
Fixed it for you Tim. (Admin privs rule!) -- hope you don't mind.
When posting code, use the "Code" button above the editor to create code markers, then type/paste your code between them. That keeps your formatting.
Useful for bigger bits. No good for inlining code as it always starts on a new line.
Code: Select all
[code]
Your code here.
With indentation preserved!
HTH
Perl: is a "worn" language. Write once, read never!

Cheers,
Norm.
Why do they put lightning conductors on churches?
Author of Arduino Software Internals
Author of Arduino Interrupts
No longer on Twitter, find me on https://mastodon.scot/@NormanDunbar.
Author of Arduino Software Internals
Author of Arduino Interrupts
No longer on Twitter, find me on https://mastodon.scot/@NormanDunbar.
- NormanDunbar
- Forum Moderator
- Posts: 2470
- Joined: Tue Dec 14, 2010 9:04 am
- Location: Buckie, Scotland
- Contact:
Re: NameCheck
I'm useless at Perl.
Does the code above correctly handle source lines where there is/are equal signs within a string?
For example.
I'm also wondering, if someone does something stupid like:
Where X and any of the other parameters, are keywords for a toolkit which is not currently loaded, those would need to be filtered out also, not just those in assignment statements.
This would apply to Dilwyn's version and yours I should imagine?
Just thinking out loud. These things have a tendency to get bigger the more you think about them.
Cheers,
Norm.
Cheers,
Norm.
Does the code above correctly handle source lines where there is/are equal signs within a string?
Code: Select all
1000 Version$ = "Toolkit version = 1.16"
I'm also wondering, if someone does something stupid like:
Code: Select all
DEFine FuNction whatEver(X, ...)
...
This would apply to Dilwyn's version and yours I should imagine?
Just thinking out loud. These things have a tendency to get bigger the more you think about them.
Cheers,
Norm.
Cheers,
Norm.
Why do they put lightning conductors on churches?
Author of Arduino Software Internals
Author of Arduino Interrupts
No longer on Twitter, find me on https://mastodon.scot/@NormanDunbar.
Author of Arduino Software Internals
Author of Arduino Interrupts
No longer on Twitter, find me on https://mastodon.scot/@NormanDunbar.
Re: NameCheck
Norman,
Thanks for the fix. The two sections should be all one script. Easy enough to be fixed by who ever downloads it.
In the example with version$, the script will find "version$" and compare that with the keyword list and it will not match if the keyword is "version". The script assumes that all variables must have an assignment, so I looked for "=".
I did not think about function or procedure names. If needed, I could create a version that looks for DEFine statements and strips out the name.
Tim
Thanks for the fix. The two sections should be all one script. Easy enough to be fixed by who ever downloads it.
In the example with version$, the script will find "version$" and compare that with the keyword list and it will not match if the keyword is "version". The script assumes that all variables must have an assignment, so I looked for "=".
I did not think about function or procedure names. If needed, I could create a version that looks for DEFine statements and strips out the name.
Tim
Re: NameCheck
Has anyone of you had a look into MasterBasic? A former commercial product that does a lot of what you're discussing here (Static S*Basic code analysis, and a lot more). I would definitely recommend it to anyone doing projects of considerable size in S*Basic.
ʎɐqǝ ɯoɹɟ ǝq oʇ ƃuᴉoƃ ʇou sᴉ pɹɐoqʎǝʞ ʇxǝu ʎɯ 'ɹɐǝp ɥO
-
- Font of All Knowledge
- Posts: 4684
- Joined: Mon Dec 20, 2010 11:40 am
- Location: Sunny Runcorn, Cheshire, UK
Re: NameCheck
Hi,
I used to use MasterBasic many years ago, it was a great programming upgrade. Now it is freeware, it worth a look at the features Masterbasic can give for programme development.
I used to use MasterBasic many years ago, it was a great programming upgrade. Now it is freeware, it worth a look at the features Masterbasic can give for programme development.
Regards,
Derek
Derek
Re: NameCheck
Bear in mind that NameCheck was never intended to compete with QREF, MasterBasic, Reporter etc, it had one sole aim in life, to check names used against a master list of keyword names.tofro wrote:Has anyone of you had a look into MasterBasic? A former commercial product that does a lot of what you're discussing here (Static S*Basic code analysis, and a lot more). I would definitely recommend it to anyone doing projects of considerable size in S*Basic.
Tim's script will be great and will do the job neatly and simply for those prepared to use Perl or similar.
The NameCheck program itself is so near to being finished I may as well complete it now. At least it did what Steve wanted. Update soon.
--
All things QL - https://dilwyn.theqlforum.com
All things QL - https://dilwyn.theqlforum.com
-
- QL Wafer Drive
- Posts: 1068
- Joined: Sat Oct 25, 2014 9:53 am
Re: NameCheck
Hi everyone
[Arguably going off-topic - or rather expanding upon this specific and valid use-case that Dilwyn's solution aims to address...]
I would also like to encourage exploring MasterBasic in this context - fundamentally it works 'within' the SBASIC environment, thus knows the context of each name in the Name Table, rather than trying to deduce usage from a purely external syntactical analysis using awk, sed and their ilk.
Whilst I'm not so thrilled in limiting SBASIC editing capability to what QDOS/SMSQE offer (i.e. ED), MasterBasic to my mind is a truly impressive bit of software engineering with some incredible SBASIC profiling tools. To my mind, if QD or some other SBASIC 'aware' editing tool could be integrated with MasterBasic's tools against a 'resident' SBASIC tokenised program, I think we'd have a fantastic basis for a next-gen SBASIC 'IDE'. Wishful thinking, I know...
[Arguably going off-topic - or rather expanding upon this specific and valid use-case that Dilwyn's solution aims to address...]
I would also like to encourage exploring MasterBasic in this context - fundamentally it works 'within' the SBASIC environment, thus knows the context of each name in the Name Table, rather than trying to deduce usage from a purely external syntactical analysis using awk, sed and their ilk.
Whilst I'm not so thrilled in limiting SBASIC editing capability to what QDOS/SMSQE offer (i.e. ED), MasterBasic to my mind is a truly impressive bit of software engineering with some incredible SBASIC profiling tools. To my mind, if QD or some other SBASIC 'aware' editing tool could be integrated with MasterBasic's tools against a 'resident' SBASIC tokenised program, I think we'd have a fantastic basis for a next-gen SBASIC 'IDE'. Wishful thinking, I know...