Leaderboard
Popular Content
Showing content with the highest reputation on 08/18/2014 in all areas
-
It's impossible to accept every context-free language with a finite-state automaton. The language you're describing is a context-free language, but isn't a regular language. That means that there is no regular expression that can do that for you.A simplified grammar of your language could be: expression -> expression + term | term term -> term * factor | factor factor -> ( expression ) | string | number | identifier You can write a simple recursive descent parser which will accept your language. You simply write these rules in AutoIt: #include <Array.au3> #Region Parser Func ParseExpression (Const ByRef $charArray, ByRef $index, ByRef $errors) Local $expression = ParseTerm ($charArray, $index, $errors) While $charArray [$index] == "+" $index += 1 Local $newExpression = ["+", $expression, ParseTerm ($charArray, $index, $errors)] $expression = $newExpression WEnd Return $expression EndFunc Func ParseTerm (Const ByRef $charArray, ByRef $index, ByRef $errors) Local $term = ParseFactor ($charArray, $index, $errors) While $charArray [$index] == "*" $index += 1 Local $newTerm = ["*", $term, ParseFactor ($charArray, $index, $errors)] $term = $newTerm WEnd Return $term EndFunc Func ParseFactor (Const ByRef $charArray, ByRef $index, ByRef $errors) If $charArray [$index] == "(" Then $index += 1 Local $factor = ["()", ParseExpression ($charArray, $index, $errors)] If $charArray [$index] == ")" Then $index += 1 Else _ArrayAdd ($errors, "syntax error: missing ')' at " & $index) EndIf Return $factor EndIf If $charArray [$index] == '"' Then Return ParseString ($charArray, $index, $errors) If NextIsNumber ($charArray, $index) Then Return ParseNumber ($charArray, $index, $errors) Return ParseIdentifier ($charArray, $index, $errors) EndFunc Func NextIsNumber (Const ByRef $charArray, ByRef $index) Local $charCode = Asc ($charArray [$index]) Return $charCode >= Asc ("0") And $charCode <= Asc ("9") EndFunc Func ParseNumber (Const ByRef $charArray, ByRef $index, ByRef $errors) Local $number = 0 Do $number *= 10 $number += Asc ($charArray [$index]) - Asc ("0") $index += 1 Until Not NextIsNumber ($charArray, $index) Local $result = ["number", $number] Return $result EndFunc Func ParseString (Const ByRef $charArray, ByRef $index, ByRef $errors) Local $string = "" $index += 1 ; Keep it simple and do not allow escape sequences. While $charArray [$index] <> '"' And $index < UBound ($charArray) - 1 $string &= $charArray [$index] $index += 1 WEnd If $charArray [$index] == '"' Then $index += 1 Else _ArrayAdd ($errors, "syntax error: missing '""' at " & $index) EndIf Local $result = ["string", $string] Return $result EndFunc Func NextIsIdentifierStart (Const ByRef $charArray, ByRef $index) Return $charArray [$index] == "$" Or $charArray [$index] == "@" Or $charArray [$index] == "_" Or StringRegExp ($charArray [$index], "\p{L}") EndFunc Func NextIsIdentifierPart (Const ByRef $charArray, ByRef $index) Return StringRegExp ($charArray [$index], "\w") EndFunc Func ParseIdentifier (Const ByRef $charArray, ByRef $index, ByRef $errors) Local $identifier = $charArray [$index] $index += 1 While NextIsIdentifierPart ($charArray [$index]) $identifier &= $charArray [$index] WEnd Local $result = ["identifier", $identifier] Return $result EndFunc Func Parse (Const ByRef $expression, ByRef $errors) Local $charArray = StringSplit (StringRegExpReplace ($expression & Chr (0), "\s", ""), "") Local $index = 1 ; StringRegExpReplace doesn't return a zero-based array. Local $result = ParseExpression ($charArray, $index, $errors) If $index < UBound ($charArray) - 1 Then _ArrayAdd ($errors, "syntax error: unexpected character at " & $index) If UBound ($errors) > 0 Then SetError (1, UBound ($errors)) Return $result EndFunc #EndRegion #Region Visitor Func VisitExpression (ByRef $expression) Switch $expression [0] Case "+" Return VisitAddition ($expression) Case "*" Return VisitMultiplication ($expression) Case "()" Return VisitParentheses ($expression) Case "number" Return VisitNumber ($expression) Case "string" Return VisitString ($expression) Case "identifier" Return VisitIdentifier ($expression) EndSwitch EndFunc Func VisitAddition (ByRef $expression) Return VisitExpression ($expression [1]) & " + " & VisitExpression ($expression [2]) EndFunc Func VisitMultiplication (ByRef $expression) Return VisitExpression ($expression [1]) & " * " & VisitExpression ($expression [2]) EndFunc Func VisitParentheses (ByRef $expression) Return "(" & VisitExpression ($expression [1]) & ")" EndFunc Func VisitNumber (ByRef $expression) Return $expression [1] EndFunc Func VisitString (ByRef $expression) Return '"' & $expression [1] & '"' EndFunc Func VisitIdentifier (ByRef $expression) Return $expression [1] EndFunc #EndRegion Local $defaultExpression = '0*1 + 2*(34 + "5") + 6' Local $expression = InputBox ("", "Please enter an expression.", $defaultExpression) If @error Then Exit Local $output = "Before: " & $expression & @CRLF & @CRLF Local $errors [0] Local $abstractSyntaxTree = Parse ($expression, $errors) If @error Then $output &= UBound ($errors) & " error(s):" & @CRLF For $i = 1 To UBound ($errors) $output &= $i & ". " & $errors [$i - 1] & @CRLF Next $output &= @CRLF EndIf Local $transformedExpression = VisitExpression ($abstractSyntaxTree) $output &= "After: " & $transformedExpression & @CRLF & @CRLF Func _Sin ($argument) Return Sin ($argument) EndFunc Local $result = Execute ($transformedExpression) $output &= "Result: " & $result MsgBox (0, "", $output) A general visitor (VisitExpression($visitAddition,$visitMultiplication,...,ByRef $expression) with VisitAddition(ByRef $expression,$visitExpression)) isn't possible (without first-class functions).3 points
-
As the code is public you could try to change it on your own. Just add on Keygen.au3 a new include (license.au3 uses this include already): #include <Crypt.au3> And on both, Keygen.au3 and license.au3 add a new function which acts as a wrapper for old _StringEncrypt() function: Func _StringEncrypt($fEncryptDecrypt, $sData, $sPassword) _Crypt_Startup() Local $sResult = "" If $fEncryptDecrypt = 1 Then $sResult = Hex(_Crypt_EncryptData($sData, $sPassword, $CALG_AES_256)) Else $sResult = BinaryToString(_Crypt_DecryptData("0x" & $sData, $sPassword, $CALG_AES_256)) EndIf _Crypt_Shutdown() Return $sResult EndFunc ;==>_StringEncrypt Note 1: The new encryption is not compatible with the encryption used in old _StringEncrypt(). Note 2: I don't use this UDF so I did not test it. Cheers, sahsanu1 point
-
HotKeySet("{F3}", "StartProcess")
232showtime reacted to BrewManNH for a topic
Use GUISetAccelerators instead of HotKeySet, this will make the hotkeys only active when that window is active and not globally.1 point -
You can change this a little and also use parameters if you need to. If $CMDLINE[0] > 0 then Switch $CMDLINE[0] Case 1 Call($CMDLINE[1]) Case 2 Call($CMDLINE[1],$CMDLINE[2]) Case 3 Call($CMDLINE[1],$CMDLINE[2],$CMDLINE[3]) Case 4 Call($CMDLINE[1],$CMDLINE[2],$CMDLINE[3],$CMDLINE[4]) Case 5 Call($CMDLINE[1],$CMDLINE[2],$CMDLINE[3],$CMDLINE[4],$CMDLINE[5]) Case Else ; EndSwitch Exit EndIf _RunExternal("_MyExternallyRanFunction") _RunExternal("_MyExternallyRanFunction",'"I have 1 param"') _RunExternal("_MyExternallyRanFunction",'"I have 2 params" "See this is my Second param"') _RunExternal("_MyExternallyRanFunction",'"I have 3 params" "This is my Second param" "And this is my Third param"') _RunExternal("_MyExternallyRanFunction",'"I have 4 params" "This is my Second param" "This is my Third param" "Look it''s my Fourth param"') MsgBox(0,"Msgbox1","I am running from the main script!" & @crlf & "My PID = " & @AutoItPID) Func _RunExternal($COMMAND,$Param = "") If @Compiled then Run('"' & @ScriptFullPath & '" ' & $COMMAND & " " & $Param, @ScriptDir) Else Run('"' & @AutoItExe & '" /AutoIt3ExecuteScript "' & @ScriptFullPath & '" ' & $COMMAND & " " & $Param,@ScriptDir) EndIf EndFunc Func _MyExternallyRanFunction($param1="",$param2="",$param3="",$param4="") Msgbox(0,"Msgbox2","I am the message box running in an external process" & @crlf & "My PID = " & @AutoItPID & @CRLF & $param1 & @CRLF & $param2 & @CRLF & $param3 & @CRLF & $param4) EndFunc1 point
-
With the help of ChrisL i made this so far that is suitable for my usage. Just want to share, maybe someone find it useful. _FuncAsProcess.au3 If $CMDLINE[0] Then Call($CMDLINE[1]) Exit EndIf Func _FuncAsProcess($Function) If @Compiled Then Return Run('"' & @ScriptFullPath & '" ' & $Function, @ScriptDir) Else Return Run('"' & @AutoItExe & '" /AutoIt3ExecuteScript "' & @ScriptFullPath & '" ' & $Function, @ScriptDir) EndIf EndFunc _FuncAsProcess Example #NoTrayIcon #include <_FuncAsProcess.au3> GUICreate('_FuncAsProcess', 250, 100) $chkEnable = GUICtrlCreateCheckbox('Enable Loop', 10, 10) GUISetState() While True Switch GUIGetMsg() Case -3 Exit Case $chkEnable If GuiCtrlRead($chkEnable) = 1 Then $ProcessID = _FuncAsProcess('_StartLoop') Else ProcessClose($ProcessID) EndIf EndSwitch WEnd Func _StartLoop() $i = 1 While $i > 0 ToolTip($i) $i += 1 Sleep(10) WEnd EndFunc1 point