reset password
Author Message
rabbott
Posts: 1649
Posted 20:51 Nov 15, 2017 |

Project 4 is the longest of the projects. Given our earlier projects, you should be comfortable with most of the code. Here are the aspects of Project 4 I want you to focus on. I'll start at the top level functionally.

 

ArithExprTestsLike all the files, this one is a module. What does it mean for a module to export and import items?

testArithExprs is the top level function. Start your discussion of the code with this function. Although not new, you should be able to explain the first argument of map in the testArithExprs function.

 

ParseState_V1Type: testArithExprs calls evalArith in either ParseState_V1Type or ParseState_V2Type. 

evalArith has the following type.  

evalArith :: String -> (String, Elmt, Int)

What String will be the argument to evalArith? Give an example that includes at least two operators.

The output of evalArith is a triple. Explain the components of the triple. Show their values assuming the argument to evalArith is the string you just gave as an example input. In particular, what is the middle component? What does it represent with respect to the input?

When printed at the terminal the middle component will look like a fully parenthesized expression. How is that middle component represented internally in terms of the types declared in DataDeclarations? Explain why the appearance of that component on the terminal differs from its actual internal structure. This explanation should include a discussion of what it means to declare the type Elmt (and its constructors) and what it means to declare instance Show Elmt.

Having discussed the input and output of evalArith, discuss its body. The body applies three functions in sequence to the input: tokenize, parse, and segment. Given your example input, show, one by one, what the output of these three functions will be. That is, if the input is some String str, show 
 o  what   tokenize str   looks like,
 o  what   parse $ tokenize str   looks like, and
 o  what   segment $ parse $ tokenize str   looks like.

The two key functions are tokenize and parse. Let's talk about them next.

 

Tokenizer: The function tokenize applies addSpaces, words, and map makeToken to its input. For your given input, show what the intermediate outputs of these functions are.

Explain how makeToken works. In particular, explain what M is, what M.lookup does, and what it means that M.lookup returns something of the type Maybe Elmt.

 

ParseStateClass: The function parse is defined as part of the ParseState class. parse is the most important function in the system. (Why do I say that?) Explain its input, [Elmt], and output, parseState, in terms of the example input used above. Since the ParseState class does not define an implementation of a ParseState, when you describe the output of the parse function represent a ParseState as a triple (left, window, right), which is the notional structure of a ParseState.

The parse function is primarily a loop. Explain the function continueParse, which is used to determine whether the loop should end or continue. What is the condition for the parse loop to terminate? Is that the correct condition? Why?

The last line of ParseStateClass lets you set a variable shouldTrace to either True or False. When set to True, what trace output is displayed at the terminal? Using your example input, explain the steps from the start of the parse to the end.

Use an input with a syntax error and trace the parse steps it generates.

The trace shows a printed representation the ParseState. Explain what is actually in the ParseState, i.e., in terms of Elmts. When discussing the ParseState explain it in terms of the (left, window, right) conceptualization, not in terms of a particular implementation.

The parse function uses parseAStep and applyARule to take one parse step. Explain what these two functions do and what it means to take a parse step.

Explain how parseAStep recognizes and labels a failed parse. (Use the current version of the code.) Explain why every failed parse results in the same parseState pattern. Explain why continueParse need look for only one pattern to terminate the parse loop--whether the parse succeeds or fails.

 

ParseState_V1Type: Until now we have talked about the ParseState abstractly. Now discuss the ParseState_V1 implementation of a ParseState. How does the implementation satisfy the requirements of the ParseState class?

 

Ideally, you should be able to discuss this information as if you were presenting it to a class, i.e., without my prompting you.

Last edited by rabbott at 19:03 Nov 16, 2017.