Jump to content

Creating a simple script-engine with autoit.


GeekIT
 Share

Recommended Posts

Hello readers of this post  :)

I'm planning to make a sort of script engine via autoit.

It will read text files as 'scripts' with my self made scripting language.

(but i'm going to make my own extension for the 'scripts')

i'm thinking about " nameOfFile.GeekScript " or something...

how it works:

files with the extension ".geekscript" will be opened with my "script-engine.exe" made in autoit.

-script-engine.exe reads the script and breaks it apart in sentences by @CRLF.

-every sentence will be spitted up to 'words' (or commands) that will be recognized by my script-engine.

-the engine recognizes if you want to make a variable when it reads a word followed by '=' and after that a string or number (or calculations).

and here i'm stuck, if the script engine reads this for example:

-----------------------------------------------------------------------------

ABC = 456

DEF = "this is a test" & ABC + 123

-----------------------------------------------------------------------------

for the variable "DEF", it must calculate the result for that variable and store that in a dictionary object or something.
i tough of using autoit's "execute" or "eval" function to see what the output would be but unfortunately if by coincidence the
variable exists in the 'script-engine source code' eval or execute will use that variable...
 

this is what i mean:

-----------------------------------------------------------------------------

Func = 456

-----------------------------------------------------------------------------

if i use eval or execute for this string: eval("func = 456") then it would give an error or it won't work.

same for variables that exist in the 'script-engine autoit code'...

does anybody know if there is a way for calculating strings like eval does, but don't use the variables made in the autoit script?

 

Link to comment
Share on other sites

Requires you to have the 'Func' declared, unfortunatly:

Local $Func
$string = "Func = 456"
$aString = StringRegExp($string,"(.*)\s=\s(.*)",3)
$VarName = $aString[0]
$VarValue = $aString[1]
Assign($VarName,$VarValue)
ConsoleWrite("VariableName=[" & $VarName & "], Value=[" & Eval($VarName) & "] or, using your 'variable'=[" & $Func & "]" & @CRLF )

output: VariableName=[Func], Value=[456] or, using your 'variable'=[456]

edit: no need to move the array into $VarName...helpfile states the first param of assign can't be an array, but am able to do so...must mean it can't be an empty array element?:

Local $Func
$string = "Func = 456"
$aString = StringRegExp($string,"(.*)\s=\s(.*)",3)
Assign($aString[0],$aString[1])
ConsoleWrite("using your 'variable'=[" & $Func & "]" & @CRLF )

output: using your 'variable'=[456]

Edited by jdelaney
IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.
Link to comment
Share on other sites

Requires you to have the 'Func' declared, unfortunatly:

Local $Func
$string = "Func = 456"
$aString = StringRegExp($string,"(.*)\s=\s(.*)",3)
$VarName = $aString[0]
$VarValue = $aString[1]
Assign($VarName,$VarValue)
ConsoleWrite("VariableName=[" & $VarName & "], Value=[" & Eval($VarName) & "] or, using your 'variable'=[" & $Func & "]" & @CRLF )

output: VariableName=[Func], Value=[456] or, using your 'variable'=[456]

edit: no need to move the array into $VarName...helpfile states the first param of assign can't be an array, but am able to do so...must mean it can't be an empty array element?:

Local $Func
$string = "Func = 456"
$aString = StringRegExp($string,"(.*)\s=\s(.*)",3)
Assign($aString[0],$aString[1])
ConsoleWrite("using your 'variable'=[" & $Func & "]" & @CRLF )

output: using your 'variable'=[456]

 

thank you for the reply!

i see you are using stringregexp, can you explain me what you are doing with that?

also, wouldn't it be more useful to store the name in a dictionary object or has stringregexp something to do with that?

to "calculate" the string i was thinking about first replacing all the possible declared variables in my "geek script" with there outputs

but the problem then is that a variable can be declared in a very complicated way:

myVar = 1 + -5 * 8 / 7 - 5 & "test" + -1 - -10 & "help!!!"

Link to comment
Share on other sites

I am trying to do something very similar in one of my scripts,

I like how jdelaney went about it but for what I am doing I cannot declare the variables before.

I came up with this real quick and it works for what you are trying to do,

there are a couple ways you could improve it because right now it will confuse similar variable names ex. ABC and ABCD

I can think of a couple ways of fixing this but i think you can figure it out ;)

#include <Array.au3>

Dim $TestScript = 'ABC = 456' & @CRLF & _
                  'DEF = "this is a test" & ABC + 123' & @CRLF & _
                  'myVar =  1 + -5 * 8 / 7 - 5  & "test" &  -1 - -10  & "help!!!"' & @CRLF & _
                  'Func = 456' & @CRLF

ProcessScript($TestScript)

Func ProcessScript($hScript)
    Local $hSplit = StringSplit($hScript, @CRLF, 1)
    Local $Variables[1] = [0], $Data[1] = [0]
    For $i = 1 to $hSplit[0] Step 1
        Local $aString
        $aString = StringRegExp($hSplit[$i],"(.*)\s=\s(.*)",3)
        If IsArray($aString) Then
            _ArrayAdd($Variables, $aString[0])
            _ArrayAdd($Data, $aString[1])
            $Variables[0] += 1
            $Data[0] += 1
        EndIf
    Next
    For $i = 1 to $Variables[0] Step 1
        ConsoleWrite("+ Variable["&$i&"] = "&$Variables[$i]&@CRLF)
        ConsoleWrite("> Data["&$i&"]     = "&$Data[$i]&@CRLF)
    Next
    For $i = 1 to $Data[0] Step 1
        Local $ProcessData = $Data[$i]
        For $c = 1 to $Variables[0] Step 1
            If StringinStr($Data[$i], $Variables[$c]) Then
                $ProcessData = StringReplace($Data[$i], $Variables[$c], $Data[$c])
            EndIf
        Next
        ConsoleWrite("- Processed Data["&$i&"]     = "&Execute($ProcessData)&@CRLF)
    Next
EndFunc
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...