Question: Define a pretty printer for MiniLogo expressions by implementing the function prettyExpr. You should try to make your output match the concrete syntax used in


-
Define a pretty printer for MiniLogo expressions by implementing the function prettyExpr. You should try to make your output match the concrete syntax used in the doctests and on the language description page exactly. The doctests assume that you print parentheses only when strictly necessary. You should try to do this but since its a bit tricky you wont be marked down as long as the concrete syntax that you generate is correct. For example, if you print (2 + (3 * x)) instead of 2 + 3 * x, thats OK. However, if you print 2 + 3 * x when it should be (2 + 3) * x, that is an error. The upshot of this is that if you cant get it just right, err on the side of including more parentheses. :-)
module HW3 where import Data.List (intercalate) Part 1: Expressions Syntax | Variable names. type Var = String | Expressions. data Expr ExprTODO -- This is a dummy constructor that should be removed! deriving (Eq, Show) -- ** Pretty printer | Pretty print an expression. >>> prettyExpr expri "2 + 3 * x" >>> prettyExpr expr2 "2 + 3 * x + 4" >>> prettyExpr expr3 "(x + 2) * 3 * y" >>> prettyExpr expr4 "(x + 2) * (y + 3)" prettyExpr :: Expr -> String prettyExpr = undefined module HW3 where import Data.List (intercalate) Part 1: Expressions Syntax | Variable names. type Var = String | Expressions. data Expr ExprTODO -- This is a dummy constructor that should be removed! deriving (Eq, Show) -- ** Pretty printer | Pretty print an expression. >>> prettyExpr expri "2 + 3 * x" >>> prettyExpr expr2 "2 + 3 * x + 4" >>> prettyExpr expr3 "(x + 2) * 3 * y" >>> prettyExpr expr4 "(x + 2) * (y + 3)" prettyExpr :: Expr -> String prettyExpr = undefined
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
