2

Possible Duplicate:
Implementing a scripting language in C#

I have a C# app, now I want to allow users invoking some methods from my app, for example:

:step2
$test2=Click("post")
Wait()
IF($test2==1){
    runjs("mceRemoveControl")
    Form("post")
    $test3=Input("post_title","$TITLE")
    IF($test3==0){
        GOTO(step2)
    }
}

This is custom language which I want to parse in my app. Methods Click,runjjs,Input are methods from my C# program. Where I should looking for solution for such task?

Community
  • 1
  • 1
user1585814
  • 21
  • 1
  • 2

2 Answers2

4

There are many ways.. just for starters:

If you want to stick with that funky syntax, start with http://www.antlr.org/ or similar parser generator or framework.

If you just want to have reasonable scripting language, not necessarily looking as the example, try IronRuby, IronPython or even JavaScript or C# (namespace CompilerServices allows you to compile code on the fly, then load it (possibly in separate appdomain to be able to unload it afterwards) and run)..

Edit: another thread with lots of links to parsers/compilercompilers: What is a good C# compiler-compiler/parser generator?

Community
  • 1
  • 1
quetzalcoatl
  • 32,194
  • 8
  • 68
  • 107
2

I found the book Compiler Construction from Niklaus Wirth to be helpful for this type of task. Because we are talking about creating a compiler here. It is a small book that explains fundamental aspects of formal languages, explains the syntax description language EBNF and explains systematically how to write a compiler. Even if you have just an interpreter in mind. An interpreter can be considered as a special kind of compiler.

Be aware of the fact that this is not an easy task. You also might consider using a compiler-compiler. An interesting alternative approach is provided by Irony. Irony allows you to specify a language syntax directly in C# by using operator overloading.

Olivier Jacot-Descombes
  • 104,806
  • 13
  • 138
  • 188