Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Define the abstract syntax of MiniLogo commands by defining a new Haskell data type Cmd. I have provided several more types and type synonyms that

image text in transcribedimage text in transcribed

  1. Define the abstract syntax of MiniLogo commands by defining a new Haskell data type Cmd. I have provided several more types and type synonyms that you should use in these definitions. Note that you do not need to define a separate synonym for cmds since cmds and block are equivalent in the abstract syntax, and cmds only appears in the grammar as part of block.

  2. Define the undefined ASTs of type Block corresponding to the bodies of the two macros in the final example from the language description (the program containing the for loop).

    The doctests show the concrete syntax of these blocks, but you wont be able to pass the doctests until completing the next task.

  3. Define a pretty printer for MiniLogo commands by implementing the function prettyCmd. As before, you should try to make your output match the concte syntax used in the doctests and on the language description page exactly. You may want to add your own doctests while developing prettyCmd. I omitted my doctests from the template since your constructor names will likely be different from mine. The doctests from the previous tasks will serve to evaluate your pretty printer, but it might be helpful to have smaller test cases too.

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) ** Pretty printer Some functions that might be useful for you: concat :: [[a]] -> [a] Concatenates a list of lists into a single list. Useful for concatenating a list of strings into a single string. Imported from the Prelude. intercalate :: [a] -> [[a]] -> [a] Insert a list between every list in a list of lists, then concatenate the results. Useful for inserting separators between every string in a list of strings, then concatenating the whole thing into one string. Imported from Data.List. | Pretty print the pen mode. >>> prettyMode Down "down" >>> prettyMode Up "up" prettyMode :: Mode -> String prettyMode Down = "down" prettyMode Up "up" 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) ** Pretty printer Some functions that might be useful for you: concat :: [[a]] -> [a] Concatenates a list of lists into a single list. Useful for concatenating a list of strings into a single string. Imported from the Prelude. intercalate :: [a] -> [[a]] -> [a] Insert a list between every list in a list of lists, then concatenate the results. Useful for inserting separators between every string in a list of strings, then concatenating the whole thing into one string. Imported from Data.List. | Pretty print the pen mode. >>> prettyMode Down "down" >>> prettyMode Up "up" prettyMode :: Mode -> String prettyMode Down = "down" prettyMode Up "up

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_2

Step: 3

blur-text-image_3

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

Database Processing Fundamentals, Design, and Implementation

Authors: David M. Kroenke, David J. Auer

14th edition

133876705, 9781292107639, 1292107634, 978-0133876703

More Books

Students also viewed these Databases questions