I this perl one liner for evaluating infix expressions in VI and emacs/VI
emulator mode:
.! perl -MPOSIX -pe ' BEGIN{ $np = qr{ \( (?: (?> [^()]+ ) | (??{ $np }) )*
\) }x;$funpat = qr/$np/;}
s/($funpat)=($funpat|(")[^\"]*(")|[0-9\.]+)/"$1=$3".eval($1)."$4"/ge'
That $np is from the camel book and it is a regular expression that parses
nested sets of parentheses and then my replace command evaluates the arithmetic
expression.
Since perl accommodates recursive regular expressions, it ought to be possible
to implement a recursive decent parser.
Can someone help me enhance the above code so that instead of just blindly
looking for balanced parenthesis, the regular expression will recognize (match)
this:
5+8*(2+8/(3+2))*(2+22/3)=()Thankssiegfried