473,789 Members | 2,833 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Csharp simple script interpreter

In the course of my project, I must include some custom logic and
would like to integrate a small script language in my application for
that purpose.
In C++, I used the LUA script language and I know that bindings exists
for a LUA/c# integration, but only using the binary DLL.
However, I would prefer a native c# solution and for a small language,
not a huge interpreter like Python.

Has anybody seen such implementation ?
Thanks,

Joel

Feb 3 '07 #1
5 10648
On 3 Feb, 09:44, "Joel" <fr.joel.ja...@ gmail.comwrote:
In the course of my project, I must include some custom logic and
would like to integrate a small script language in my application for
that purpose.
In C++, I used the LUA script language and I know that bindings exists
for a LUA/c# integration, but only using the binary DLL.
However, I would prefer a native c# solution and for a small language,
not a huge interpreter like Python.

Has anybody seen such implementation ?
Thanks,

Joel
Would C# be appropriate for your scripting requirements? It's really
simple to dynamically compile and load code into a running
application. I hadn't heard of LUA, I'm just looking at the docs now
and I can't see anything it does well that you can't do in C# if that
makes sense. There's a good tutorial on CodeProject that I can't find
which shows how to type in code, have it compiled and even list any
compilation errors.

Feb 3 '07 #2
If your script language is very simple, you could build your own interpreter
using a combination of RegEx and the various Parse functions. If it is too
complicated for that, you can find a parser, in C#, at
http://www.frontiernet.net/~fredm/pa...istWebPage.htm .
"DeveloperX " <nn*****@operam ail.comwrote in message
news:11******** **************@ p10g2000cwp.goo glegroups.com.. .
On 3 Feb, 09:44, "Joel" <fr.joel.ja...@ gmail.comwrote:
>In the course of my project, I must include some custom logic and
would like to integrate a small script language in my application for
that purpose.
In C++, I used the LUA script language and I know that bindings exists
for a LUA/c# integration, but only using the binary DLL.
However, I would prefer a native c# solution and for a small language,
not a huge interpreter like Python.

Has anybody seen such implementation ?
Thanks,

Joel

Would C# be appropriate for your scripting requirements? It's really
simple to dynamically compile and load code into a running
application. I hadn't heard of LUA, I'm just looking at the docs now
and I can't see anything it does well that you can't do in C# if that
makes sense. There's a good tutorial on CodeProject that I can't find
which shows how to type in code, have it compiled and even list any
compilation errors.

Feb 3 '07 #3
Writing a simple C# syntax based interpreter in C# is a simple task. I
occasionaly implement one in my projects when I find use for this kind of
functionality.

What you need is to use CSharpCodeProvi der to compile the prepared source
code which looks basically like this:

you'll declare this class in your project:

public class ScriptBase
{
public virtual void Execute() {}
}

you'll prepare a "template" from which you'll create the source code you are
going to compile dynamically:
string template =
@"public class Script : YourNamespace.S criptBase
{
public override void Execute()
{
$script comes here$;
}
}";

what you do is string source = template.Replac e("$script comes here$",
script); and compile this source using the compiler you get from the code
provider by calling its CreateCompiler method. Make sure you include your
executing assembly (the one that contains class ScriptBase) in the
ReferencedAssem blies.

Then you'll check for errors, take the compiled assembly from the
CompilerResults , and use reflection to create an instance, cast it to
ScriptBase and call its Execute() method - which will execute you script.
You can also implement some binding to your running program (passing a
reference to some "bridge" object to the execute method or constructor) or
methods in the ScriptBase class which you will be able to call in your
scripts, depending on your needs.

this article has source code for expression evaluation that does what I have
described above: http://www.codeproject.com/csharp/runtime_eval.asp
There is an article on C# interpreter that uses a slightly different
approach on codeproject as well: http://www.codeproject.com/csharp/csi.asp

"Joel" <fr***********@ gmail.comwrote in message
news:11******** *************@m 58g2000cwm.goog legroups.com...
In the course of my project, I must include some custom logic and
would like to integrate a small script language in my application for
that purpose.
In C++, I used the LUA script language and I know that bindings exists
for a LUA/c# integration, but only using the binary DLL.
However, I would prefer a native c# solution and for a small language,
not a huge interpreter like Python.

Has anybody seen such implementation ?
Thanks,

Joel

Feb 3 '07 #4


Thank you all for your extensive answers.

As a (mainly) C/C++ programmer, it is quite strange for me to use my
own "internal" compiler in r/t mode.
I will study this solution.

