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.