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:
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
Define a grammar and lexing rules in PLY.
Thanks this will probably work! although I was hoping to write it myself, oh well.
There's also pyparsing, which seems to be a bit less robust but much easier to use.
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 1
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement