Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

.NET 

Lexiron - Front-End Script Engine [2.1 Updated]

I present you Lexiron or 'Lexi' and has entered the beta stage.

The purpose of Lexi is that you can extend your functionality of your application dynamicly.
Adding your functions hooked into Lexi, making it agile and a versatile tool for your applications.

Ever wanted to let your end-users change the behavior of your application or perhaps you want
to have a dynamic element on your own application to make it more functional?
Lexi could be your awnser.

Extended with scripts that can be build to serialized objects and even encrypted if you want it protected.

[Image: ar2o8fz.png]

How does it work?

I'm not gonna explain every detail but it uses the LL(1) top down parsing method.
You will find more details on this method here:

http://en.wikipedia.org/wiki/LL_parser

Lexi breaks down the character stream into tokens wich then are broken down to
seperate AST elements, after this is done Lexi can save this state of your script into a serialized object.

As you can see here:
[Image: Tm7CzlH.png]

How can we use it?

You set a new reference of lexi in your project.

[Image: Tb6Kw5Q.png?1?3504]

Declare the engine
Code
Private Engine As Lexiron.Engine

Private Sub FrmMain_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
  Engine = New Lexiron.Engine
End Sub

To load and build a script:
Code
Engine.Parse(Filename)

If no errors occoured you can save it to a serialized object:
Code
Engine.Save(Filename)

To execute your finalized script object:
Code
Engine.Execute(Filename,Parameters())

This function also returns a value if the script makes use of the 'return()'

How can we check if any errors occoured?

You can check the engine for errors as follows
Code
if (Engine.HasError) then
..code...
End If

If this is true, you wanna see what kind of errors occoured

Code
For Each Err As ParseError In Engine.Errors
  ...show errors...
Next

Engine usefull routines
Code
Public Sub Parse(Filename As String)
Public Sub AddDelegate(Reference As String, Delegate As ScriptDelegate)
Public Sub RemoveDelegate(Reference As String)
Public Sub Open(Filename As String, Optional Key As String = "")
Public Sub Save(Filename As String, Optional Key As String = "")
Public Function Execute(Filename As String, ParamArray Params() As Object) As Object
Public Function Execute(ParamArray Params() As Object) As Object
Public Function Evaluate(Expression As String, ParamArray Params() As Object) As Object
Public Sub GenerateTreeview(Tv As TreeView)
Public Sub SerializeObject(Obj As Object, OutputFile As String, Compression As Boolean, Optional Key As String = "")
Public Function Deserialize(Obj As Object, Inputfile As String, Optional Key As String = "") As Object

Properties:
Code
Public ReadOnly Property Tokenizer As Tokenizer
Public ReadOnly Property Tokens As List(Of Token)
Public ReadOnly Property HasError As Boolean
Public ReadOnly Property Errors As ParseError()
Public ReadOnly Property AstTree As Statement
Public Property Break() As Boolean

Changelog

2.0 Initial Release
- Released

Download link

2.1
- Fixed: Return(Expression) will terminate any further execution and return to the caller
- Added: For-Loops
- Added: break() Will exit from the current active for-loop
- Added: Switch Case (With '..else' support)
- Added: Engine.Evaluate() will evaluate and execute direct input and return if any
- Added: Engine.Execute() Another execute signature for in combination with Engine.Open()
- Added: Engine.Break() Will forcefully stop a scipt execution

Download link

Qeustions and Feedback are welcome.

If you need help using my software you can pm me for skype.

(if ur planning to decompile my engine, go ahead, but your better of asking me how it works as i can explain to you how it works)

- Barret
Been talking about this already for quite a while with barret, as we work on similar projects :3.

Glad to see it released. Really reminds me of LUA, as it is also a script language that extends a program. This one however has a a C-ish syntax, which I like actually. As far as I can see it's really easy to add functions, which is pretty sweet!

Some questions: Does it also support some kind of start-up arguments ? How about declaring functions inside the script ? Maybe you can add a possibility to execute these functions as well from the host application, so people can write for instance callbacks for events. That would be pretty cool.
https://github.com/Washi1337

"I'll tell you this UDP joke, and I don't care if you will get it or not."
You seriously have too much free time, to do so much in so little time. How much coffee do you consume on a daily basis?
I'm really curious on how that syntax tree works :3
Great job as always ^^
[Image: IQE6i8G.png]

BlackCap Wrote:You're even more verbose than Java.
About using GoTo's in VB/C#:
Only3 Wrote:asm use it why u shouldnt
(May 3, 2014 10:44 AM)Washi Wrote:  Been talking about this already for quite a while with barret, as we work on similar projects :3.

Glad to see it released. Really reminds me of LUA, as it is also a script language that extends a program. This one however has a a C-ish syntax, which I like actually. As far as I can see it's really easy to add functions, which is pretty sweet!

Some questions: Does it also support some kind of start-up arguments ? How about declaring functions inside the script ? Maybe you can add a possibility to execute these functions as well from the host application, so people can write for instance callbacks for events. That would be pretty cool.

Arguments
Yes it does
Code
Engine.Executes(Filename,Arguments)