Do you think that this solution is also available on mobile devices ?
I am inclined to think "yes" because it is more "language" dependent
than framework dependent, but... (I had a lot of trouble finding the
available metods in compact framework).

Joel


Feb 4 '07 #5
Unfortunately, this is not supported on mobile devices. The reason is that
there is no C# compiler (csc.exe) that runs on mobile device - you compile
your device applications on desktop.
Some time ago I had an idea to try to convert some freely available parser
for compact framework, create a basic C# compiler (or try to port mono
implementation to CF) and add this functionality to the CF, since (not only)
I really miss dynamic code compilation on compact framework.

"Joel" <fr***********@ gmail.comwrote in message
news:11******** **************@ h3g2000cwc.goog legroups.com...
>

Thank you all for your extensive answers.

As a (mainly) C/C++ programmer, it is quite strange for me to use my
own "internal" compiler in r/t mode.
I will study this solution.

Do you think that this solution is also available on mobile devices ?
I am inclined to think "yes" because it is more "language" dependent
than framework dependent, but... (I had a lot of trouble finding the
available metods in compact framework).

Joel


Feb 4 '07 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
1989
by: Ian Giblin | last post by:
I am an experienced C programmer, learning C++ by writinging a mathematical toolkit in the framework of a script interpreter. I am posting here to ask for advice (or references) on the object design and implimentation. Currently I have a portable "ScriptSession" class which contains the mechanics of looping with a user prompt, parsing a sentence and handling syntax errors, etc., and I wan this to be a class I can use for any script...
6
2275
by: harish | last post by:
Hi, We are developing one application for smartphone. In this we are parsing XMLs and rendering it as UI elements using smartphone SDK. Everything is working fine. Now one more requirement has come. Java script will also be included in the XMLs. We are searching for java script interpreters so that we will give our script files to this interpreters as input andthe output buffer will be pure XML. We have got one java script interpreter,...
27
4624
by: one man army | last post by:
Hi All- I am new to PHP. I found FAQTS and the php manual. I am trying this sequence, but getting 'no zip string found:'... PHP Version 4.4.0 $doc = new DomDocument; $res = $doc->loadHTMLFile("./aBasicSearchResult.html"); if ( $res == true ) { $zip = $doc->getElementById('zipRaw_id')->value; if ( 0 != $zip ) {
1
1585
by: Brian Blais | last post by:
Hello, I was wondering if there is a way to, within a script, jump into the interpreter. What I mean is something like the "keyboard" command in Matlab, where the script pauses and you get an interpreter prompt, where you can look at variables, change their values, etc. then when you exit the interpreter, the script continues from where it left off. Is this possible in python? thanks,
2
2270
by: tom.purl | last post by:
I use the pyGTD script to manage my todo lists and such. From Vim, I shell out a call to the gtd.py script, which updates my todo.txt file after update one of the related pyGTD files. Since I make a lot of updates to the related pyGTD files, I execute the gtd.py script dozens of times a day. The problem is that this script can be a little slow. It usually takes at least 5 seconds to run, time that I can't use Vim (and running it in...
6
15033
by: Alan Isaac | last post by:
I'm fairly new to Python and I've lately been running a script at the interpreter while working on it. Sometimes I only want to run the first quarter or half etc. What is the "good" way to do this? Possible ugly hacks include: - stick an undefined name at the desired stop point - comment out the last half I do not like these and assume that I have overlooked the obvious.
3
2345
by: uzzi | last post by:
I don't know how to make a php script to work via cron...I want to make it run daily...My server API is CGI/Fast CGI.I have hosting from godaddy and in the help section i found that i have to specify the interpreter manually...look what it says: i've tried with /web/cgi-bin/php "$HOME/html/path/to/my/script.php as command and it doesn't work. if i run the script in browser it works...what should i introduce as a command..and do i have...
13
12805
by: jkimbler | last post by:
As part of our QA of hardware and firmware for the company I work for, we need to automate some testing of devices and firmware. Since not everybody here knows C#, I'm looking to create a new scripting language that makes writing automated tests simpler. Really, I'm looking to kind of abstract the power of the C# language into a simpler language that's easier to learn. The script files would be interpreted by a script interpreter...
4
2836
by: Chris8Boyd | last post by:
I am embedding Python in a MSVC++ (2005) application. The application creates some environment and then launches a Python script that will call some functions exported from the MSVC++ application. I want to be able to debug the Python script by using a debug server, like Winpdb (winpdb.org). I use ActivePython 2.5.2.2, Microsoft Visual Studio 2005, and Winpdb 1.3.8.
0
9511
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10200
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10139
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9984
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6769
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5418
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4093
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3701
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2909
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.