Stumped with Scripting Language in Design Philosophy
|
|
Okay. I allow functions to be defined in this language. I look for functions by searching function, and the entire function will be mapped into an associative list for easy recall. However, while findText'ing function, how do I know it's not in a string or function?
Well, I thought of searching the brackets. If the left bracket had a lower findtext position than the function tag was found AND the right bracket had a higher findtext position than the function tag, it'd be inside a function. However, what if they simply forgot the last bracket on another procedure? Then how do I do this?
I could search for quote characters, but I'd never know how to. You can find quotes all over. Please helpx0rz/
|
In short, Lexical Analysis is how most multi-pass Interpreters and compilers do it. Basically, you match text to regular expressions, the first match (If you're being greedy, which may be easiest) is the one you assume it is, produce a relevant symbol to demonstrate what you found, add it to a stack and eat the text you matched. This technique strips out unwanted formating (Like whitespace) and clears up certain problems, including the one you stated.
I haven't the foggiest how easy or difficult this would be in DM, but you may find Lummox JR's regex library useful.