I am writing a simple imperative program. The user types in a friendly command like:
Show me image happyface.jpg
and the parser translates that into the correct python code.
I can't really tell if PyParsing is the right tool. It doesn't appear to be, yet lex and yacc are mentioned in the documentation, along with Steven Metsker's book 'Building Parsers with Java', which uses classes that could handle this task.
I am able to create a grammar, I'm not sure what I'm supposed to do with the my lists of tokens.
Depending on what you mean by "simple", I think pyparsing should work fine.
Have you defined the grammar for your set of friendly commands your program will support? I don't mean a pyparsing set of classes, I mean a design, perhaps in EBNF, of the grammar you want to implement. This is really the first step.
For instance, if your grammar is just tokenizing the sentence "show me image blah.jpg" into the individual words, then you're right, the parser hasn't been all that much help. On the other hand, if your parser recognizes that this is a SHOW command, that "image" indicates you want a graphics file, which is the next part of the sentence, then you can execute that section of code related to the SHOW command, using the various tokens and keywords to define what to do, and how.
So I think pyparsing *is* a good tool for this task, but you'll have to provide more info and/or do more design work.
Thanks for the reply. Since posting the message I've spent more time reading the fun manual and discovered the 'setParseAction' method. Now things make sense.
There is a lot of documentation, but not a lot of 'this is how you do it'. I'm not complaining, but I think that is a barrier to the casual parser like myself.
Thank you for creating pyparsing though. It is helping me a lot.
I'm glad you have been able to make more headway in your project. I know the documentation is barely adequate, and I was hoping that the set of example programs would give people some hints on some of the more involved topics. But I know I will have to dig down and generate a bunch of your 'this is how you do it' description.
Good luck with pyparsing!