Jump to content
TheAutomator

Writing a recursive decent parser in Autoit

Recommended Posts

I'm writing a recursive decent parser in Autoit!

The programming language i'm making is called HighLevel.
I'm doing this for learning purposes, because it's fun and because I can implement it into my other project:
Fullscreen Console With custom programming language!

 

It's not easy...

In Autoit you don't have objects like in Java or Visual Basic, so I had to figure out a way to still convert the code to an abstract syntax tree.
I used nested array's and array based dictionary's instead of objects.
The code is still very dirty and I need to make a lot of modifications but if you're careful with testing you'll see what it can do already.

 

Console window

Because this code eventually will get implemented into my console project I crafted a nice little console window (with a custom sci-fi looking theme, yeah i was a little bored haha).
{ESC} is your panic button for now, it terminates the script completely.
If you get an error while opening a script the text will turn red.
To minimize it press the blue button, to close it use the red one, to drag the gui just grab it on one of the sides.
The console window will display what you write to it with your "HighLevel-script" and some additional information:

Naamloos.jpg.508e637083c0c28635582309830e8d7c.jpg

 

How to test it:

Download: HighLevel.Au3, Debug.Au3 (includes a function to display nested arrays for debugging), GUI.bmp (for the console)
Compile the Autoit code to EXE.
The GUI.bmp must be in the same folder as the EXE file!
Write a
HighLevel-script (text file) and drag it into the compiled autoit-exe.
The custom made little console window will pop up in the left top corner of your screen and your
HighLevel-script (the text file) will be interpreted and executed.

 

The Language:

exit script:

    Abort
    
show / hide the console:

    Show
    Hide
    
write to/clear the console:

    Write 'this is a ''string''!'
    Clear
    
variables:
    test_var_1 = 123
    some_list = ['a', 5, true]
    some_list[1] = 3
    math = 1 + 2 * 3 / 4 - -5 & test_var

beep (under construction):

    Beep F, optD

wait X seconds:
    Wait X
    
Messages:

    Message 'Hello World!'
    
move/click the mouse:

    Move X, Y
    Click
    
send keys (under construction):

    Send 'HighLevel', True
    
if's:

    If false
    ElseIf true
        # this part will run
    Else
    End

subs:

    Sub X
        # do stuff
    End

    Call X
    
for loops:

    For X = 1 to 10
        # X iterates
    End

Values:

    Input 'Give me input'
    Random
    YesNo 'yes or no'

operators:

    + - * / & > = ! < ( ) And Not Or

 

Example script:

# my first HighLevel script

message 'Hello World!'
message 'Lets write to the console...'

clear # clear the console...

list = ['a', 16, true]
for i = 0 to 2
    write list[i]
    wait 1
end

sub test
    if YesNo 'would you like to quit?'
        message 'Goodbye!'
        abort
    else
        write 1 + 2 * 3 & ' math!'
    end
end

call test

 

test script.HighLevel

GUI.bmp

Debug.au3

HighLevel.au3

Edited by TheAutomator

Share this post


