Using JScript in Excel for the DSL

  • I tested the following: If one defines a multiline text box with name 'CommandBox' for entering the code, and a button named 'Execute' for execution attached to a subroutine 'exec()', then the following very simple code shows the idea and could be a starting point for the DSL:

    Dim sc
    Sub exec()
      If Not IsObject(sc) Then
        Set sc = New ScriptControl
        sc.Language = "JavaScript"
      End If
      MsgBox sc.eval(CommandBox.Text)
    End Sub

    Once defined, the JScript Interpreter will be reused, keeping the context of former commands. In fact, this is a big feature: Once, at initialization of sc, one could define several functions or objects dealing with the access to the library functions.

    It would then be possible to create a DSL on top of the JScript syntax, simply by adding some predefined objects.