MaximusCZ Posted July 31 Share Posted July 31 (edited) Hi. I have a file that contains boolean expressions: ... IF ((KV = TRUE) AND (MH = FALSE)) OR (TV = TRUE) THEN GUN(GUN1, GunOn, PT5, TR5) END_IF ... I would like to read the file, parse those imporant bits, and save those in some data structure that allows me to "simulate a run" trough that file with all combinations of variables. I have trouble comming up with an idea on how to save the data in a way I can than use later. How do I model my data structure so that I can then assign "random" values(true/false) to vars (KV, MH..), and see if, given those variable values, the IF condition is satisfied or not (so whether Gun line gets read given set of variables). Theres gonna be max 10 IFs per file, and the maximum amount of variables is about 10, so bruteforcing seems like the easiest way (I will just try all combinations one after another) for simulation. But how do I code up the "solver" of these regular expressions? Edited July 31 by MaximusCZ Link to comment Share on other sites More sharing options...
jchd Posted July 31 Share Posted July 31 Lookup the 3-SAT problem: it's NP-complete. Hence 10-SAT isn't going to be any easier than NP. If fortunately you don't have to process gazillions of terms, you can still do something. To get your hands wet, try DPLL. This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt) Link to comment Share on other sites More sharing options...
MaximusCZ Posted August 1 Author Share Posted August 1 I am not really looking for efficient way to do it, as I said I think bruteforcing is completely acceptable approach here. I just do a pass on the file for each combination of inputs. The issue I have is "how" to parse and store the data in codeblock, so that it can then simulate executing the IF properly. Link to comment Share on other sites More sharing options...
Nine Posted August 1 Share Posted August 1 You can do everything in a single run : 1- parse all statements between IF ... THEN 2- parse all variables inside a statement (alpha chars before = sign) 3- Add $ sign before each variable inside a statement 4- Assign those vars to False / True in alternance 5- Execute the statement for each combination and show result “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...
MaximusCZ Posted August 1 Author Share Posted August 1 Already have 1. and 2. finished. I am not sure I follow the rest? Currently I store the vars in an array (KV, MH..), do I just do a pass on the array adding "$" in front of every element? How am I supposed to simulate the boolean logic on the whole statement? Link to comment Share on other sites More sharing options...
Solution Nine Posted August 1 Solution Share Posted August 1 (edited) Execute function (see help file) will do the boolean logic for the whole statement Assign function (see help file) will set each variable to True/False StringReplace function will replace each var with $var inside a statement You need to create a loop to assign in alternance each var to true/false edit : Local $aVar = ["KV", "MH", "TV"] Local $sStatement = "((KV = TRUE) AND (MH = FALSE)) OR (TV = TRUE)" Local $nVar = UBound($aVar), $sList, $bRes $sStatement = StringRegExpReplace($sStatement, "([A-Z]+ =)", "\$\1") ConsoleWrite($sStatement & @CRLF) For $i = 0 To (2 ^ $nVar) - 1 $sList = "" For $j = 0 To $nVar - 1 Assign($aVar[$j], BitAND($i, 2 ^ $j) ? True : False) $sList &= $aVar[$j] & " = " & Eval($aVar[$j]) & @TAB Next $bRes = Execute($sStatement) ConsoleWrite($sList & ":: " & $bRes & @CRLF) Next Edited August 1 by Nine change replace approach pixelsearch and MaximusCZ 2 “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...
MaximusCZ Posted August 1 Author Share Posted August 1 (edited) Absolutely amazing, thanks! Had no idea about Execute and Assign function existing at all , now it make sense why you made them Bold in your original post Edited August 1 by MaximusCZ Link to comment Share on other sites More sharing options...
Developers Jos Posted August 1 Developers Share Posted August 1 10 hours ago, MaximusCZ said: so whether Gun line gets read Care to explain what this is all about? SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
MaximusCZ Posted August 1 Author Share Posted August 1 (edited) 9 hours ago, Jos said: Care to explain what this is all about? Sure thing! I am reading files containing movement/application programs for atomotive industrial paintshop robots. Each file consists of points and triggers. Points for actual robot movement, and triggers for events like opening/closing the main needle (GunOn/Off), changing application parameters (flow amount of color/air etc) and possibly much more. In this case the IFs are for panel repairs, making the robot paint only the areas that are marked by the factory to be repainted, hence the GunOn/Off events in IFs. The problem I am facing is that if those conditions are made the easy way, theres a high chance a robot will encounter two GunOns in a row (without GunOff in between), and for some stupid reason this raises an alarm. So every condition must be carefully crafted to only trigger precisely as needed, making sure that all condition states from before are considered. Its clunky, its unintuitive, but its reality. I am writing a macro capable of reading these programs, simulating "going trough" the program in sequence for all possible combinations of variables (usually less than 5 in a single module), and making sure such things cant happen. No need to worry, I am not writing a game bot, I am aware of the rules Thanks for taking care of AutoIt and its users so consistently over the years, its really helping. Also 69th comment, nice.. Edited August 1 by MaximusCZ Link to comment Share on other sites More sharing options...
Developers Jos Posted August 1 Developers Share Posted August 1 1 hour ago, MaximusCZ said: No need to worry, I am not writing a game bot, I am aware of the rules Thanks for taking care of AutoIt and its users so consistently over the years, its really helping. Thanks for explaining and sorry to be a pain, but I am trying to avoid some pain we experienced in the old days. MaximusCZ 1 SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
Nine Posted August 1 Share Posted August 1 Modified the code above from StringReplace to StringRegExpReplace. Should avoid bug if 2 vars are similar (ex. BC and ABC) “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