CYCho Posted October 1, 2020 Share Posted October 1, 2020 (edited) Sometimes I wondered how many keywords were used in my particular script. When I was trying to persuade one of my friends to learn coding, I told him that a few hundred words were all he had to learn to speak a decent computer language, while he had to learn several thousand words to speak a decent English as a foreign language. As a proof I counted the number of keywords used in my zPlayer.au3 with the following code and it was 185. As only standard UDF files were used in the script, I think this is a pretty close count. My question: Is there a simpler and more accurate way of counting the number of keywords used in a script, especially when external UDFs are included, in which case the function names are not listed in au3.keywrods.properties file? #include <Array.au3> $sPath = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\autoit3.exe", "") $allKeywords = FileReadToArray(StringReplace($sPath, "autoit3.exe", "SciTE\au3.keywords.properties")) $sScript = FileRead("d:\zplayer\zplayer.au3") Local $aKeywordsUsed[1] For $i = 1 To UBound($allKeywords)-1 $sLine = StringStripWS($allKeywords[$i], 3) If StringInStr($sLine, "=") Then $sLine = StringMid($sLine, StringInStr($sLine, "=")+1) EndIf $sLine = StringReplace($sLine, " \", "") $aLine = StringSplit($sLine, " ") For $j = 1 To $aLine[0] If StringInStr($sScript, $aLine[$j]) Then _ArrayAdd($aKeywordsUsed, $aLine[$j]) EndIf Next Next $aKeywordsUsed[0] = UBound($aKeywordsUsed)-1 _ArraySort($aKeywordsUsed, 0, 1) _ArrayDisplay($aKeywordsUsed) Edited October 1, 2020 by CYCho zPlayer - A Small Audio and Video Player Time Sync + SystemTimeAdjustment Link to comment Share on other sites More sharing options...
JockoDundee Posted October 1, 2020 Share Posted October 1, 2020 1 hour ago, CYCho said: As a proof I counted the number of keywords used in my zPlayer.au3 with the following code and it was 185 and yet the number of keywords in the entire language is around 50. CYCho 1 Code hard, but don’t hard code... Link to comment Share on other sites More sharing options...
RTFC Posted October 1, 2020 Share Posted October 1, 2020 CodeScanner will give you detailed lists of all functions, variables, and macros used in a script. CYCho and mLipok 1 1 My Contributions and Wrappers Spoiler BitMaskSudokuSolver BuildPartitionTable CodeCrypter CodeScanner DigitalDisplay Eigen4AutoIt FAT Suite HighMem MetaCodeFileLibrary OSgrid Pool RdRand SecondDesktop SimulatedAnnealing Xbase I/O Link to comment Share on other sites More sharing options...
Nine Posted October 1, 2020 Share Posted October 1, 2020 It all depends on what you call keywords. But the true base definition of keywords in AutoIt is clearly documented here : https://www.autoitscript.com/autoit3/docs/keywords.htm “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
CYCho Posted October 1, 2020 Author Share Posted October 1, 2020 By keywords, I meant those entries in the AutoIt Help file and similar UDF function names which have not yet made it to the Help file. I found that au3.keywords.properties file in the SciTE folder contains all the current keywords satisfying my definition. zPlayer - A Small Audio and Video Player Time Sync + SystemTimeAdjustment Link to comment Share on other sites More sharing options...
Musashi Posted October 1, 2020 Share Posted October 1, 2020 (edited) 3 hours ago, Nine said: It all depends on what you call keywords. This is exactly the crucial point (in my opinion). @CYCho : The base definition of keywords in AutoIt will certainly not be sufficient for your project. Without the AutoIt functions it will hardly be possible to write a program. Therefore I would consider functions and possibly relevant constants as keywords. I would create my own list of keywords (as a file - one keyword per line). As a basis I would use the au3.keywords.properties, just as you have already planned yourself. You can then enhance this list with function names of non-standard UDF's if required. @CYCho EDIT : OK, you were faster BTW : If you analyze a script the following would be useful: #AutoIt3Wrapper_Run_Au3Stripper=y #Au3Stripper_Parameters=/MO So all includes are contained in one file. Comments should also be ignored, because they may have keywords in them. Edited October 1, 2020 by Musashi CYCho 1 "In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move." Link to comment Share on other sites More sharing options...
JockoDundee Posted October 1, 2020 Share Posted October 1, 2020 11 hours ago, CYCho said: By keywords, I meant those entries in the AutoIt Help file and similar UDF function names which have not yet made it to the Help file. I found that au3.keywords.properties file in the SciTE folder contains all the current keywords satisfying my definition. In that case, why not include all unique function calls used , regardless of source, and all @ macros used as well as any predefined $ constants. Otherwise you are being arbitrary, imo. Code hard, but don’t hard code... Link to comment Share on other sites More sharing options...
Nine Posted October 2, 2020 Share Posted October 2, 2020 I think your definition of keywords is wrong. The moment a UDF is adding a new function, you would need to modify your list. Based on you definition, there is an unlimited number of keywords, which of course does not make sense. You must want to talk of (instead of keywords) a dictionary of functions. “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now