User Tools

Site Tools


cs330_f2016:lab16

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
cs330_f2016:lab16 [2016/11/26 17:53]
morse
cs330_f2016:lab16 [2021/06/30 23:42] (current)
Line 1: Line 1:
-** This is a draft version of the assignment. Do not start on it until this line is removed. ** 
  
 ====Objective:​==== ====Objective:​====
Line 8: Line 7:
 ====Deliverable:​==== ====Deliverable:​====
  
-Implement the CITypes interpreter using the provided shell.+Implement the CITypes interpreter using [[http://​liftothers.org/​dokuwiki/​doku.php?​id=cs330_f2016:​lab16shell|the provided shell]].
  
 === Language Overview === === Language Overview ===
  
-The CITypes language is based on the CI5 language, just like your Extended Interpreter.+The CITypes language is based on the CI3 language, just like your Extended Interpreter.
 ** You do not need to add any functionality from your previous assignments. ** ** You do not need to add any functionality from your previous assignments. **
  
 To make the type system more interesting,​ the CITypes language adds booleans and numeric lists. To make the type system more interesting,​ the CITypes language adds booleans and numeric lists.
-The "​if0"​ function is replaced by "​ifb",​ which requires that the conditional return a boolean value (like in Java). ​ 
 A new operator "​iszero"​ is added, which tests to see if a number is zero and returns a boolean result. A new operator "​iszero"​ is added, which tests to see if a number is zero and returns a boolean result.
  
Line 23: Line 21:
   * false   * false
  
-The language also requires that the types of formal parameters be specified with the function is declared: <​code>​(lambda <id> : <​type>​ <​expr>​)</​code>​. ​  +The "​if0"​ function is replaced by "​ifb",​ which requires that the conditional return a boolean value (like in Java).  
-For example, a simple numeric increment function would be written as <​code>​(lambda x : number (+ x 1)</​code>​.+So that the language can be statically type checked, both branches of "​ifb"​ must return the same type. 
 + 
 +The language also requires that the types of formal parameters be specified with the function is declared: ​ 
 +<​code ​lisp> 
 +  ​(lambda <id> : <​type>​ <​expr>​) 
 +</​code> ​ 
 +To support this, the language'​s grammar also includes a new nonterminal "<​type>",​ which can be "​number",​ "​boolean",​ "​nlist",​ or a function type signature of the form "​(<​type>​ : <​type>​)"​.  ​ 
 + 
 +For example, a simple numeric increment function would be written as  
 +<​code ​lisp> 
 +  ​(lambda x : number (+ x 1)
 +</​code>​ 
 +and a function lambda that takes as input a function f from numbers to numbers would look like this: 
 +<code lisp> 
 +  (lambda f : (number : number) (f 3)) 
 +</​code>​
  
 There are five new types of expressions for handling numeric lists: There are five new types of expressions for handling numeric lists:
Line 36: Line 49:
  
 Here is the grammar for the CITypes language: Here is the grammar for the CITypes language:
-<​code>​+<​code ​bnf>
 <​expr>​ ::= <​number>​ <​expr>​ ::= <​number>​
          | true          | true
Line 50: Line 63:
          | nempty          | nempty
          | (ncons <​expr>​ <​expr>​)          | (ncons <​expr>​ <​expr>​)
-         | (nempty ​<​expr>​)+         | (nisempty ​<​expr>​)
          | (nfirst <​expr>​)          | (nfirst <​expr>​)
          | (nrest <​expr>​)          | (nrest <​expr>​)
Line 81: Line 94:
 ** The type checker should perform no evaluation of the code, only type checking. ** ** The type checker should perform no evaluation of the code, only type checking. **
  
-Some of the tests will involve comparing two types, and a "​same_types"​ function is provided ​to do a recursive comparison.+In class, we went over [[lab16judgments | the type judgments for the expressions other than those that work with lists]].  
 +You will need to determine them for the five list-handling expressions yourself.
  
 +Some of the tests will involve comparing two types, and a "​same_types"​ function is provided to do a (recursive if necessary) comparison.
  
- +When your type checker catches an error, it should throw an exception with a descriptive error message.
  
 +----
 ====Hints:​==== ====Hints:​====
 +
 +  * The "​calcf"​ function in the CI3 interpreter that read in a test file, ran it through lex / parse / calc has been replaced with a "​typef"​ function that similarly reads in a test file and runs it through lex / parse / type_of_expression. ​ You can use it to run your own test cases.
 +  * Make sure you test not only for validly typed expressions but for each kind of type error.
cs330_f2016/lab16.1480182810.txt.gz · Last modified: 2021/06/30 23:40 (external edit)