Jump to content

AutoItify-C PRE_Alpha no RC


Padol
 Share

Recommended Posts

#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>




$stri=0

Dim $ParseVar[0][2]
func addParser($Pattern,$output)
        $lastIndex=UBound($ParseVar)
    ReDim $ParseVar[$lastIndex+1][2]
    $ParseVar[$lastIndex][0]=$Pattern
    $ParseVar[$lastIndex][1]=$output
EndFunc
$Pattern='for\s*[$](\w+)(\s+|\s?)(=)(\s+|\s?)(\d+)\s*to\s*(\d+)\s*step\s*(\d+)' ;for $i = 0 to 123 step 1
$output ='for (int $1 $3 $5; $1 < $6; $1 += $7) {'
addParser($Pattern,$output)

$Pattern='if\s+[$](\w+)\s+=\s+(\d+)\s+then' ; if $i = 0 then
$output ='if ( $1 == $2 ){'
addParser($Pattern,$output)

$pattern='[$](\w+)\s*=\s*(\d+[.]\d+)([\S+ ]*)' ; $i = 0.5
$output='float $1 = $2$3;'&@CRLF
addParser($Pattern,$output)
$pattern='[$](\w+)\s*=\s*(\d+)([\S+ ]*)'  ; $i = 123
$output='int $1 = $2$3;'&@CRLF
addParser($Pattern,$output)
$pattern='[$](\w+)\s*=\s*(("|'&"'"&')([\w+\s+\W+])+("|'&"'"&'))'  ;  $i = "Occhio lol"
$output='char $1[] = $2;'&@CRLF
addParser($Pattern,$output)
$pattern='(next|endif)'  ;  $i = "Occhio lol"
$output='};'
addParser($Pattern,$output)
$pattern='[$]([\w+_]*\s*=[\S+ ]+)'
$output='$1;'
addParser($Pattern,$output)
$pattern='[$]([\w+_]*)' ;$varname
$output='$1'
addParser($Pattern,$output)







#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 802, 400, 192, 124)
$Edit1 = GUICtrlCreateEdit("", 8, 8, 385, 185)
GUICtrlSetData(-1, "Edit1")
$Edit2 = GUICtrlCreateEdit("", 400, 8, 385, 185)
GUICtrlSetData(-1, "Edit2")
$list1 = GUICtrlCreateList("nhgbfdvds",1,200, 800,200)


GUISetState(@SW_SHOW)


GUIRegisterMsg($WM_COMMAND, "My_WM_COMMAND")
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

    EndSwitch
    WinSetTitle($Form1,"",$nMsg)
WEnd

for $i=0 to 123

Next


func varDeclared($str)

    $st=StringRegExpReplace($str,$ParseVar[UBound($ParseVar)-1][0],$ParseVar[UBound($ParseVar)-1][1])
    if not @error Then
        GUICtrlSetData($list1,$st&"|")
    EndIf

EndFunc


func varParse($str)
    GUICtrlSetData($list1,"")
    varDeclared($str)
    local $stri=$str

    for $i = 0 to ubound($ParseVar,1)-1
    $stri = StringRegExpReplace($stri,$ParseVar[$i][0],$ParseVar[$i][1])
    Next
    $stre = 'int main (void) {'&@crlf&@crlf
    $stru=@crlf &'return 0;'&@crlf&'}'
    Return $stre&$stri&$stru
EndFunc











func parse($string)
    $stri=StringReplace($string,"func","Function")
    $expForInt='for\s*[$](\w+)(\s+|\s?)(=)(\s+|\s?)(\d+)\s*to\s*(\d+)\s*step\s*(\d+)'; for $i = 0 to 123 step 1
    $exp1='[$](\w+)(\s+|\s?)(=)(\s+|\s?)(\d+[.]\d+)' ;$i = 0.54
    $expIfVarEqInt='if\s+[$](\w+)\s+=\s+(\d+)\s+then' ; if $i = 0 then

    $expIfNotVarEqInt='if\s+not\s+[$](\w+)\s+=\s+(\d+)\s+then' ; if not $i = 0 then

    $expIfVarOpInt='if\s+[$](\w+)\s+(<|>|>=|<=)\s+(\d+)\s+then' ;if $i <= 0 then

    $stri=StringRegExpReplace($string,$expIfVarEqInt,'if ( $1 == $2 ){')
    $stri=StringRegExpReplace($stri,$expIfVarOpInt,'if ( $1 $2 $3 ){')
    $stri=StringRegExpReplace($stri,$expIfNotVarEqInt,'if ( $1 != $2 ){')
    $stri=StringRegExpReplace($stri,$expForInt,'for (int $1 $3 $5; $1 < $6; $1 += $7) {')
    $stri=StringRegExpReplace($stri,$exp1,'float $1 $3 $5;')
    $stri=StringRegExpReplace($stri,'[$](\w+)(\s+|\s?)(=)(\s+|\s?)(\d+)','int $1 $3 $5;')
    $stri=StringReplace($stri,'next','};');Forloopend
    $stri=StringReplace($stri,'endif','};');Endif
    return $stri


EndFunc

