Hello all,
I'm working on coding up a little language model in Redex, and I'd like to get it to render things in the form that my colleagues are used to. This means some infix operators as well as dealing with parenthesizing based on operator precedence.
Here's a boiled-down sample of what I'm up to:
#lang racket
(require redex pict)
(define-language L
(C success (then C C) (or C C)))
(with-compound-rewriters
(['or (match-lambda [(list _ _ x y _) (list "" x " or " y "")])]
['then (match-lambda [(list _ _ x y _) (list "" x " then " y "")])])
(vl-append
20
(render-language L)
(render-term L (then (or success success) success))))
I've attached the result. The resulting rendering of L looks appropriate, but the nesting of then and or in the rendered term does not indicate the nesting. I'd like to be able to specify precedence and associativity and have parentheses inserted appropriately; failing that, a reasonable backup would be parenthesizing sub-expressions that are not atomic.
Can anyone point me at the right resource to use to figure out how to do this?
Thank you!
David