关键词 > CSCI4430/6430

CSCI 4430/6430 Programming Languages Fall 2023 Programming Assignment #1

发布时间:2023-09-26

Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: daixieit

CSCI 4430/6430 Programming Languages

Fall 2023

Programming Assignment #1

Due Date: 7:00 PM September 25 (Monday)

This a signment is to be done either individualy or in pairs. Do not show your code to any other group and do not look at any other group's code. Do not put your code in a public directory or otherwise make it public. However, you may get help from the mentors, TAs, or the instructor. You are encouraged to use the LMS Discusion Forum to post problems so that other students can also answer/see the answers.

Lambda Calculus Interpreter

The goal of this assignment is to write a lambda calculus interpreter in a functional programming language to reduce lambda calculus expressions in a call-by-name (normal order) manner.

You are to use the following grammar for the lambda calculus:

<expression> ::= <atom>

|    "\" <atom> "." <expression>

|    "(" <expression> " " <expression> ")"

Your interpreter is expected to take each lambda calculus expression and repeatedly perform beta reduction until no longer possible. It must then perform eta reduction until no longer possible.

In the above grammar, <atom> is deined as a lower case letter followed by a sequence of zero or more alphanumeric characters, excluding Oz language keywords. A full listing of Oz language

keywords can be found at the top of the PA1Helper ile. Your interpreter is to take lambda

calculus expressions from a text ile (one expression per line) and reduce them sequentially. To   enable you to focus on the lambda calculus semantics, a parser is available for both Haskell and Oz, along with supporting code to handle input and output.

Your program must accept two command line arguments. The irst argument is the name of a

ile containing a list of lambda calculus expressions. The second argument is the name of the ile you will write your reduced lambda calculus expressions into.

Your parser should write out the reduced expressions to a ile, again one per line. If something

goes wrong and you cannot reduce an expression, you should write a single new line and then

continue with the next lambda calculus expression. Writing more than one line, or writing nothing at all, will interfere with autograding. Do not write anything else, such as debug printouts, test numbers, etc.

You may (and should!) deine auxiliary procedures for alpha-renaming, beta-reduction, and eta- conversion. For beta reduction, you may want to write an auxiliary procedure that substitutes all  occurrences of a variable in an expression for another expression. Be sure that the replacing

expression does not include free variables that would become captured in the substitution.

Remember that in call-by-name, the argument to a function is not evaluated before the function is called.

You may choose whatever names you wish when alpha-renaming, as long as they do not violate the deinition of <atom>. Your code will be judged correct if we could make your solution match our solution by renaming zero or more of your variable names.

Sample Interpretations

Below are some lambda calculus interpretation test cases:

For your convenience, these have been given in a sample input ile, where each line contains one lambda expression.

Notes for Oz Programmers

You should remove any other Oz installations and use Mozart 2. You can download the binaries from the project's GitHub repository.

Note for Windows users: the interactive Oz editor may fail to launch if you install Mozart on a path containing spaces. It may also fail to launch due to problems with your environment

(causing Mozart to be unable to ind its bundled copy of Emacs). If you are having problems, please post about it on LMS or come to office hours for help.

A parser is provided. Use this starter code and this provided main ile. main.oz receives    command line arguments and invokes PA1Helper's RunProgram procedure, which handles

reading the input and writing output. You will need to implement the ReduceExp method. The

program will write reduced expressions to the output ile and print out both the original and

reduced expressions to stdout. Only the lines written to the ile will be considered when grading.

Sample Interaction

$ cat sample.lambda

(\x.x y)

(\x.\y.(x y) (y w))

$ ozc -c parser.oz

$ ozc -c PA1Helper.oz

$ ozc -c main.oz

$ ozengine main.ozf sample.lambda output.lambda

$ cat output.lambda

y

(y w)

Notes for Haskell Programmers

Use this parser to get a list of lambda calculus expressions from an input ile. See also the

sample main.hs ile (in particular, see the runProgram function.) Speciically, type constructors for the Lexp datatype have been exported from the module. This datatype is used to represent

lambda calculus expressions in Haskell, and the type constructors should be used to pattern

match a lambda expression. Your goal is to create a reducer function that takes an Lexp value as input and returns a Lexp value as output.

The provided helper code will both write to stdout and to the output ile. The former is inteded to help you during the development process. Only the lines written to the ile will matter when the

assignment is graded.

Note: Please name your main ile 'main.hs'. It should accept two arguments when compiled and executed. The provided main.hs has this functionality provided.

Sample Interaction

$ cat sample.lambda

x(x) .(.) y) (y w))

$ runghc main.hs sample.lambda output.lambda

$ cat output.lambda

y

(y w)

If you get an error about Text.Parsec being undeined, run stack install parsec (or cabal install parsec)

Further Haskell Hints: It may be useful to consider Map and Set, which can be found in the

Data.Map and Data.Set modules, respectively. It is also recommended to use Hoogle, a search engine for looking up Haskell documentation.

Grading: The assignment will be graded mostly on correctness, but code clarity / readability will also be a factor. If something is unclear, explain it with comments!

Correctness is judged by testing if your lambda calculus expressions are alpha-equivalent to the expected expressions. Therefore, your choice of names when performing alpha renaming will not afect correctness, as long as your chosen names are valid (i.e. lowercase alphanumeric strings   that start with a letter and are not Oz keywords).

Submission Requirements: Please submit a ZIP ile with your code, including a README ile.

Your ZIP ile should be named with your LMS user name(s) as the ilename underscore the

language you chose. Examples: userid1_oz.zip, userid1_userid2_hs.zip, userid1_lisp.zip. Only

submit one assignment per pair via LMS. In the README ile, place the names of each group

member (up to two). Your README ile should also have a list of speciic features/bugs in your solution.