Link to post
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

  • Similar Content

    • By jantograaf
      Hi all, 
      I'm trying to make a listing of all files in subdirectories on a specific level in a folder structure. Let me explain, visually, this will help things a lot.

      I have a folder structure like this:
       
      ROOT |--- SUBDIR 1 | |---- SUBDIR 1.1 | |----- SUBDIR 1.1.1 | |---- File1.ext | |----- SUBDIR 1.1.2 | |---- File2.ext | |----- SUBDIR 1.1.3 | |---- File2.ext | |----- SUBDIR 1.1.4 | |---- File2.ext | |----- SUBDIR 1.1.5 | |---- File2.ext | |---- SUBDIR 1.2 | |----- SUBDIR 1.2.1 | ..... | |---- SUBDIR 1.3 .... I use _FileListToArrayRec twice:
      - once to make an array of the specific directories I should be working at: I need all files on the x.x level, so it will go just until that depth using a negative integer for $iRecur
      - once again to create an array of all files found under that directory and its subdirectories (level x.x.x\files...)
      What happens now is that _FileListToArrayRec will always include all levels before the maximum depth is reached. The result would look like this
      Row 0 15 Row 1 Root\Subdir 1 Row 2 Root\Subdir 2 Row 3 Root\Subdir 3 Row 4 Root\Subdir 1\Subdir 1.1 Row 5 Root\Subdir 1\Subdir 1.2 Row 6 Root\Subdir 1\Subdir 1.3 ... Needless to say that when my second function iterates over this array, it will find all files twice. Once on the x level, once again on the x.x level. There is no way for me not to use the recursive option in the second iteration, since the files are actually in a subdirectory there.

      Where are the wizards of programming logic here? Since I can't seem to find a comprehensible or easily implementable solution for this issue.

      Thanks in advance and kind regards,

      Jan
    • By FrancescoDiMuro
      Good morning
      I was looking around the forum if there were some customizable solutions about creating a PDF from "0" to something like a report...
      What I'd like to do is something with a header ( 2 logos and a title ), with a table which contains data read from a file
      At the moment, I was working with HTML, since I know it and it's very simple to do a table with some data inside...
      But know, I'm a bit stuck about the exporting the HTML page to PDF... And, here too, if someone knows how to do it, please, I'm here listening
      Thanks guys
       
    • By Fade91
      Hello, first time poster here
      I am working on a project that has to parse a log file in real time. The thing is I know it's hard for Autoit to attach itself to log files when they're already in use by other programs, at least in my experience.
      I was taking a look at this thread because the log file is quite large and I think Autoit might be a little slow on it's own.

      The thing is I don't know how to use this properly to extract all data out of a log file or is there a native way to do this using Autoit.
      Basically , I just need a log parser that is able to read from a log that is 'already opened' and 'being written to'
       
      Thanks!
    • By TheAutomator
      Hi everyone
      Are there any people here that know how to use a parser generator that uses 'bnf' (not 'ebnf'!)
      i'm using the gold parser:
      http://goldparser.org/index.htm
      not possible in autoit:
      https://www.autoitscript.com/forum/topic/167663-activex-gold-parser-in-autoit-is-this-possible/
      What i'm looking for is the best way to parse a list:
      <List> ::= <Item> ',' <List> | <Item> <Item> ::= Number | String for example, the tree returned from:
      'test', 1, 2 is:

      since its not possible in AutoIT code I did it in vb script.
      this is what i did:
      ' in the parse loop: Case Rule_List_Comma set result = new list call result.input(.tokens(0).data,.tokens(2).data) ' the list class: class list private arg0 private arg1 public sub input(a,b) set arg0 = a set arg1 = b end sub private sub push(item,byref stack) redim preserve stack(ubound(stack) + 1) stack(ubound(stack)) = item end sub public function value value = array(arg0.value) value2 = arg1.value if isarray(value2) then for each thing in value2 push thing,value next else push value2,value end if end function end class  
      is there a better way to do this?
       
      regards,
      TheAutomator
    • By TheAutomator
      hi everyone
      i have an interesting question about the gold parser:
      info:
      http://www.goldparser.org/index.htm
      download (regsvr32 to register):
      http://www.goldparser.org/engine/1/vb6/index.htm
      on the website it seems that this dll can be used as an activex object,
      does that mean that it can be used in autoit to?
      help for the activeX dll:
      http://www.goldparser.org/engine/1/vb6/doc/index.htm
      it gives me error code '4' if i try to use it... 
      Const $gpMsgAccept = 3 Const $gpMsgCommentBlockRead = 9 Const $gpMsgCommentError = 7 Const $gpMsgCommentLineRead = 10 Const $gpMsgInternalError = 8 Const $gpMsgLexicalError = 5 Const $gpMsgNotLoadedError = 4 Const $gpMsgReduction = 2 Const $gpMsgSyntaxError = 6 Const $gpMsgTokenRead = 1 $Parser = ObjCreate("goldparserengine.goldparser") $Parser.LoadCompiledGrammar("test_script.cgt") $Parser.OpenFile("Program.txt") $Response = $Parser.Parse() MsgBox(0,'test',$Response) If there are people interested in answering or helping feel free to reply and then i will upload the "test_script.cgt" somewhere if you want
      i know this question is a bit specific but you never know.. 
      Thanks for reading!
      TheAutomator.
×
×
  • Create New...