Writing interpreter in Lua

classic Classic list List threaded Threaded
10 messages Options
Reply | Threaded
Open this post in threaded view
|

Writing interpreter in Lua

Gopalakrishnan Subramani
All,

What are the toolset/libraries available in Lua to write the interpretter in Lua for a Domain Specific Language? Can you point the different way of implementing interpreter like

1. Should I convert the language to Lua byte code convention before execution?
2. The core framework will be written in Lua say for example print "hello" in the domain specific language calls a Lua print or similar function writing in Lua. I am not sure whether to map to lua function or should I generate Lua byte codes.

Looking for general advice, where as I never had experience writing interpretter myself, but this is going to be long term project for us. Any basic/intermediate/advanced tutorials or examples would be appreciated.

Thanks,

Gopalakrishnan
Reply | Threaded
Open this post in threaded view
|

Re: Writing interpreter in Lua

steve donovan
On Fri, Nov 11, 2011 at 2:22 PM, Gopalakrishnan Subramani
<[hidden email]> wrote:
> 1. Should I convert the language to Lua byte code convention before
> execution?

Good question. This is the hard way to do it, although you get direct
control over the debug information.  But it will be tied to a
particular Lua implementation - e.g. if targeting Lua 5.1, it will not
work with Lua 5.2 without modification and LuaJIT has a completely
different byte code structure.

It is easier to know what's going on if you (at least initially)
generate Lua source.

The other option is to modify the Lua compiler until it gives the
syntax that you want. People have made curly bracket languages this
way ;)

steve d.

Reply | Threaded
Open this post in threaded view
|

Re: Writing interpreter in Lua

steve donovan
On Fri, Nov 11, 2011 at 2:32 PM, steve donovan
<[hidden email]> wrote:
> syntax that you want. People have made curly bracket languages this
> way ;)

For instance, Bright is a C-like Lua derivative

http://bluedino.net/luapix/Bright.pdf

Great line from the last slide:

"The Lua project has been incredibly understanding about our somewhat
heretical approach"

And of course, there's Squirrel:

http://squirrel-lang.org/

steve d.

Reply | Threaded
Open this post in threaded view
|

Re: Writing interpreter in Lua

Gopalakrishnan Subramani
In reply to this post by steve donovan
Does it mean, Lua JIT is not backward & forward compatible within minor versions?

I thought, the versions adds more libraries than core changes to JIT structure. I could be wrong.

any way, If I distribute the lua dll along with solution, still the modification required in JIT structure? What I am assuming is that not get into Lua inside much, since my lack of language design, I could be wrong in my questions itself.

Thanks for answer.

--

Gopalakrishnan

On Fri, Nov 11, 2011 at 6:02 PM, steve donovan <[hidden email]> wrote:
On Fri, Nov 11, 2011 at 2:22 PM, Gopalakrishnan Subramani
<[hidden email]> wrote:
> 1. Should I convert the language to Lua byte code convention before
> execution?

Good question. This is the hard way to do it, although you get direct
control over the debug information.  But it will be tied to a
particular Lua implementation - e.g. if targeting Lua 5.1, it will not
work with Lua 5.2 without modification and LuaJIT has a completely
different byte code structure.

It is easier to know what's going on if you (at least initially)
generate Lua source.

The other option is to modify the Lua compiler until it gives the
syntax that you want. People have made curly bracket languages this
way ;)

steve d.


Reply | Threaded
Open this post in threaded view
|

Re: Writing interpreter in Lua

Luiz Henrique de Figueiredo
In reply to this post by Gopalakrishnan Subramani
> What are the toolset/libraries available in Lua to write the interpretter
> in Lua for a Domain Specific Language?

Can you try to write your DSL *in* Lua? Lua can surprise you with syntax
that does not look like ordinary Lua but in fact is. Could you give us
an example of what your DSL looks like?

> 1. Should I convert the language to Lua byte code convention before
> execution?

That is one path but if you're doing code generation, why not generate Lua
source code first until you get the design right? That said, you can try
Metalua: http://metalua.luaforge.net/

> 2. The core framework will be written in Lua say for example print "hello"
> in the domain specific language calls a Lua print or similar function
> writing in Lua. I am not sure whether to map to lua function or should I
> generate Lua byte codes.

If your DSL is a simple command-line kind of language, try my lcl
        http://www.tecgraf.puc-rio.br/~lhf/ftp/lua/#lcl

If you need help with lcl, please ask me directly.

Reply | Threaded
Open this post in threaded view
|

Re: Writing interpreter in Lua

Gopalakrishnan Subramani


On Fri, Nov 11, 2011 at 6:26 PM, Luiz Henrique de Figueiredo <[hidden email]> wrote:
> What are the toolset/libraries available in Lua to write the interpretter
> in Lua for a Domain Specific Language?

Can you try to write your DSL *in* Lua? Lua can surprise you with syntax
that does not look like ordinary Lua but in fact is. Could you give us
an example of what your DSL looks like?

The DSL Language I talk is widely used in Automation across world for 15 years of time. They are packaged, we would like to run it as it is on wider platforms like iOS, Android and windows.
So we don't define the DSL.

 
 

> 1. Should I convert the language to Lua byte code convention before
> execution?

