1. Homepage
  2. Programming
  3. CS321: Programming Languages - Homework 2: Functions, Errors, Conditionals, Predicate and Multiplication

CS321: Programming Languages - Homework 2: Functions, Errors, Conditionals, Predicate and Multiplication

Engage in a Conversation
NorthwesternCS321COMPSCI321Programming LanguagesRacketFunctionsConditionals

CS 321: Programming Languages — Homework 2 CourseNana.COM

1 Functions with Multiple Arguments (with Deferred Substitutions) CourseNana.COM

Start with the f1WAE interpreter for deferred substitution, and extend the implementation to support any number of arguments to a function (including zero), and any number of arguments (including zero) in a function application: CourseNana.COM

<FunDef> = {deffun {<id> <id>*} <fnWAE>}
<fnWAE> = <num>
        | {+ <fnWAE> <fnWAE>}
        | {- <fnWAE> <fnWAE>}
        | {with {<id> <fnWAE>} <fnWAE>}
        | <id>
        | {<id> <fnWAE>*}

As with homework 1, you must change the f1WAE datatype, and you must thus provide a parse func- tion that produces values of your modified f1WAE datatype. It must accept a quoted expression and pro- duce an fnWAE value. Similarly, you must provide a parse-defn function to parse definitions. CourseNana.COM

See homework 1 for details on these functions.
You must also provide an
interp-expr function with signature: CourseNana.COM

fnWAE (listof FunDef) -> Number
This function should be a very simple wrapper for your interp function, which our tests will call on the CourseNana.COM

results of your parsers. If yours is more than a few lines (one line is possible), you may be overthinking it. CourseNana.COM

2 Errors CourseNana.COM

Your interpreter and parser must obey the formats and precedence rules described in homework 1. Otherwise, assume that the input to your parser is a well-formed program. CourseNana.COM

3 Conditionals CourseNana.COM

Add if0, a conditional expression. It has three subexpressions: <fnWAE> = ... CourseNana.COM

        | {if0 <fnWAE> <fnWAE> <fnWAE>}

Evaluating an if0 expression evaluates the first subexpression; if it produces 0, then the result of the entire expression is the result of the second subexpression. Otherwise, the result is the result of the third subexpression. CourseNana.COM

Examples: CourseNana.COM

  (test (interp-expr (parse '{if0 0 1 2}) '()) 1)
  (test (interp-expr (parse '{if0 1 2 3}) '()) 3)

4 Negative predicate CourseNana.COM

Implement, in the fnWAE language (without any extensions, i.e., you cannot add new kinds of expressions to the language or to your interpreter), a predicate neg? that determines if an integer is negative. That is, write a defun like this one that can be passed to your parse function and then used with your interp function (with a suitable <fnWAE> expression that calls it): CourseNana.COM

{deffun {neg? x} ...}

It must return either 0 (if the input is negative), or 1 (if not). The number 0 is not itself considered negative. CourseNana.COM

5 Multiplication on integers CourseNana.COM

As you did in the previous problem, implement (in the fnWAE language without any extensions), a function mult that computes the product of two integers. CourseNana.COM

{deffun {mult x y} ...}

6 Handin instructions CourseNana.COM

Provide definitions for parse, parse-defn, and interp-expr, as above.
Provide a PLAI-level definition of
mult-and-neg-deffuns that is bound to a list of (unparsed) def- CourseNana.COM

funs that contains both neg? and mult as well as any helper functions you need: CourseNana.COM

(define mult-and-neg-deffuns (list `{deffun {neg? x} ...} CourseNana.COM

`{deffun {mult x y} ...}
; other deffuns okay, too, for your helpers )) CourseNana.COM

Do not leave in any unused code (i.e., no subst). Tests for the above functions (or helpers you may use along the way) are fine, though. CourseNana.COM

Have the 8 rules from the Provost’s website (see the homework 0 for more details).
Submit your code via Canvas.
Your submission must include your test cases; submissions without test cases will not get any credit.
CourseNana.COM

7 Grading CourseNana.COM

To receive a grade of on the way (1), your submission must correctly implement multiple argument functions and if0. CourseNana.COM

CourseNana.COM

To receive a grade of got it (3), your submission must in addition correctly implement neg? and mult. Submissions which do not achieve on the way criteria will receive a grade of not yet (0). CourseNana.COM

Get in Touch with Our Experts

WeChat (微信) WeChat (微信)
Whatsapp WhatsApp
Northwestern代写,CS321代写,COMPSCI321代写,Programming Languages代写,Racket代写,Functions代写,Conditionals代写,Northwestern代编,CS321代编,COMPSCI321代编,Programming Languages代编,Racket代编,Functions代编,Conditionals代编,Northwestern代考,CS321代考,COMPSCI321代考,Programming Languages代考,Racket代考,Functions代考,Conditionals代考,Northwesternhelp,CS321help,COMPSCI321help,Programming Languageshelp,Rackethelp,Functionshelp,Conditionalshelp,Northwestern作业代写,CS321作业代写,COMPSCI321作业代写,Programming Languages作业代写,Racket作业代写,Functions作业代写,Conditionals作业代写,Northwestern编程代写,CS321编程代写,COMPSCI321编程代写,Programming Languages编程代写,Racket编程代写,Functions编程代写,Conditionals编程代写,Northwesternprogramming help,CS321programming help,COMPSCI321programming help,Programming Languagesprogramming help,Racketprogramming help,Functionsprogramming help,Conditionalsprogramming help,Northwesternassignment help,CS321assignment help,COMPSCI321assignment help,Programming Languagesassignment help,Racketassignment help,Functionsassignment help,Conditionalsassignment help,Northwesternsolution,CS321solution,COMPSCI321solution,Programming Languagessolution,Racketsolution,Functionssolution,Conditionalssolution,