POV-Ray : Newsgroups : povray.off-topic : The trick : The trick Server Time
6 Sep 2024 01:24:08 EDT (-0400)
  The trick  
From: Invisible
Date: 12 Mar 2009 10:22:15
Message: <49b91a97$1@news.povray.org>
OK, so does anybody know the trick to taking a parse tree such as

   (2*(5^2))+((8*6)^(x-1)))

and printing it out *without* several billion brackets?

Printing it with brackets as above, or with no brackets at all, is quite 
trivial:

   output expr = case expr of
     Operator n x y = "(" ++ output x ++ n ++ output y ++ ")"
     Variable n     = n
     Constant v     = show v
     ...

But how do you "decide" when the brackets can or can't be omitted?


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.