#Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_Icon=HighLevel.ico #AutoIt3Wrapper_Outfile=HighLevel.Exe #AutoIt3Wrapper_UseX64=y #Tidy_Parameters=/reel /gd /gds /ri #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** ;~ #NoTrayIcon ;T:\Projects\HighLevel\test.HighLevel #include #include #include #include #include Const $EMPTY = '' #include "debug.au3" ;################################################################################################## HotKeySet('{ESC}', 'Abort') Func Abort() Exit EndFunc Opt('TrayMenuMode', 3) ;~ Const $About = TrayCreateItem('About') ;~ Const $Quit = TrayCreateItem('Quit') Const $TITLE = 'Console' _Singleton($TITLE, 0) #Region form Const $Form = GUICreate($TITLE, 301, 173, 5, 5, $WS_POPUP, BitOR($WS_EX_LAYERED, $WS_EX_TOPMOST)) GUISetBkColor(0xFFFFFF) Const $Minimize = GUICtrlCreateLabel($EMPTY, 173, 10, 21, 4, $SS_WHITERECT) Const $Close = GUICtrlCreateLabel($EMPTY, 218, 10, 21, 4, $SS_WHITERECT) Const $Log = GUICtrlCreateEdit('Loading', 30, 30, 241, 111, $ES_AUTOVSCROLL, $WS_TABSTOP) GUICtrlSetFont(Default, 8, 800, 0, 'Lucida Console') GUICtrlSetColor(Default, 0xFFFF00) GUICtrlSetBkColor(Default, 0x000000) GUICtrlSetCursor(Default, 5) GUICtrlSendMsg(Default, $em_limittext, Default, 0) GUICtrlCreatePic(@ScriptDir & '\GUI.BMP', 0, 0, 301, 173, Default, $GUI_WS_EX_PARENTDRAG) GUISetState(@SW_SHOW) #EndRegion form Global $EMPTYLOG Func ClearLog() GUICtrlSetData($Log, '') $EMPTYLOG = True EndFunc Func ColorLog($hex) GUICtrlSetColor($Log, $hex) EndFunc Func WriteLog($text) _GUICtrlEdit_AppendText($Log, ($EMPTYLOG ? $EMPTY : @CRLF) & $text) $EMPTYLOG = False EndFunc ;################################################################################################## $Regexp = ObjCreate('vbscript.regexp') $Regexp.Global = True $Regexp.IgnoreCase = True #Region language Const $CodeSplit = "(\r\n)+|'([^\r\n']|'')*'|#[^\r\n]*|[a-z_][a-z_0-9]*|[0-9]+|[+\-*/&>=!<(),\[\]]|\S+" Const $CodeIgnore = '^#[^\r\n]*$' Const $CodeNewline = '^(\r\n)+$' Const $CodeString = "^'([^\r\n']|'')*'$" Const $CodeVariable = '^([a-z_][a-z_0-9]*)$' Const $CodeNumber = '^(-?[0-9]+)$' Const $CodeSymbol = '^([+\-*/&>=!<(),\[\]])$' ;~ Const $CodeKeyword = '^(And|Or|Not|Show|Hide|Write|Clear|Message|Move|Beep|Click|Send|Wait|Sub|Call|If|Then|Else(If)?|For|To|End|Abort)$' Const $CodeKeyword = '^(And|Or|Not|Show|Hide|Write|Clear|Message|Move|Beep|Click|Send|Wait|Sub|Call|If|Else(If)?|For|To|End|Abort)$' Const $CodeMacro = '^(Input|YesNo|True|False|Random)$' #EndRegion language Func Match($Pattern, $String) $Regexp.pattern = $Pattern Return $Regexp.test($String) EndFunc ;################################################################################################## Const $TYPE = 0, $VALUE = 1 Global $LINE = 1 Local $TOKEN = 0 Local $Tokens[2][0] ;[ ;t0 = [a, b, c], ;t1 = [1, 2, 3] ;] Const $EXCLAMATION = 262192 Const $CRITICAL = 262160 Func ScriptError($Content, $Bad = False) ColorLog(0xFF0000) WriteLog('A script error occured!') MsgBox($Bad ? $CRITICAL : $EXCLAMATION, $TITLE, _ $Content & @CRLF & @CRLF & _ 'Line: ' & $LINE & ((TokenPeek($TYPE) = $EMPTY) ? $EMPTY : @CRLF & _ 'Token: ' & TokenPeek($TYPE) & @CRLF & _ 'Value: ' & TokenPeek($VALUE)) _ ) Abort() EndFunc Func TokenPush($typ, $val) ;$tokens ReDim $Tokens[2][UBound($Tokens, 2) + 1] $Tokens[$TYPE][UBound($Tokens, 2) - 1] = $typ $Tokens[$VALUE][UBound($Tokens, 2) - 1] = $val EndFunc Func Tokenize() ;tokenpush -> $tokens, $line = 1, $token = 0 Local $plusline Local $Content = FileRead($cmdline[1]) $Regexp.pattern = $CodeSplit Local $execute = $Regexp.execute($Content) For $t = 0 To $execute.count - 1 If Match($CodeIgnore, $execute($t).value) Then ContinueLoop Select Case Match($CodeNewline, $execute($t).value) $plusline = StringLen($execute($t).value) / 2 TokenPush('newline', $plusline) $LINE += $plusline Case Match($CodeString, $execute($t).value) Local $_ = StringReplace(StringMid($execute($t).value, 2, StringLen($execute($t).value) - 2), "''", "'") TokenPush(VarType($_), $_) Case Match($CodeKeyword, $execute($t).value) TokenPush('keyword', $execute($t).value) Case Match($CodeMacro, $execute($t).value) TokenPush('macro', $execute($t).value) Case Match($CodeVariable, $execute($t).value) TokenPush('variable', $execute($t).value) Case Match($CodeNumber, $execute($t).value) TokenPush('number', Int($execute($t).value)) Case Match($CodeSymbol, $execute($t).value) TokenPush('symbol', $execute($t).value) Case Else ScriptError('Undefined token: ' & $execute($t).value, False) EndSelect $TOKEN += 1 Next $LINE = 1 $TOKEN = 0 EndFunc ;################################################################################################## Global $VAR[0][2] Global $SUB[0][2] Global $PROGRAM[0] ;-------------------------------------------------------------------------------------------------- Func ListPush($item, ByRef $array) ReDim $array[UBound($array) + 1] $array[UBound($array) - 1] = $item EndFunc ;-------------------------------------------------------------------------------------------------- Func BuildTree() Do ;do becouse tokens.count is > 0 ListPush(Statement(), $PROGRAM) Until TokenPeek($TYPE) = $EMPTY EndFunc ;################################################################################################## Func TokenNext() ;$token If $TOKEN < TokenCount() Then $TOKEN += 1 EndFunc Func TokenCount() Return UBound($Tokens, 2) EndFunc Func TokenPeek($Data) Return TokenCount() > $TOKEN ? $Tokens[$Data][$TOKEN] : $EMPTY EndFunc Func TokenExpect($typ, $val = $EMPTY) If Not ((TokenPeek($TYPE) = $typ) And (($val = $EMPTY) ? True : TokenPeek($VALUE) = $val)) Then ScriptError('[' & $typ & ':' & $val & '] expected!') EndFunc Func TokenTest($typ, $val, $reg = False) Return (TokenPeek($TYPE) = $typ) And ($reg ? Match($val, TokenPeek($VALUE)) : (TokenPeek($VALUE) = $val)) EndFunc ;-------------------------------------------------------------------------------------------------- Func Statement() ;expression does a 'token_next'... Local $Statement[0] ; remove if $empty from IF? Select Case TokenPeek($TYPE) = 'newline' ListPush('newline', $Statement) $LINE += TokenPeek($VALUE) ListPush($LINE, $Statement) TokenNext() Return $Statement Case TokenTest('keyword', '^(Abort|Clear|Click|Hide|Show)$', True) ListPush(TokenPeek($VALUE), $Statement) TokenNext() Case TokenTest('keyword', 'Move') ListPush(TokenPeek($VALUE), $Statement) TokenNext() ListPush(EXPRESSION(), $Statement) TokenExpect('symbol', ',') TokenNext() ListPush(EXPRESSION(), $Statement) Case TokenTest('keyword', 'Send') ListPush(TokenPeek($VALUE), $Statement) TokenNext() ListPush(EXPRESSION(), $Statement) If TokenTest('symbol', ',') Then TokenNext() ListPush(EXPRESSION(), $Statement) Else ListPush($EMPTY, $Statement) EndIf Case TokenTest('keyword', 'Beep') ListPush(TokenPeek($VALUE), $Statement) TokenNext() Switch TokenPeek($TYPE) Case $EMPTY, 'newline' ListPush($EMPTY, $Statement) ListPush($EMPTY, $Statement) Case Else ListPush(EXPRESSION(), $Statement) If TokenTest('symbol', ',') Then TokenNext() ListPush(EXPRESSION(), $Statement) Else ListPush($EMPTY, $Statement) EndIf EndSwitch Case TokenTest('keyword', 'if') ListPush(TokenPeek($VALUE), $Statement) ; If | [EXPn] | line | [STMTn] | 'line' | Local $exps[0], $lnes[0], $stms[0] do TokenNext() ListPush(EXPRESSION(), $exps) ;~ TokenExpect('keyword', 'then') ;~ TokenNext() TokenExpect('newline') $LINE += TokenPeek($VALUE) ListPush($LINE, $lnes) TokenNext() Local $StatementList[0] While Not TokenTest('keyword', '^(else(if)?|end)$', true) if TokenPeek($TYPE) = $EMPTY Then ScriptError('END expected!') ListPush(Statement(), $StatementList) wend ListPush($StatementList, $stms) Until Not TokenTest('keyword', 'elseif') ListPush($exps, $Statement) ListPush($lnes, $Statement) ListPush($stms, $Statement) Local $StatementList[0] If TokenTest('keyword', 'else') Then TokenNext() TokenExpect('newline') $LINE += TokenPeek($VALUE) ListPush($LINE, $Statement) TokenNext() While Not TokenTest('keyword', '^(else(if)?|end)$', true) if TokenPeek($TYPE) = $EMPTY Then ScriptError('END expected!') ListPush(Statement(), $StatementList) wend Else ListPush($empty, $Statement) EndIf ListPush($StatementList, $Statement) TokenNext() Case TokenTest('keyword', 'sub') ListPush(TokenPeek($VALUE), $Statement) TokenNext() TokenExpect('variable') ListPush(TokenPeek($VALUE), $Statement) TokenNext() TokenExpect('newline') $LINE += TokenPeek($VALUE) ListPush($LINE, $Statement) TokenNext() Local $StatementList[0] While Not TokenTest('keyword', 'end') If TokenPeek($TYPE) = $EMPTY Then ScriptError('END expected!') ListPush(Statement(), $StatementList) WEnd ListPush($StatementList, $Statement) TokenNext() Case TokenTest('keyword', '^(else(if)?)$', True) ScriptError('IF missing') Case TokenTest('keyword', 'end') ScriptError('SUB, IF or FOR missing') Case TokenTest('keyword', 'call') ListPush(TokenPeek($VALUE), $Statement) TokenNext() TokenExpect('variable') ListPush(TokenPeek($VALUE), $Statement) TokenNext() Case TokenTest('keyword', '^(write|message|wait)$', True) ListPush(TokenPeek($VALUE), $Statement) TokenNext() ListPush(EXPRESSION(), $Statement) Case TokenTest('keyword', 'for') ListPush(TokenPeek($VALUE), $Statement) TokenNext() TokenExpect('variable') ListPush(TokenPeek($VALUE), $Statement) TokenNext() TokenExpect('symbol', '=') TokenNext() ListPush(EXPRESSION(), $Statement) TokenExpect('keyword', 'to') TokenNext() ListPush(EXPRESSION(), $Statement) Local $StatementList[0] TokenExpect('newline') $LINE += TokenPeek($VALUE) ListPush($LINE, $Statement) TokenNext() While Not (TokenTest('keyword', 'end')) If TokenPeek($TYPE) = $EMPTY Then ScriptError('END expected!') ListPush(Statement(), $StatementList) WEnd ListPush($StatementList, $Statement) TokenNext() Case TokenPeek($TYPE) = 'variable' ListPush(TokenPeek($TYPE), $Statement) ListPush(TokenPeek($VALUE), $Statement) TokenNext() If TokenTest('symbol', '[') Then $Statement[$type] = 'list_set' TokenNext() ListPush(EXPRESSION(), $Statement) TokenExpect('symbol', ']') TokenNext() EndIf TokenExpect('symbol', '=') TokenNext() ListPush(EXPRESSION(), $Statement) Case Else ScriptError('Syntax error!') EndSelect If Not (TokenPeek($TYPE) = $EMPTY) Then TokenExpect('newline') Return $Statement EndFunc ;################################################################################################## Func DictionaryExists(ByRef $Dictionary, $key) For $count = 0 To UBound($Dictionary) - 1 If $Dictionary[$count][0] = $key Then Return $count Next Return -1 EndFunc Func DictionarySet(ByRef $Dictionary, $key, $item) Local $dictionaryexists = DictionaryExists($Dictionary, $key) If DictionaryExists($Dictionary, $key) > -1 Then $Dictionary[$dictionaryexists][1] = $item Else ReDim $Dictionary[UBound($Dictionary) + 1][2] $Dictionary[UBound($Dictionary) - 1][0] = $key $Dictionary[UBound($Dictionary) - 1][1] = $item EndIf EndFunc Func DictionaryGet(ByRef $Dictionary, $key) Local $dictionaryexists = DictionaryExists($Dictionary, $key) Return $Dictionary[$dictionaryexists][1] EndFunc Func TokenCopy() ; only type and value! Local $COPY[2] = [TokenPeek($TYPE), TokenPeek($VALUE)] Return $COPY EndFunc Func TokenMake($typ, $val) ; only type and value! Local $tok[2] = [$typ, $val] Return $tok EndFunc Func VarType($Check) Return Match($CodeNumber, $Check) ? 'number' : 'string' EndFunc Func MinMax($x, $min, $max) ;? If ($x < $min) Or ($x > $max) Then Return False Return True EndFunc ;################################################################################################## Func ExecuteTree($StatementList) For $Statement In $StatementList ExecuteStatement($Statement) Next EndFunc ;--------------------------------------------------------------------------------------- Func ExecuteStatement($Statement) Switch $Statement[0] Case 'newline' $LINE = $Statement[1] Case 'sub' ;sub, var, nl, $LINE = $Statement[2] DictionarySet($SUB, $Statement[1], $Statement[3]) Case 'call' ;call, var If DictionaryExists($SUB, $Statement[1]) = -1 Then ScriptError("sub " & $Statement[1] & " don't exist", True) Else ExecuteTree(DictionaryGet($SUB, $Statement[1])) EndIf Case 'if' ; If | [EXPn] | line | [STMTn] | 'line'| ; 0 | 1 | 2 | 3 | 4 | 5 For $i = 0 To UBound($Statement[1])-1 Local $bool = EVALUATE(($Statement[1])[$i]) If $bool[$VALUE] = 'true' Then $LINE = ($Statement[2])[$i] ExecuteTree(($Statement[3])[$i]) ExitLoop EndIf $LINE = $Statement[4] ExecuteTree($Statement[5]) Next Case 'for' ;for, varname, , , ;0 , 1 , 2 , 3 , 4 Local $sta = EVALUATE($Statement[2]) Local $sto = EVALUATE($Statement[3]) ;~ Local $opt = int($sta[$VALUE]) < int($sto[$VALUE]) ? 1 : -1 Local $opt = $sta[$VALUE] < $sto[$VALUE] ? 1 : -1 ;~ msgbox(16,0,$sta[$VALUE] & ',' &$sto[$VALUE] & ',' &$opt & ' = sta sto opt' ) If Not (Match($CodeNumber, $sta[$VALUE]) And Match($CodeNumber, $sto[$VALUE])) Then ScriptError('FOR needs numbers!', True) For $i = $sta[$VALUE] To $sto[$VALUE] Step $opt DictionarySet($VAR, $Statement[1], TokenMake('number', $i)) $LINE = $Statement[4] ExecuteTree($Statement[5]) $i = DictionaryGet($VAR, $Statement[1])[$VALUE] Next Case 'abort' WriteLog('script aborted at line: ' & $LINE) Abort() Case 'message' Local $message = EVALUATE($Statement[1]) MsgBox(270400, $TITLE, $message[$VALUE]) Case 'clear' ClearLog() Case 'click' WriteLog('clicking mouse') ;~ GUISetState(@SW_MINIMIZE, $Form) MouseClick('left') Case 'move' Local $x = EVALUATE($Statement[1]) If Not ($x[$TYPE] = 'number') Then ScriptError('MOVE X argument not a number!', True) Local $y = EVALUATE($Statement[2]) If Not ($y[$TYPE] = 'number') Then ScriptError('MOVE Y argument not a number!', True) WriteLog('moving mouse to: X = ' & $x[$VALUE] & ', Y = ' & $y[$VALUE]) MouseMove($x[$VALUE], $y[$VALUE]) Case 'send' WriteLog('Sending keystroke') Local $_ = EVALUATE($Statement[1]) Send($_[$VALUE]) Case 'wait' Local $_ = EVALUATE($Statement[1]) If Not $_[$TYPE] = 'number' Then ScriptError('WAIT argument must be a number!', True) If Not MinMax($_[$VALUE], 1, 10) Then ScriptError('WAIT argument must be between 1 and 10 seconds!', True) Sleep($_[$VALUE] * 1000) Case 'variable' Local $_ = EVALUATE($Statement[2]) DictionarySet($VAR, $Statement[1], $_) Case 'list_set' Local $i = EVALUATE($Statement[2])[$value];item to change Local $v = EVALUATE($Statement[3]);new value Local $list = DictionaryGet($VAR, $Statement[1])[$value];get the list $list[$i] = $v $list = TokenMake('list',$list) arraydisplay($list) DictionarySet($VAR, $Statement[1], $list);replace the list Case 'hide', 'show' Local $_ = $Statement[0] = 'hide' GUISetState($_ ? @SW_HIDE : @SW_SHOW) WriteLog($_ ? 'Hide log' : 'Show log') Case 'write' Local $_ = EVALUATE($Statement[1]) WriteLog($_[$VALUE]) EndSwitch EndFunc ;################################################################################################## Func EVALUATE($NESTED) ; evaluate expressions to new token by traversing 'nested' or else If $NESTED[0] = 'unary' Then Local $O = $NESTED[1] Local $R = EVALUATE($NESTED[2]) Switch $O[$VALUE] ; expressions in order Case '-' Return TokenMake('number', -$R[$VALUE]) Case 'not' Return TokenMake('string', $R[$VALUE] = 'True' ? 'False' : 'True') EndSwitch ElseIf $NESTED[0] = 'binary' Then Local $L = EVALUATE($NESTED[1]) Local $O = $NESTED[2] Local $R = EVALUATE($NESTED[3]) Switch $O[$VALUE] ; expressions in order Case 'or' Return TokenMake('string', ($L[$VALUE] = 'True') Or ($R[$VALUE] = 'True') ? 'True' : 'False') Case 'and' Return TokenMake('string', ($L[$VALUE] = 'True') And ($R[$VALUE] = 'True') ? 'True' : 'False') Case '<' Return TokenMake('string', $L[$VALUE] < $R[$VALUE] ? 'True' : 'False') Case '>' Return TokenMake('string', $L[$VALUE] > $R[$VALUE] ? 'True' : 'False') Case '=' Return TokenMake('string', $L[$VALUE] = $R[$VALUE] ? 'True' : 'False') Case '!' Return TokenMake('string', $L[$VALUE] = $R[$VALUE] ? 'False' : 'True') Case '&' Local $_ = $L[$VALUE] & $R[$VALUE] Return TokenMake(VarType($_), $_) Case '+' If Not (($L[$TYPE] = 'number') And ($R[$TYPE] = 'number')) Then ScriptError('+ needs 2 numbers!', True) Return TokenMake('number', Int($L[$VALUE] + $R[$VALUE])) Case '-' If Not (($L[$TYPE] = 'number') And ($R[$TYPE] = 'number')) Then ScriptError('- needs 2 numbers!', True) Return TokenMake('number', Int($L[$VALUE] - $R[$VALUE])) Case '*' If Not (($L[$TYPE] = 'number') And ($R[$TYPE] = 'number')) Then ScriptError('* needs 2 numbers!', True) Return TokenMake('number', Int($L[$VALUE] * $R[$VALUE])) Case '/' If Not (($L[$TYPE] = 'number') And ($R[$TYPE] = 'number')) Then ScriptError('/ needs 2 numbers!', True) Return TokenMake('number', Int($L[$VALUE] / $R[$VALUE])) EndSwitch Else Switch $NESTED[$TYPE] Case 'variable' ; returns stored variable or $EMPTY If DictionaryExists($VAR, $NESTED[$VALUE]) = -1 Then Return TokenMake('string', $EMPTY) Else Return DictionaryGet($VAR, $NESTED[$VALUE]) EndIf Case 'list_get' If DictionaryExists($VAR, $NESTED[$VALUE]) = -1 Then ScriptError('No such list!', True) Local $list = DictionaryGet($VAR, $NESTED[$VALUE]) Local $item = EVALUATE($NESTED[2]) If (UBound($list[$VALUE]) - 1) < $item[$VALUE] Then ScriptError('Integer to big for list size: ' & UBound($list), True) Return EVALUATE(($list[$VALUE])[$item[$VALUE]]) Case 'macro' Switch $NESTED[$VALUE] Case 'Input' Local $V = EVALUATE($NESTED[2]) Local $_ = InputBox($TITLE, $V[$VALUE], Default, Default, Default, Default, Default, Default, Default, $Form) Return TokenMake(VarType($_), $_) Case 'YesNo' Local $V = EVALUATE($NESTED[2]) Local $_ = MsgBox(270372, $TITLE, $V[$VALUE]) Return TokenMake('string', ($_ = 6) ? 'True' : 'False') Case 'True', 'False' Return TokenMake('string', ($NESTED[$VALUE] = 'true') ? 'True' : 'False') Case Else;random Return TokenMake('string', (Random(0, 1, 1) = 1) ? 'True' : 'False') EndSwitch Case Else ; give back value to this function Return $NESTED EndSwitch EndIf EndFunc ;################################################################################################## Func EXPRESSION() ; ...Or ... Local $E_Or = E_And() While TokenTest('keyword', 'Or') Local $_ = $E_Or Dim $E_Or[4] $E_Or[0] = 'binary' $E_Or[1] = $_ $E_Or[2] = TokenCopy() TokenNext() $E_Or[3] = E_And() WEnd Return $E_Or endfunc Func E_And() ; ... And ... Local $E_And = E_Not() While TokenTest('keyword', 'And') Local $_ = $E_And Dim $E_And[4] $E_And[0] = 'binary' $E_And[1] = $_ $E_And[2] = TokenCopy() TokenNext() $E_And[3] = E_Not() WEnd Return $E_And endfunc Func E_Not() ;unary not ... Local $E_Not If TokenTest('keyword', 'Not') Then Dim $E_Not[3] $E_Not[0] = 'unary' $E_Not[1] = TokenCopy() TokenNext() $E_Not[2] = E_Not() Else $E_Not = E_Com() EndIf Return $E_Not endfunc Func E_Com() ; ...=...? Local $E_Com = E_ADD() While TokenTest('symbol', '^(<|>|=|!)$', True) Local $_ = $E_Com Dim $E_Com[4] $E_Com[0] = 'binary' $E_Com[1] = $_ $E_Com[2] = TokenCopy() TokenNext() $E_Com[3] = E_ADD() WEnd Return $E_Com EndFunc Func E_ADD() ; ...&... Local $E_Add = E_P_M() While TokenTest('symbol', '&') Local $_ = $E_Add Dim $E_Add[4] $E_Add[0] = 'binary' $E_Add[1] = $_ $E_Add[2] = TokenCopy() TokenNext() $E_Add[3] = E_P_M() WEnd Return $E_Add EndFunc Func E_P_M() ; ...+... Local $E_P_M = E_M_D() While TokenTest('symbol', '^([+\-])$', True) Local $_ = $E_P_M Dim $E_P_M[4] $E_P_M[0] = 'binary' $E_P_M[1] = $_ $E_P_M[2] = TokenCopy() TokenNext() $E_P_M[3] = E_M_D() WEnd Return $E_P_M EndFunc Func E_M_D() ; ...*... Local $E_M_D = E_Neg() While TokenTest('symbol', '^([*/])$', True) Local $_ = $E_M_D Dim $E_M_D[4] $E_M_D[0] = 'binary' $E_M_D[1] = $_ $E_M_D[2] = TokenCopy() TokenNext() $E_M_D[3] = E_Neg() WEnd Return $E_M_D EndFunc Func E_Neg() ;unary -, ---... Local $E_NEG If TokenTest('symbol', '-') Then Dim $E_NEG[3] $E_NEG[0] = 'unary' $E_NEG[1] = TokenCopy() TokenNext() $E_NEG[2] = E_Neg() Else $E_NEG = E_Val() EndIf Return $E_NEG EndFunc ;-------------------------------------------------------------------------------------------------- Func E_Val() ; add in values to the build tree Select Case Match('^(number|string)$', TokenPeek($TYPE)) Local $E_Val = TokenCopy() TokenNext() Case TokenPeek($TYPE) = 'macro' Local $E_Val = TokenCopy() If TokenTest('macro', '^(Input|YesNo)$', True) Then TokenNext() ListPush(EXPRESSION(), $E_Val) Else TokenNext() EndIf Case TokenPeek($TYPE) = 'variable' Local $E_Val = TokenCopy() TokenNext() If TokenTest('symbol', '[') Then $E_Val[$TYPE] = 'list_get' TokenNext() ListPush(EXPRESSION(), $E_Val) TokenExpect('symbol', ']') TokenNext() EndIf Case TokenTest('symbol', '[') TokenNext() Local $LIST[0] While Not TokenTest('symbol', ']') ListPush(EXPRESSION(), $LIST) If TokenTest('symbol', ',') Then TokenNext() ElseIf TokenTest('symbol', ']') Then ;exit loop Else TokenExpect('symbol', ',') EndIf wend TokenNext() Local $E_Val = TokenMake('list', $LIST) Case TokenTest('symbol', ']') TokenExpect('symbol', '[') Case TokenTest('symbol', '(') TokenNext() Local $E_Val = EXPRESSION() TokenExpect('symbol', ')') TokenNext() Case TokenTest('symbol', ')') TokenExpect('symbol', '(') Case Else ScriptError('Value error!', False) EndSelect Return $E_Val EndFunc ;################################################################################################## Func ConsoleError($Content, $Bad = False) ColorLog(0xFF0000) WriteLog('An error occured!') MsgBox($Bad ? $CRITICAL : $EXCLAMATION, $TITLE, $Content) Abort() EndFunc WriteLog('Checking arguments') Switch $cmdline[0] Case 0 WriteLog('0 arguments') ConsoleError('No arguments') Case 1 WriteLog('Checking filepath') If FileExists($cmdline[1]) = False Then ConsoleError('No such file: ' & $cmdline[1], True) EndIf Case Else WriteLog($cmdline[0] & ' arguments') ConsoleError('You can only open 1 file at a time') EndSwitch WriteLog('Arguments ok') ColorLog(0x00FF00) ;--------------------------------------------------------------------------------------- Tokenize() ;fill up $tokens If TokenCount() > 0 Then BuildTree() ;build AST $Tokens = 0 ; clear tokens, not needed anymore $LINE = 1 arraydisplay($PROGRAM) ExecuteTree($PROGRAM) EndIf ;--------------------------------------------------------------------------------------- WriteLog('Script executed successfully!') While True ;weg doen? Switch GUIGetMsg() Case $gui_event_close, $Close Abort() Case $Minimize GUISetState(@SW_MINIMIZE, $Form) EndSwitch WEnd