473,320 Members | 1,870 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Programming a Script language

Hello

I'm new to programming under C#.

I have question about suggestions, how to write a simple script
language, that can handle operations like 'if' statement.

Whats better, operating on variables [ like 'if a>b foo() else goo() ],
or maybe predefined functions [ like if(getA()>getB()) foo() else goo()]

And how to handle script interpretating, or optimising scripts speed?
Like compiling text to some type of ' native' program code.
I'm thinking about fast and simple script language, that will allow to
make templates of behavior in game [ change AI ].

--
Best regards.. or not..
Piotr 'Zenobius' Baranowski
Nov 17 '05 #1
5 1462
Piotr 'Zenobius' Baranowski wrote:
Hello

I'm new to programming under C#.

I have question about suggestions, how to write a simple script
language, that can handle operations like 'if' statement.

Whats better, operating on variables [ like 'if a>b foo() else goo() ],
or maybe predefined functions [ like if(getA()>getB()) foo() else goo()]

And how to handle script interpretating, or optimising scripts speed?
Like compiling text to some type of ' native' program code.
I'm thinking about fast and simple script language, that will allow to
make templates of behavior in game [ change AI ].

--
Best regards.. or not..
Piotr 'Zenobius' Baranowski


Yet Another Compiler Compiler (yacc) is a application for turning a
language grammar into code. It's an old C thing originally on Unix
systems, but ports were done to Java. Have a search on google and you
might come across a C# port of YACC.

Jimbo
Nov 17 '05 #2
"Piotr 'Zenobius' Baranowski" <ze******@zeno.pl> wrote in message
news:de**********@atlantis.news.tpi.pl...
Hello

I'm new to programming under C#.

I have question about suggestions, how to write a simple script
language, that can handle operations like 'if' statement.

Whats better, operating on variables [ like 'if a>b foo() else goo() ],
or maybe predefined functions [ like if(getA()>getB()) foo() else goo()]

And how to handle script interpretating, or optimising scripts speed?
Like compiling text to some type of ' native' program code.
I'm thinking about fast and simple script language, that will allow to
make templates of behavior in game [ change AI ].


How about using Microsoft.CSharp.Compiler.Compile()?
Nov 17 '05 #3
> How about using Microsoft.CSharp.Compiler.Compile()?

This gives me whole C# lang support, right? :-)
This should be easy to write lang - for players that want to change
their units behavior. Like:

if attacked() run() else stay()

or

if attackerNum>100 run() else fight

it should be compiled, to run fast, and then such compiled script,
loaded as resource, can be added to unit/units.

Any suggestions?
--
Best regards.. or not..
Piotr 'Zenobius' Baranowski
Nov 17 '05 #4

"Piotr 'Zenobius' Baranowski" <ze******@zeno.pl> wrote in message
news:de**********@nemesis.news.tpi.pl...
How about using Microsoft.CSharp.Compiler.Compile()?


This gives me whole C# lang support, right? :-)
This should be easy to write lang - for players that want to change
their units behavior. Like:

if attacked() run() else stay()

or

if attackerNum>100 run() else fight

it should be compiled, to run fast, and then such compiled script,
loaded as resource, can be added to unit/units.

Any suggestions?


Just look up scripting languages and write an interpreter or compiler (or if
you are using .NET 2.0, complie to DynamicMethods). Its not the easiest
thing in the world, but its doable. You'll need a parser(you could use a
parser generator or write your own, I prefer the former) and a bit of
compiler knowhow. Developing a scripting language is well beyond what could
be explained here.

You might also want to look for python or lua bindings or consider existing
..NET languages like boo or nemerle that might help.

Nov 17 '05 #5
Piotr 'Zenobius' Baranowski wrote:
How about using Microsoft.CSharp.Compiler.Compile()?

This gives me whole C# lang support, right? :-)
This should be easy to write lang - for players that want to change
their units behavior. Like:

if attacked() run() else stay()

or

if attackerNum>100 run() else fight

it should be compiled, to run fast, and then such compiled script,
loaded as resource, can be added to unit/units.

Any suggestions?


I am doing a game where a computer controlled player has to move army
units and make decisions about which territories to invade, when to
retreat etc.

My solution for having different behaviours for different players is to
use an implementation of the strategy pattern. This involves purely java
code (but its the same for c#) where I define the interface that all
behaviours must implement. The interface basically passes in the game
state so that the implemented behaviour can make its decision. Once
written the new class is compiled in the normal way. I then use
reflection to load the appropriate class into the game at run time. I
have a configutation file which tells the system which class to load and
use.

In theory this allows A. N. Other person to write a strategy and try it
out in the game.

Jimbo.
Nov 17 '05 #6

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

Similar topics

33
by: Joe Cheng | last post by:
I'm curious about something... many Artima.com members who have a Java background and learned Python have come to the conclusion that Java and Python are highly complimentary languages. They would...
2
by: J. Muenchbourg | last post by:
I'm doing a few tests with simple .net scripts, and I noticed that I display the following error message at ErrMessage.Text if I don't enter "BLUE" in capital letters into my input textbox: ...
80
by: Bibby | last post by:
Hi, I'm interested in getting started in the programming world. I've dabbled in C, C++ and VB6. Which would be the best language to focus my attention to regarding the following considerations: ...
20
by: James++ | last post by:
Hi all, I have been recently assigned the responsibility to conduct a survey, the aim of which to find the most popular programming language. I know that many of you program only in C#, but will...
458
by: wellstone9912 | last post by:
Java programmers seem to always be whining about how confusing and overly complex C++ appears to them. I would like to introduce an explanation for this. Is it possible that Java programmers...
111
by: Enteng | last post by:
Hi I'm thinking about learning C as my first programming language. Would you recommend it? Also how do you suggest that I learn it?What books/tutorials should I read for someone like me? Thanks...
3
dmjpro
by: dmjpro | last post by:
plz send me a good link which can clearify me how the J2EE framework works i want the details information .... plz help thanx
29
by: Martin Schmied | last post by:
Dear folks I'm looking for good sites/material for this topic: Introduction to programming, using Javascript. So, not introduction to programming *in" Javascript. Well, I guess this would be...
53
by: Vicent Giner | last post by:
Hello. I am new to Python. It seems a very interesting language to me. Its simplicity is very attractive. However, it is usually said that Python is not a compiled but interpreted programming...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.