Thread: Self Made C Scripting Language.

  1. #1
    Registered User
    Join Date
    Nov 2010
    Location
    In my house
    Posts
    32

    Self Made C Scripting Language.

    Hey everyone, I have a few questions regarding creating my own scripting language.

    I'm having a bit of trouble when it comes to tokenizing the file (ie, the lexical analyzer). My first version, ashamed as I am to say it, was basically just a huge else-if statement using strcmp(). Eventually I ended up using strtok() which was fine for code such as:
    Code:
    var SomeVariable; /* this assigns a variable named SomeVariable */
    SomeVariable = 3; /* assigns 3 to SomeVariable */
    but I ran into a problem. How would I tokenize and process something such as:
    Code:
    SomeVariable = (3 + 4) - 2 * 3; /* this should make SomeVariable = 1 */
    because strtok() doesn't return what it finds, it only returns a string which contains the next token, so I have some troubles when doing calculations because if I set it up to tokenize brackets, I don't know if it found a bracket or not, It would just return a string.

    I'm just wondering if anyone could give me some tips/pseudocode on how to overcome this.

  2. #2
    Registered User
    Join Date
    Apr 2011
    Location
    Las Vegas
    Posts
    66
    The expression you're referring to is in what's called "infix" notation, and you will need to convert it to "postfix" notation to evaluate it properly.

    Check out InFix to PostFix and PostFix expression evaluation.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Reviving my old scripting language.
    By suzakugaiden in forum Game Programming
    Replies: 4
    Last Post: 06-15-2006, 03:02 PM
  2. Scripting Language
    By ~Kyo~ in forum A Brief History of Cprogramming.com
    Replies: 0
    Last Post: 12-12-2005, 10:10 AM
  3. What's the Difference Between a Programming Language and a Scripting Language?
    By Krak in forum A Brief History of Cprogramming.com
    Replies: 23
    Last Post: 07-15-2005, 04:46 PM
  4. Scripting language
    By Blizzarddog in forum C++ Programming
    Replies: 5
    Last Post: 09-17-2003, 11:47 AM
  5. Creating my own Scripting language in C++ for CGI
    By stovellpaul in forum C Programming
    Replies: 0
    Last Post: 10-01-2002, 03:41 AM