|
-
Jun 17th, 2006, 08:22 AM
#1
Thread Starter
Hyperactive Member
[2.0] recognition
im working on a scripting language project (well, i havent started yet, because i have this important question ).
I'm not sure how I'd take commands that had arguments and process the arguments.
For example:
the command for printing some text to the console is:
Code:
Say "This is the text to be printed"
How would i recognise that the user has used the "say" command, and where the text they wish to print starts and finishes.
Thank you for any replies
-
Jun 17th, 2006, 09:03 AM
#2
Re: [2.0] recognition
store your commands in a table and check every line for StartsWith(..)
"I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
My Blog
-
Jun 17th, 2006, 09:41 AM
#3
Not NoteMe
Re: [2.0] recognition
Your implimentation will depend on how complex you want it.
I.e. do you want it to handle flow statements, e.g. switch, if, else etc.?
Do you want looping?
Do you want UDT's, Classes or Structs?
If you only want 'Command Arguments' as you suggest with ur 'say' command then the method suggested by ComputerJy is fine, but if you want it to be more complex you should research Tokenizing to start with, as well as writing a parser.
You could also look at the Reflection namespace in .NET, although it may not be that usefull (it allows you to create new data types e.g. new classes at runtime).
Quotes:
"I am getting better then you guys.." NoteMe, on his leet english skills.
"And I am going to meat her again later on tonight." NoteMe
"I think you should change your name to QuoteMe" Shaggy Hiker, regarding NoteMe
"my sweet lord jesus. I've decided never to have breast implants" Tom Gibbons
Have I helped you? Please Rate my posts. 
-
Jun 17th, 2006, 12:19 PM
#4
Thread Starter
Hyperactive Member
Re: [2.0] recognition
I really just want to start the project quite small, see whats involved with making a language. I would eventually like to add looping and if-else but i don't think i'd make it OO.
-
Jun 17th, 2006, 12:42 PM
#5
Re: [2.0] recognition
Regular expressions are brilliant for tokenising and when you use the compiled option they're quick too
-
Jun 17th, 2006, 02:08 PM
#6
Thread Starter
Hyperactive Member
Re: [2.0] recognition
I was testing some of the stuf you guys said, and i came up with this:
Code:
string cmd = textBox1.Text;
if (cmd.StartsWith("Say \""))
{
cmd = cmd.TrimStart('S','a','y',' ','"');
cmd = cmd.TrimEnd('"');
MessageBox.Show(cmd);
}
That works, but if the first letter after the " is "S","a","y" or "', it cuts that letter off.
Any suggestions ?
-
Jun 17th, 2006, 03:33 PM
#7
Re: [2.0] recognition
Don't use trim. Just ignore the first 5 characters using the Substring method. If you use trim in that ugly manner and the user types a string that starts with S,a,y or " ", then its going to break it.
whatever.Substring(5)
I don't live here any more.
-
Jun 17th, 2006, 03:43 PM
#8
Thread Starter
Hyperactive Member
-
Jun 17th, 2006, 05:01 PM
#9
Not NoteMe
Re: [2.0] recognition
Once you want more complex stuff (for example ignoring white space, commands with more parameters etc.) you'll want to look at tokanizing.
Btw, a similar excersize, that could be useful to try once you get into it would be making something that could do calculations like such:
1+ 5 * ((3)/(2-4))
Then u could expand it to add variables defined on other lines, then combine it with your command code.
Quotes:
"I am getting better then you guys.." NoteMe, on his leet english skills.
"And I am going to meat her again later on tonight." NoteMe
"I think you should change your name to QuoteMe" Shaggy Hiker, regarding NoteMe
"my sweet lord jesus. I've decided never to have breast implants" Tom Gibbons
Have I helped you? Please Rate my posts. 
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|