Func My_WM_COMMAND($hWnd, $imsg, $iwParam, $ilParam)
    Local $setHK = False
    $nNotifyCode = BitShift($iwParam, 16)
    $nID = BitAND($iwParam, 0x0000FFFF)
    $hCtrl = $ilParam

    If $nNotifyCode = $EN_CHANGE Then
        If $hCtrl = GUICtrlGetHandle($edit1) Then
            If GUICtrlRead($edit1) <> "" Then
                GUICtrlSetData($edit2, varParse(GUICtrlRead($edit1)))

            EndIf

        EndIf

    EndIf

    Return $GUI_RUNDEFMSG


EndFunc  ;==>My_WM_COMMAND

this is a really bad scratch but essentially it turn actually basic autoit code to c syntax

i really want to improve that

remember that c "mustdeclarevar" :*

working example:

$io = 0                             --> int io = 0;

$string="Hola"              ---> char string[]= "Hola";

$flo = 0.5                        --> float flo = 0.5;

if $i = 10 then                --> if ( i == 10 ){

endif or Next                 --> };

for $i = 0 to 100 step 1 --> for (int i = 0; i < 100; i += 1) {

 

 

Link to comment
Share on other sites

Im' afraid you need to start at a higher level. Start with an AutoIt grammar parser, else you'll get stuck pretty soon.

Note that AutoIt strings are UCS2-encoded (Unicode restricted to plane 0). Also AutoIt variables are not fixed type:

Local $a = 3 & ".1415926"
ConsoleWrite(-$a + '3' & @TAB & $a ^ 2 & @LF)
; also
_CubeMe($a)
ConsoleWrite($a & @LF)

Func _CubeMe(ByRef $n)
    $n = $n ^ 3
EndFunc

; also
Local $aTricky[Random(2, 5, 1][Floor($a)]

... and more pitfalls.

Then you'll have to rewrite all internal functions and deal with non-native C datatypes and much more.

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 here
RegExp tutorial: enough to get started
PCRE 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

It's very hard to convert AutoIt to C, an "AutoIt Compiler" which compiles AutoIt code into C code is more appropriate in this situation ;).

I also see that you are using Regex in the parse function... Take my advice, DO NOT USE REGEX to parse ANYTHING. You are better off parsing everything manually rather than using Regex to capturing the needed parts. It will be far easier to understand and modify in the future than using Regex :).

EasyCodeIt - A cross-platform AutoIt implementation - Fund the development! (GitHub will double your donations for a limited time)

DcodingTheWeb Forum - Follow for updates and Join for discussion

Link to comment
Share on other sites

52 minutes ago, TheDcoder said:

It's very hard to convert AutoIt to C, an "AutoIt Compiler" which compiles AutoIt code into C code is more appropriate in this situation ;).

I also see that you are using Regex in the parse function... Take my advice, DO NOT USE REGEX to parse ANYTHING. You are better off parsing everything manually rather than using Regex to capturing the needed parts. It will be far easier to understand and modify in the future than using Regex :).

Uhm... what??

You have over 2.2k posts here, someone could actually take your advices seriously.

♡♡♡

.

eMyvnE

Link to comment
Share on other sites

57 minutes ago, TheDcoder said:

Take my advice, DO NOT USE REGEX to parse ANYTHING. You are better off parsing everything manually rather than using Regex to capturing the needed parts. It will be far easier to understand and modify in the future than using Regex :).

You must have a very strong argument to back such a statement and it seems I aint alone to be impatient to read it in full.

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 here
RegExp tutorial: enough to get started
PCRE 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

1 hour ago, TheDcoder said:

It's very hard to convert AutoIt to C, an "AutoIt Compiler" which compiles AutoIt code into C code is more appropriate in this situation ;).

This part leaves me completely speechless.

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 here
RegExp tutorial: enough to get started
PCRE 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

On 31/10/2016 at 1:10 AM, jchd said:

Im' afraid you need to start at a higher level. Start with an AutoIt grammar parser, else you'll get stuck pretty soon.

Note that AutoIt strings are UCS2-encoded (Unicode restricted to plane 0). Also AutoIt variables are not fixed type:

Local $a = 3 & ".1415926"
ConsoleWrite(-$a + '3' & @TAB & $a ^ 2 & @LF)
; also
_CubeMe($a)
ConsoleWrite($a & @LF)

Func _CubeMe(ByRef $n)
    $n = $n ^ 3
EndFunc

