Question: Complete the definition of the example program. Be sure to reuse your definitions of the macro bodies from Part 2. * Part 3: Programs |


- Complete the definition of the example program. Be sure to reuse your definitions of the macro bodies from Part 2.

* Part 3: Programs | The parameters of a macro are a list of variables that will be bound to the arguments passed to the macro when it is called. type Pars = [Var] | A macro definition. data Def = Define Macro Pars Block deriving (Eq, Show) | A program is a list of macro definitions plus the block of the main macro. data Prog - Program [Def] Block deriving (Eq,Show) | The entire example program. - >>> putStrln (pretty boxes) box(x, y, W, h) { pen up; move(x, y); pen down; move(x + w, y); move(x + W, y + h); move(x, y + h); move(x, y) } main() { for i = 1 to 15 { box(i, i, i, i) } } - - - boxes :: Prog boxes undefined | Pretty print a macro definition. prettyDef :: Def -> String prettyDef (Define m ps b) concat [m, "(", intercalate ps, ") ", prettyBlock b] 11 | Pretty print a program. pretty :: Prog -> String pretty (Program dsb) concat [intercalate " " (map prettyDef ds), " main() ", prettyBlock b] Macro names. type Macro = String | The arguments to be evaluated and passed to a macro. type Args = [Expr] | A sequence of commands. type Block = [Cmd] | The mode of the pen. data Mode = Down | Up deriving (Eq,Show) | Commands. data Cmd CmdTODO -- This is a dummy constructor that should be removed! deriving (Eq,Show) * Part 3: Programs | The parameters of a macro are a list of variables that will be bound to the arguments passed to the macro when it is called. type Pars = [Var] | A macro definition. data Def = Define Macro Pars Block deriving (Eq, Show) | A program is a list of macro definitions plus the block of the main macro. data Prog - Program [Def] Block deriving (Eq,Show) | The entire example program. - >>> putStrln (pretty boxes) box(x, y, W, h) { pen up; move(x, y); pen down; move(x + w, y); move(x + W, y + h); move(x, y + h); move(x, y) } main() { for i = 1 to 15 { box(i, i, i, i) } } - - - boxes :: Prog boxes undefined | Pretty print a macro definition. prettyDef :: Def -> String prettyDef (Define m ps b) concat [m, "(", intercalate ps, ") ", prettyBlock b] 11 | Pretty print a program. pretty :: Prog -> String pretty (Program dsb) concat [intercalate " " (map prettyDef ds), " main() ", prettyBlock b] Macro names. type Macro = String | The arguments to be evaluated and passed to a macro. type Args = [Expr] | A sequence of commands. type Block = [Cmd] | The mode of the pen. data Mode = Down | Up deriving (Eq,Show) | Commands. data Cmd CmdTODO -- This is a dummy constructor that should be removed! deriving (Eq,Show)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