Declaring external function
Yes it does

Code
Engine.AddDelegate("print", New Engine.ScriptDelegate(AddressOf Me.ScriptMessage))

and for that delegate signature:
Code
Private Function ScriptMessage(Params() As Object) As Object
      If (Params.Length > 0) Then
      ScriptLog.AppendText(String.Join("", Params) & ControlChars.CrLf)
      ScriptLog.SelectionStart = DebugLog.Text.Length - 1
      ScriptLog.ScrollToCaret()
      End If
      Return String.Empty
    End Function

- Barret
This is truly awesome bro! I've seen you post this in another thread and thought it was pretty cool.
[Image: 1zL3pDG.jpg]
This is just amazing. Ability to dynamically execute code in your app in another language and use it in the actual app, now that is epic. Also I was going to ask for the Help thingy, but it's already there. The three is amazing and the whole thing is amazing.
this is really some good shit, I appreciate
Next update is coming soon!

To be expected new features in lexi:

- For Loops
Can be escaped with break()
Nested loops possible with the use of a Loopstack

Code
for x = 1 to 10 {
    print("Hello!");
      if (x=5) { break(); }
}

- Select Case

Code
Switch x {
    :1 { }
    :2 { }
    :3 { }
}

- Fixed: Return() will terminate the script execution and return to the caller.
- Added: Syntax tree will show and mark where "escapes" are set for better overview.

- Barret
(May 3, 2014 10:55 AM)TheBarret Wrote:  Arguments
Yes it does
Code
Engine.Executes(Filename,Arguments)

Declaring external function
Yes it does

Code
Engine.AddDelegate("print", New Engine.ScriptDelegate(AddressOf Me.ScriptMessage))

and for that delegate signature:
Code
Private Function ScriptMessage(Params() As Object) As Object
      If (Params.Length > 0) Then
      ScriptLog.AppendText(String.Join("", Params) & ControlChars.CrLf)
      ScriptLog.SelectionStart = DebugLog.Text.Length - 1
      ScriptLog.ScrollToCaret()
      End If
      Return String.Empty
    End Function

- Barret

I was actually not talking about external functions, but internal functions, which are declared inside the script and not by the host. This allows people to for instance set up event listeners or callbacks that will get executed when an event occurs. Suppose I have a button in the host application and want to add a callback to the click event of that button in my script.

The script would look something like below.

PHP Code

<?php 
addhandler
(button_click_event, click_callback);

function 
click_callback()
{
   print(
"This script has just handled a click event from the host application!");
} 

The addhandler would be specified by the host application of course, as that is an external function. It will subscribe a function declared inside the script to an event declared outside the script. And on the host, I'd put in my button handler something like below, which will dispatch the event and calls all functions that are subscribing to this event.

PHP Code

<?php 
Public Sub Button1_Click(....) Handles Button1.Click
    Engine
.DispatchEvent(button_click_event)
End Sub 

If you could implement that, then this script engine would be really useful.
https://github.com/Washi1337

"I'll tell you this UDP joke, and I don't care if you will get it or not."
(May 3, 2014 03:29 PM)Washi Wrote:  If you could implement that, then this script engine would be really useful.

Hmmm ye i think i can make that possible.

Let me see what i can do tomorrow, got some new updates waiting already (forloops are working tho)

- Barret
Impressive man. That would be much better if you were sharing the source code though. I'm really interesting to see how you handled the parsing. Amazing job anyway.
[Image: 1riOqZa.png]
New update,

- Forloops
- Switch
And a few fixes..
http://sharpdox.de/en/ - Software for creating documentation for C# projects. I love it.
(May 4, 2014 07:24 PM)Smelly Shoes Wrote:  http://sharpdox.de/en/ - Software for creating documentation for C# projects. I love it.

Nice find, really usefull thank you! ✌
(May 3, 2014 03:28 PM)TheBarret Wrote:  Next update is coming soon!

To be expected new features in lexi:

- For Loops
Can be escaped with break()
Nested loops possible with the use of a Loopstack

Code
for x = 1 to 10 {
    print("Hello!");
      if (x=5) { break(); }
}

- Select Case

Code
Switch x {
    :1 { }
    :2 { }
    :3 { }
}

- Fixed: Return() will terminate the script execution and return to the caller.
- Added: Syntax tree will show and mark where "escapes" are set for better overview.

- Barret

In my opinion, you shouldn't be using "Break()" or "Return()", but instead "Break" and "Return". In fact, those aren't methods or functions, so you shouldn't be using their syntax.

Nice work though.
The Alliance


Possibly Related Threads...
Thread / Author Replies Views Last Post
by NobleJul 17, 2024 08:13 AM 4 181 Jul 17, 2024 08:13 AM
Last Post: ShadowCipher
[.NET] by BarretNov 16, 2017 08:14 PM 0 254 Nov 16, 2017 08:14 PM
Last Post: Barret
[C] by Recycle Bin.Nov 6, 2015 09:36 PM 61 6,297 Nov 6, 2015 09:36 PM
Last Post: TheUnCola