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
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Parsing syntax trees
by GrandFather (Saint) on Dec 30, 2015 at 07:16 UTC | |
Re: Parsing syntax trees
by GrandFather (Saint) on Dec 30, 2015 at 08:31 UTC | |
Re: Parsing syntax trees
by GrandFather (Saint) on Dec 30, 2015 at 03:54 UTC | |
by betacentauri (Sexton) on Dec 30, 2015 at 13:01 UTC | |
by GrandFather (Saint) on Dec 30, 2015 at 22:21 UTC | |
Re: Parsing syntax trees
by Anonymous Monk on Dec 30, 2015 at 04:00 UTC |
Back to
Seekers of Perl Wisdom