Tuesday, May 3, 2011

How do you create a computer or scripting language for an application?

Duplicate of:

and others I'm too lazy to find right now.


I'm not asking how to make an incredibly complex language. I just wanted to understand the basics. I would use c# as the underlying language. I know it's vague. I was hoping for something very basic to direct me.

I think I'm mostly interested in creating scripting languages. For example, I see people that write programs but then they have a scripting language for their application. I do not want to rewrite a windows scripting language. Say I had a text file reader and for some reason wanted a scripting language to automate something. I'm not sure how to ask.

Thank you.

EDIT - Thank you for the answers. I was looking at it more for the learning not the doing at the moment. I would probably use LUA, but I am trying to learn more about the concept in general.

From stackoverflow
  • There's no need to create a new scripting language there are several eg. Rhino which is a widely used embeddable javascript (http://www.mozilla.org/rhino/) or Jscript from MS, that you can use directly in your product.

    I've gone the way that you are asking - I once created my own scheme interpreter. This worked really well, but we re-invented a lot of technology and didn't really get a lot of additional benefit. We would have been far better off just using one of the scheme's that were available. I would not make that decision again even though it was fun and successful.

  • You could take a look at LUA - I've used it to great success each time I asked myself the question "How would I automate insert task here in insert one of my apps here?"

    Edit: Here are some examples (taken from the links page, admittedly, unwieldy Lua Wiki) on how you could embed Lua in your app:

    Sii : +1. Lua's entire raison d'etre is to be easily integrated into your application and get out of the way performance-wise, you're highly unlikely to implement anything better within a reasonable timeframe.
    Sii : Also, since the author states .NET as the host platform: http://luaforge.net/projects/luainterface/ is a C#/Lua binding. (Can't vouch for the quality, it seems current and active though.)
    dmckee : Nice answer to the OPs problem rather than the question, BTW.
  • You can use an existing language like Python or Javascript. For example, for Javascript, there is http://www.mozilla.org/rhino/ for Java apps. So typically you don't need to actually invent a new language, you would just provide a custom API for a language that already exists.

  • first you need a lexical parser like lex, then a syntax parser like bison.

    then you can work with the syntax parser to create an interpreter to 'execute' the syntax results.

    that's how the most scripting languages do.

    p.s: another way is to practice by writing shells - shell scripts (bash, csh, or sh) are highly simplified scripting languages.

  • Some terminology is in order. You may be talking about a domain-specific language. The two basic ways to transform a text file into an "executable": a compiler or an interpreter. An interpreter fits the scripting concept better, as it is easier to build and executes lines one at a time. Note that beyond a very simple language both writing a decent parser or a decent interpreter are non-trivial. The classic work on interpreters is SICP, but this is quite a hard book for beginners.

  • Scott Hanselman mentioned in his latest hanselminutes podcast that integrating IronPython to allow scripting of an existing application was very easy to do.

    If you're interested in the end target of having your application be scriptable, then you should definitely consider using an existing language rather than attempting to write your own.

    If you are more interested in the educational experience of writing your own scripting language, then you should go for it!

0 comments:

Post a Comment