Minimizing parentheses in a postfix->infix converter output

acmfiu@fiu.edu (ACMFIU)
Sat, 13 Apr 91 01:21:31 EDT

          From comp.compilers

Related articles
Minimizing parentheses in a postfix->infix converter output acmfiu@fiu.edu (1991-04-13)
Re: Minimizing parentheses in a postfix->infix converter output ressler@cs.cornell.edu (1991-04-14)
Re: Minimizing parentheses in a postfix->infix converter output firth@sei.cmu.edu (1991-04-14)
Re: Minimizing parentheses in a postfix->infix converter output ge@dbf.kun.nl (1991-04-15)
| List of all articles for this month |
Newsgroups: comp.compilers
From: acmfiu@fiu.edu (ACMFIU)
Keywords: design
Organization: Compilers Central
Date: Sat, 13 Apr 91 01:21:31 EDT

I have a postfix->infix converter and need to output the least number of
parentheses as possible. The resulting infix expression is kept in a
binary tree and I just traverse the tree outputting the left/right
parentheses at each level. This was done for convenience. but now I'd
like to make it better. As this will involve, to my knowledge, some
lookahead to test the next operator, I don't see the binary tree as the
best data structure. What can I use to make the lookahead "not hard" and
how would I go about doing what I want?


albert chin
[It is my recollection that there is an easy way to do paren minimization,
but the details escape me. Roughly, at each level you build the expression
string, and wrap a subexpression in parens if its operator binds looser
than the one in the current expression. -John]
--


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.