[ANN] MIDLE - Almost an Alternative to EXECUTE [message #89095] |
Thu, 24 July 2014 00:00  |
SonicKenking
Messages: 51 Registered: October 2010
|
Member |
|
|
Mini IDL Evaluator (MIDLE) evaluates simple IDL statements and most expressions without EXECUTE, i.e. virtual machine safe. It can be an alternative to EXECUTE in many cases.
GitHub repo:
https://github.com/ywangd/midle
It is currently at version 0.1.0 and can be also be downloaded at https://github.com/ywangd/midle/archive/v0.1.0.zip
MIDLE implements its own parser and evaluates simple IDL statements and expressions without resorting to the power of `EXECUTE`. It even adds additional language features such as syntax for HASH and LIST literals, higher level array concatenation, bettering support for chaining function/method calls and subscripts.
MIDLE is however not without limitations. Some limitations are due to the limit of IDL language itself, notably output arguments and object property access (object method calls are OK). Others are deliberately set by design to meet the scope of MIDLE, notably program control constructs. Please refer to the GitHub page for details.
MIDLE requires IDL 8.0 or up (8.3 is recommended).
Here are a few examples using MIDLE (full documentation can be found at the GitHub repo page).
------------------------------------------------------------ --------
; Mandatory classic example
print, midle('"Hello, World!"')
midle, 'print, "Hello, World!"'
; Array of strings
midle, ['print, "STAR"', 'print, "WARS"']
; Or write them in one line
midle, 'print, "STAR" & print, "WARS"'
; Evaluate the content of given file
midle, 'filename', /file
; Passing variables
env = {num: 50}
print, midle('indgen(2,3,4, start=num)', env)
; Procedure call
midle, 'plot, indgen(50, start=100), /ynozero'
; Expressions
print, midle('-2.2 - 2 mod ((42. + 22) ^ 2 > 3 - 4.2) * 2.2 / 2.4')
print, midle('x eq 42 ? indgen(5, start=x) : indgen(5)', {x: 42})
; Assignment
print, midle('x = 42', env)
print, env.x ; output 42
print, midle('h = Hash()', env)
print, midle('h["a"] = indgen(3,4,5)', env)
print, midle('h["a", 0, 1, 2] = 420', env)
print, (env.a)[0,1,2] ; output 420
; List literal
print, midle('("a", "list", "literal")')
; Hash literal
print, midle('h{"x": 42, "y": 22, "description": "This is a hash literal"}')
; Higher level array concatenation:
env = {a: indgen(6,5,4,3,2), b: indgen(6,5,4,3,2, start=720)}
help, midle('[ [[[[a]]]], [[[[b]]]] ]', env) ; concatenate on the 5th dimension
; Better support for chained function/method calls and subscripts
print, midle('list(indgen(3,4,5,6)[*,0:3:2,4,*][2,*,0,0:5:2], /extract).count()')
------------------------------------------------------------ --------
Comments and suggestions are welcome.
I'd like to thank Mike Galloy for his wonderful mgunit and idldoc, which I used extensively for developing MIDLE.
Cheers,
Yang
|
|
|
|
|
Re: [ANN] MIDLE - Almost an Alternative to EXECUTE [message #89143 is a reply to message #89095] |
Sun, 27 July 2014 21:14   |
SonicKenking
Messages: 51 Registered: October 2010
|
Member |
|
|
On Thursday, July 24, 2014 5:00:39 PM UTC+10, SonicKenking wrote:
> Mini IDL Evaluator (MIDLE) evaluates simple IDL statements and most expressions without EXECUTE, i.e. virtual machine safe. It can be an alternative to EXECUTE in many cases.
>
>
>
> GitHub repo:
>
> https://github.com/ywangd/midle
>
>
>
> It is currently at version 0.1.0 and can be also be downloaded at https://github.com/ywangd/midle/archive/v0.1.0.zip
>
>
>
>
>
> MIDLE implements its own parser and evaluates simple IDL statements and expressions without resorting to the power of `EXECUTE`. It even adds additional language features such as syntax for HASH and LIST literals, higher level array concatenation, bettering support for chaining function/method calls and subscripts.
>
>
>
> MIDLE is however not without limitations. Some limitations are due to the limit of IDL language itself, notably output arguments and object property access (object method calls are OK). Others are deliberately set by design to meet the scope of MIDLE, notably program control constructs. Please refer to the GitHub page for details.
>
>
>
> MIDLE requires IDL 8.0 or up (8.3 is recommended).
>
>
>
> Here are a few examples using MIDLE (full documentation can be found at the GitHub repo page).
>
>
>
> ------------------------------------------------------------ --------
>
> ; Mandatory classic example
>
> print, midle('"Hello, World!"')
>
> midle, 'print, "Hello, World!"'
>
>
>
> ; Array of strings
>
> midle, ['print, "STAR"', 'print, "WARS"']
>
> ; Or write them in one line
>
> midle, 'print, "STAR" & print, "WARS"'
>
>
>
> ; Evaluate the content of given file
>
> midle, 'filename', /file
>
> ; Passing variables
>
> env = {num: 50}
>
> print, midle('indgen(2,3,4, start=num)', env)
>
>
>
> ; Procedure call
>
> midle, 'plot, indgen(50, start=100), /ynozero'
>
>
>
> ; Expressions
>
> print, midle('-2.2 - 2 mod ((42. + 22) ^ 2 > 3 - 4.2) * 2.2 / 2.4')
>
> print, midle('x eq 42 ? indgen(5, start=x) : indgen(5)', {x: 42})
>
>
>
> ; Assignment
>
> print, midle('x = 42', env)
>
> print, env.x ; output 42
>
> print, midle('h = Hash()', env)
>
> print, midle('h["a"] = indgen(3,4,5)', env)
>
> print, midle('h["a", 0, 1, 2] = 420', env)
>
> print, (env.a)[0,1,2] ; output 420
>
> ; List literal
>
> print, midle('("a", "list", "literal")')
>
>
>
> ; Hash literal
>
> print, midle('h{"x": 42, "y": 22, "description": "This is a hash literal"}')
>
>
>
> ; Higher level array concatenation:
>
> env = {a: indgen(6,5,4,3,2), b: indgen(6,5,4,3,2, start=720)}
>
> help, midle('[ [[[[a]]]], [[[[b]]]] ]', env) ; concatenate on the 5th dimension
>
>
>
> ; Better support for chained function/method calls and subscripts
>
> print, midle('list(indgen(3,4,5,6)[*,0:3:2,4,*][2,*,0,0:5:2], /extract).count()')
>
>
>
> ------------------------------------------------------------ --------
>
>
>
> Comments and suggestions are welcome.
>
>
>
> I'd like to thank Mike Galloy for his wonderful mgunit and idldoc, which I used extensively for developing MIDLE.
>
>
>
> Cheers,
>
> Yang
MIDLE is now at v0.2.0 and can be downloaded at
https://github.com/ywangd/midle/archive/v0.2.0.zip
Version 0.2.0 2014-07-28
New Feature: Subscripts and dot notations can now also be chained for the left-hand-side variable of assignments. This allows direct assignment to an item of a list where the list itself is inside an array.
Improve: Error handling. MIDLE now always provides helpful information if the error is due to the input string of code. It also always return the error message through the error output keyword.
Bug Fix: Implicit integer and unsigned integer are now auto-promoted to their corresponding LONG and LONG64 types when necessary.
Version 0.1.1 2014-07-25
Improve: Array subscripting optimized.
Improve: Error handling for type conversion during array concatenation
Improve: Documentations
Bug Fix: Assignment can now be done to slice of a list
|
|
|
|
|
|
|
|
Re: [ANN] MIDLE - Almost an Alternative to EXECUTE [message #89163 is a reply to message #89157] |
Tue, 29 July 2014 23:35   |
SonicKenking
Messages: 51 Registered: October 2010
|
Member |
|
|
On Wednesday, July 30, 2014 6:31:10 AM UTC+10, superchromix wrote:
> I'm still trying to understand how and why to use this tool.
>
>
>
> Could MIDLE be used as... an IDL console implemented within an IDL program?
>
>
>
> Otherwise, could you please explain what was your motivation for creating this project?
>
>
>
> thanks!
>
> Mark
Hi Mark,
The original motivation of MIDLE came from the desire to use a script containing a list of IDL assignments as a configuration file of an application that runs in IDL VM. As EXECUTE cannot be used in VM, MIDLE is developed to parse the configuration file.
It is like if you use XML for configuration file, you need a XML parser. Similarly, if you use IDL statements for configuration file, you need an IDL parser and this is where MIDLE comes in.
Though it was not the intention of MIDLE, I guess it is possible to use it as a mini console (a pare down version of IDL) in a GUI application for some interactive data analysis. It could be useful as it exposes some underlying IDL powers to end-users who do not own IDL licenses.
Cheers,
Yang
|
|
|
Re: [ANN] MIDLE - Almost an Alternative to EXECUTE [message #89165 is a reply to message #89163] |
Wed, 30 July 2014 04:36   |
SonicKenking
Messages: 51 Registered: October 2010
|
Member |
|
|
On Wednesday, July 30, 2014 4:35:47 PM UTC+10, SonicKenking wrote:
> On Wednesday, July 30, 2014 6:31:10 AM UTC+10, superchromix wrote:
>
>> I'm still trying to understand how and why to use this tool.
>
>>
>
>>
>
>>
>
>> Could MIDLE be used as... an IDL console implemented within an IDL program?
>
>>
>
>>
>
>>
>
>> Otherwise, could you please explain what was your motivation for creating this project?
>
>>
>
>>
>
>>
>
>> thanks!
>
>>
>
>> Mark
>
>
>
> Hi Mark,
>
>
>
> The original motivation of MIDLE came from the desire to use a script containing a list of IDL assignments as a configuration file of an application that runs in IDL VM. As EXECUTE cannot be used in VM, MIDLE is developed to parse the configuration file.
>
>
>
> It is like if you use XML for configuration file, you need a XML parser. Similarly, if you use IDL statements for configuration file, you need an IDL parser and this is where MIDLE comes in.
>
>
>
> Though it was not the intention of MIDLE, I guess it is possible to use it as a mini console (a pare down version of IDL) in a GUI application for some interactive data analysis. It could be useful as it exposes some underlying IDL powers to end-users who do not own IDL licenses.
>
>
>
> Cheers,
>
> Yang
Another potential usage is to provide a scripting language interpreter for a GUI application. Something like how you can script Photoshop with VBScript. In MIDLE's case, the scripting language happens to share the same syntax as the language with which the application itself is written in.
MIDLE as it is now lacks support for program control constructs, e.g. IF/ELSE, FOR, etc, which is pretty much mandatory for a proper scripting language. But it is possible to add them. In fact, this potential now really makes me want to add more features to MIDLE.
|
|
|
Re: [ANN] MIDLE - Almost an Alternative to EXECUTE [message #89166 is a reply to message #89165] |
Wed, 30 July 2014 06:34  |
markb77
Messages: 217 Registered: July 2006
|
Senior Member |
|
|
On Wednesday, July 30, 2014 1:36:01 PM UTC+2, SonicKenking wrote:
> Another potential usage is to provide a scripting language interpreter for a GUI application. Something like how you can script Photoshop with VBScript. In MIDLE's case, the scripting language happens to share the same syntax as the language with which the application itself is written in.
>
>
>
> MIDLE as it is now lacks support for program control constructs, e.g. IF/ELSE, FOR, etc, which is pretty much mandatory for a proper scripting language. But it is possible to add them. In fact, this potential now really makes me want to add more features to MIDLE.
I'm not sure that I fully understand this, but it seems very useful. I am also writing a GUI application which would benefit from the ability to be scripted...
ah - I see. If one had their IDL code already built into a SAV file... using this tool one would still be able to add features to the code by writing a "plugin" module (in IDL) and then using MIDLE to execute it. This would also be VM-safe. cool!
|
|
|