Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

image text in transcribedimage text in transcribed

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

image text in transcribed

* 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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Essentials of Database Management

Authors: Jeffrey A. Hoffer, Heikki Topi, Ramesh Venkataraman

1st edition

133405680, 9780133547702 , 978-0133405682

More Books

Students also viewed these Databases questions

Question

Explain the topology and media access control of Bluetooth.

Answered: 1 week ago

Question

Which of the following is NOT a relational operator? 1. =

Answered: 1 week ago