That is one path but if you're doing code generation, why not generate Lua
source code first until you get the design right? That said, you can try
Metalua: http://metalua.luaforge.net/


This will be a nice approach and we could try as a first attempt instead of going on complex route. Since I am an amateur in language design, I could not come with any best estimation for these kind of work. Thanks for the link.
 

> 2. The core framework will be written in Lua say for example print "hello"
> in the domain specific language calls a Lua print or similar function
> writing in Lua. I am not sure whether to map to lua function or should I
> generate Lua byte codes.

If your DSL is a simple command-line kind of language, try my lcl
       http://www.tecgraf.puc-rio.br/~lhf/ftp/lua/#lcl


Again, this will help me to understand the basic. Thanks a lot.

 
If you need help with lcl, please ask me directly.



Sure. I will follow you up.


Reply | Threaded
Open this post in threaded view
|

Re: Writing interpreter in Lua

Eduardo Ochs
In reply to this post by Gopalakrishnan Subramani
On Fri, Nov 11, 2011 at 10:22 AM, Gopalakrishnan Subramani <[hidden email]> wrote:
All,

What are the toolset/libraries available in Lua to write the interpretter in Lua for a Domain Specific Language? Can you point the different way of implementing interpreter like

1. Should I convert the language to Lua byte code convention before execution?
2. The core framework will be written in Lua say for example print "hello" in the domain specific language calls a Lua print or similar function writing in Lua. I am not sure whether to map to lua function or should I generate Lua byte codes.

Looking for general advice, where as I never had experience writing interpretter myself, but this is going to be long term project for us. Any basic/intermediate/advanced tutorials or examples would be appreciated.

Thanks,

Gopalakrishnan

Hi Gopalakrishnan,

I've implemented several DSLs on top of Lua - mostly stack-based ones,
so I'm sure that other people are going to be much more able to advise
you about syntax than me :-) - the main links are:


All my DSLs are easy to bootstrap and to extend - but it took me years
to find the easiest ways to attain that, so there's some chance that
you will find some nice tricks there.

I am sure that there are lots of people here who implement DSLs all
the time, but most of these languages are too simple to deserve being
announced publically... Can you say more about what you want to do,
give samples of the syntax that you would like to support, how much
would you mind if this syntax would be changed to make it easier to
implement, etc?

  Eduardo Ochs


P.S.: Jon Bentley: "Little Languages" (CACM version)

Reply | Threaded
Open this post in threaded view
|

Re: Writing interpreter in Lua

Luiz Henrique de Figueiredo
In reply to this post by Gopalakrishnan Subramani
> The DSL Language I talk is widely used in Automation across world for 15
> years of time. They are packaged, we would like to run it as it is on wider
> platforms like iOS, Android and windows.
> So we don't define the DSL.

Could you please give us a sample?

Reply | Threaded
Open this post in threaded view
|

Re: Writing interpreter in Lua

Alexander Gladysh
In reply to this post by Gopalakrishnan Subramani
On Fri, Nov 11, 2011 at 16:22, Gopalakrishnan Subramani
<[hidden email]> wrote:

> All,
>
> What are the toolset/libraries available in Lua to write the interpretter in
> Lua for a Domain Specific Language? Can you point the different way of
> implementing interpreter like
>
> 1. Should I convert the language to Lua byte code convention before
> execution?
> 2. The core framework will be written in Lua say for example print "hello"
> in the domain specific language calls a Lua print or similar function
> writing in Lua. I am not sure whether to map to lua function or should I
> generate Lua byte codes.
>
> Looking for general advice, where as I never had experience writing
> interpretter myself, but this is going to be long term project for us. Any
> basic/intermediate/advanced tutorials or examples would be appreciated.

Shameless plug: for a particular kind of embedded declarative DSLs
(pretty expressive one), you may use this approach:

http://www.slideshare.net/agladysh/declarative-internal-dsls-in-lua-a-game-changing-experience

Alexander.

Reply | Threaded
Open this post in threaded view
|

Re: Writing interpreter in Lua

Gopalakrishnan Subramani
Nice Presentation. Thanks for sharing.


On Tue, Nov 15, 2011 at 6:47 AM, Alexander Gladysh <[hidden email]> wrote:
On Fri, Nov 11, 2011 at 16:22, Gopalakrishnan Subramani
<[hidden email]> wrote:
> All,
>
> What are the toolset/libraries available in Lua to write the interpretter in
> Lua for a Domain Specific Language? Can you point the different way of
> implementing interpreter like
>
> 1. Should I convert the language to Lua byte code convention before
> execution?
> 2. The core framework will be written in Lua say for example print "hello"
> in the domain specific language calls a Lua print or similar function
> writing in Lua. I am not sure whether to map to lua function or should I
> generate Lua byte codes.
>
> Looking for general advice, where as I never had experience writing
> interpretter myself, but this is going to be long term project for us. Any
> basic/intermediate/advanced tutorials or examples would be appreciated.

Shameless plug: for a particular kind of embedded declarative DSLs
(pretty expressive one), you may use this approach:

http://www.slideshare.net/agladysh/declarative-internal-dsls-in-lua-a-game-changing-experience

Alexander.