; also
Local $aTricky[Random(2, 5, 1][Floor($a)]

... and more pitfalls.

Then you'll have to rewrite all internal functions and deal with non-native C datatypes and much more.

yeah that is some of the problem point you was helpfull

i'm working on variable rappresentation i don't know which are the best metod i can make an union type called variant that include int32 float and char

i also see that utf-8 wich is the c standard is pretty equal to ucs2 u mentioning 65 is still A like in utf-8 that i was thinking as default au3 char rappresentation

you are right with autoit var type conversion

but you can't do $i = "A" + 2 this never give you "C"

actually in au3 you treat it as

$i = chr(   int( stringtobinary("A") ) + 2)

autoit literally append number like if it was a string so $i = 10 & "12.123"  ==   $i = 1012.123

and why i cannot do that? i will convert with itoa -> strcat and if needed back with atoi

yeah of course in the example i use a float so dosent work for real

i can also do it matematically with

unsigned concatenate(unsigned x, unsigned y) {
    unsigned pow = 10;
    while(y >= pow)
        pow *= 10;
    return x * pow + y;        
}

this will concatenate 2 given integer

if you have some other helpfull argument i'm ready to appriciate him.

 

Link to comment
Share on other sites

Points raised in same sequence.

You'll need a variant datatype compatible with AutoIt own variant implementation, including Keyword, Function, UserFunction, Map (beta), Hwnd, Bool, Int32, Int64, Array, Binary, Ptr, Object, String, Double, DllStruct, at least as per current beta version.

UTF8 is fundamentally different from UCS2. Google them to see why.

"A" + 2 this never give you "C" since AutoIt + operators forces conversion to numeric datatypes. Number("A") gives 0, so "A" + 2 evaluates to 2.

Quote

actually in au3 you treat it as

$i = chr(   int( stringtobinary("A") ) + 2)

Not at all, see above. Try to work out by yourself the result of the following code:

ConsoleWrite(("z" + 16) & @LF)
ConsoleWrite(("€" + 10) & @LF)
ConsoleWrite(("AutoIt" + 10) & @LF)
ConsoleWrite(Chr(Int(StringToBinary("z")) + 16) & @LF)
ConsoleWrite(Chr(Int(StringToBinary("€")) + 10) & @LF)
ConsoleWrite(Chr(Int(StringToBinary("AutoIt")) + 10) & @LF)

You're still seem to think that one character = one byte, but this is untrue.

Again, in $i = 10 & "12.123" the & operator forces conversion of its arguments to strings, hence it means $i = "10" & "12.123" yielding $i = "1012.123" as a string.

Be warned that if you mess with floats (actually doubles) as you intend, you'll hit approximation errors.

 

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 here
RegExp tutorial: enough to get started
PCRE 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

Quote

You're still seem to think that one character = one byte, but this is untrue.

eeehck?!? {"e","e","e","h","c","k","?","!","?","/0"} realy?? i think my whole pc work with that shit but not autoit? some time i subspected that you know... xD

 

what i can ackieve is a string actually? the resulting of $i = "1012.123" is a string until i don't use the + operator? and is treathed at it is? 

Quote

Again, in $i = 10 & "12.123" the & operator forces conversion of its arguments to strings, hence it means $i = "10" & "12.123" yielding $i = "1012.123" as a string.

every time autoit use a variable  check if is string then force conversion when needed? so variable type in autoit are a class that auto recognize itself? can't i achieve it with c union maybe a struct? i don't want to remake the interpreter so i realy dosn't want to recognize all of that data, maybe i colda add som form of forcing convention without the needem of aving it actually on c code

Link to comment
Share on other sites

Unicode (using UTF16-LE for your OS, but only UCS2 for AutoIt). How else would you obtain this?

Local $String = "Sample english text 한국어 텍스트의 예 טקסט עברית ירושלים русский образец អត្ថបទថៃ"
Local $res = StringRegExp($String, "(*UCP)\b(\p{Hangul}[\p{Hangul}\s]*)\b", 1)
If not @error Then MsgBox(64, "Korean text found", $res[0])
$res = StringRegExp($String, "(*UCP)\b(\p{Khmer}[\p{Khmer}\s]*)\b", 1)
If not @error Then MsgBox(64, "Thaï text found", $res[0])
$res = StringRegExp($String, "(*UCP)\b(\p{Latin}[\p{Latin}\s]*)\b", 1)
If not @error Then MsgBox(64, "Latin text found", $res[0])
$res = StringRegExp($String, "(*UCP)\b(\p{Hebrew}[\p{Hebrew}\s]*)\b", 1)
If not @error Then MsgBox(64, "Hebrew text found", $res[0])
$res = StringRegExp($String, "(*UCP)\b(\p{Cyrillic}[\p{Cyrillic}\s]*)\b", 1)
If not @error Then MsgBox(64, "Cyrillic text found", $res[0])

Yes, operator can and do force necessary conversions, but only when needed.

Maybe you don't want to rewrite an AutoIt interpretor, but you're embarking on a boat which will sail very close to that. If it isn't complete it will be mostly useless.

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 here
RegExp tutorial: enough to get started
PCRE 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

14 minutes ago, TheDcoder said:

USC-2 always uses 2 bytes to store 1 character :)

i always use int with c for char type and the same int correspond with chr(int) the ascii standard implies the use of latin alphabet plus digits stored in one bytes so i don't think there is realy that difference from 0 to 255 and if you add other to  65'535 is still an integer

Link to comment
Share on other sites

"Latin alphabet" doesn't mean anything when applied to a string. You need to specify which codepage you're using to give a meaning to an extended ASCII string. That led to untractable issues due to non-interoperability and the answer was Unicode, some 20 [correction] 25 years ago.

A char in C isn't an int.

Edited by jchd

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 here
RegExp tutorial: enough to get started
PCRE 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

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...