Hello everyone! recently I've been working on a scripting language, but I've run into a few problems. The biggest of all is finding a good way to parse the text from a a line of code in the right order so i can run the commands in the right order. Now before I was splitting a string by ";" and then splitting it by "," to get the command and then the arguments. It came out something like this:
Code:
Now if you look at this method you'll see that it's almost impossible to put a command inside of another command or use loops/conditionals with this syntax. That's why I have an "output variable"(a variable that the output of the command is stored to), but event then it still doesn't solve the problem of loops/conditionals. What I'm looking for is a way to parse a command like this:
Code:
I cant seem to figure out how to do this. I was thinking that I could use a method with these steps:
1.) find the first command or keyword
2.) if its a command look for any parse the inputs
3.) if its a keyword parse accordingly
Now this would technically work but I cant figure out how to parse the inputs. I was thinking that I would have a parse function, then when a command parses the inputs I uses the parse function to figure out get the value of everything inside. Now this works because when a command calls the parse function the parse function calls the next command inside of its inputs. But this turns out to be pretty slow. So basically what I'm asking is, does anyone know of a better way to parse a string of nested commands? I'm really stumped here so any help would be greatly appreciated.
Thanks in advance,
Spud2451
Code:
get_input,output_variable,"prompt here";
Now if you look at this method you'll see that it's almost impossible to put a command inside of another command or use loops/conditionals with this syntax. That's why I have an "output variable"(a variable that the output of the command is stored to), but event then it still doesn't solve the problem of loops/conditionals. What I'm looking for is a way to parse a command like this:
Code:
echo(get_input("prompt_here: "));
I cant seem to figure out how to do this. I was thinking that I could use a method with these steps:
1.) find the first command or keyword
2.) if its a command look for any parse the inputs
3.) if its a keyword parse accordingly
Now this would technically work but I cant figure out how to parse the inputs. I was thinking that I would have a parse function, then when a command parses the inputs I uses the parse function to figure out get the value of everything inside. Now this works because when a command calls the parse function the parse function calls the next command inside of its inputs. But this turns out to be pretty slow. So basically what I'm asking is, does anyone know of a better way to parse a string of nested commands? I'm really stumped here so any help would be greatly appreciated.
Thanks in advance,
Spud2451