betacentauri has asked for the wisdom of the Perl Monks concerning the following question:
O Monks,
I need to parse some text expressions which are a lot like the arithmetic expressions consisting of +, * and constants, so being able to parse arithmetic expressions would be more than enough. What I need is a syntax tree, where every leaf node is a constant, and the interior nodes are "+" and "*" tokens.
Using Tree::Parser seemed like a good deal to me because I need to do some tree traversal after parsing, and the Tree::Simple object returned by Tree::Parser seems to provide suitable methods.
However, the useNestedParensFilter() filter coming with the module is not quite what I need. I'm lost at how to write a proper parser to be given to setParseFilter(), as the iterator->next() function seems to break lexical units only on parentheses or whitespace, while I need to detect "+" and "*" tokens alone as well.
Can someone explain how to build a syntax tree for {+,*,A..Z,(,)} with Tree::Parser?
TIA
Back to
Seekers of Perl Wisdom