in reply to Regex: first match that is not enclosed in parenthesis
I'm using this code in a little project I started out of boredom. Its purpose is to print function graphs on the commandline, like gnuplot can do as well.
At the current point it parses mathematical expressions into a kind of abstract syntax tree and plots them onto the cmdl. I knew that I could have defined a grammar for it and implemented a serious parser and lexer, but I wanted to do it myself first and then see what I could have done better.
So far, the supported expressions included only +-*/ and nested parenthesis. Since I wanted to include more expressions and functions, I figured it would be a pain to deal with operator precedence unless I take on a more general approach of precedence levels.
The initial question is because I want to find the first operator with the lowest precedence and recursively build subtrees from the prefix and postfix terms of the found operator.
The difficult question for me here was how to handle the parenthesis-terms atomically during this operator lookup.
|
|---|