Results 1 to 9 of 9

Thread: [2.0] recognition

  1. #1

    Thread Starter
    Hyperactive Member francisstokes's Avatar
    Join Date
    May 2005
    Location
    Kent, England
    Posts
    272

    [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

  2. #2
    Arabic Poster ComputerJy's Avatar
    Join Date
    Nov 2005
    Location
    Happily misplaced
    Posts
    2,513

    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

  3. #3
    Not NoteMe SLH's Avatar
    Join Date
    Mar 2002
    Location
    192.168.0.1 Preferred Animal: Penguin Reason for errors: Line#38
    Posts
    3,051

    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.


  4. #4

    Thread Starter
    Hyperactive Member francisstokes's Avatar
    Join Date
    May 2005
    Location
    Kent, England
    Posts
    272

    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.

  5. #5
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: [2.0] recognition

    Regular expressions are brilliant for tokenising and when you use the compiled option they're quick too

  6. #6

    Thread Starter
    Hyperactive Member francisstokes's Avatar
    Join Date
    May 2005
    Location
    Kent, England
    Posts
    272

    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 ?

  7. #7
    type Woss is new Grumpy; wossname's Avatar
    Join Date
    Aug 2002
    Location
    #!/bin/bash
    Posts
    5,682

    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.

  8. #8

    Thread Starter
    Hyperactive Member francisstokes's Avatar
    Join Date
    May 2005
    Location
    Kent, England
    Posts
    272

    Re: [2.0] recognition

    Cheers wossname.

  9. #9
    Not NoteMe SLH's Avatar
    Join Date
    Mar 2002
    Location
    192.168.0.1 Preferred Animal: Penguin Reason for errors: Line#38
    Posts
    3,051

    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
  •  



Click Here to Expand Forum to Full Width