User Tools

Site Tools


cs330_f2016:labpaint

Differences

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

Link to this comparison view

Next revision
Previous revision
cs330_f2016:labpaint [2016/10/04 23:28]
wingated created
cs330_f2016:labpaint [2021/06/30 23:42] (current)
Line 6: Line 6:
 ====Pre-requisite:​==== ====Pre-requisite:​====
  
-For this lab, you should have Julia 0.4+ installed, the same as for the rudimentary interpreter. ​ You will need both the Lexer and Error modules, and you will need your code from the Extended Interpreter.+For this lab, you should ​again have Julia 1.installed, the same as for the rudimentary interpreter. ​ You will need both the Lexer and Error modules, and you will need your code from the Extended Interpreter.
  
 ---- ----
 ====Deliverable:​==== ====Deliverable:​====
  
-For this lab, you will expand the interpreter that you have already built, and add in a new "​analysis"​ function that performs three different flavors of syntactic ​desugaring.+For this lab, you will expand the interpreter that you have already built, and add in a new "​analysis"​ function that performs three different flavors of syntactic ​de-sugaring.
  
 The primary deliverable for this lab is a new Julia module. ​ Your module should export ''​parse'',​ ''​calc''​ **and ''​analyze''​** functions, and two return types, ''​NumVal''​ and ''​ClosureVal''​. The primary deliverable for this lab is a new Julia module. ​ Your module should export ''​parse'',​ ''​calc''​ **and ''​analyze''​** functions, and two return types, ''​NumVal''​ and ''​ClosureVal''​.
  
-Your module should be able to do everything that your simple interpreter could do and everything that your extended interpreter can do.  However, you will use program analysis to both eliminate ''​With''​ nodes, and to add two new simple ​fe+Your module should be able to do everything that your simple interpreter could do and everything that your extended interpreter can do.  However, you will use program analysis to both eliminate ''​With''​ nodes, and to add two new simple ​features.
  
-The ''​CI7.jl''​ module is available ​on LearningSuite,​ under "Content ​-> Julia -> Program analysis"​.+The ''​CI4.jl''​ module is available ​in the Content ​section in Learning Suite.
  
 Please name your module TransInt. Please name your module TransInt.
Line 33: Line 33:
  
 Each is discussed in more detail in the following sections. Each is discussed in more detail in the following sections.
 +
 +Note that we do not expect you to nor want you to implement short-circuiting of if0 nodes or pre-calculation of arithmetic expressions. Only do the syntactic de-sugaring as described here.
  
 The grammar for our new language is the following: The grammar for our new language is the following:
  
 <code BNF> <code BNF>
-<OWL> ::= number +<AE> ::= number 
-          | (+ <OWL> <OWL> <OWL>​*) ​  # at least two parameters, possibly infinity. ​ note extra star! +          | (+ <AE> <AE> <AE>​*) ​  # at least two parameters, possibly infinity. ​ note extra star! 
-          | (- <OWL> <OWL>) +          | (- <AE> <AE>) 
-          | (* <OWL> <OWL>) +          | (* <AE> <AE>) 
-          | (/ <OWL> <OWL>) +          | (/ <AE> <AE>) 
-          | (mod <OWL> <OWL>) +          | (mod <AE> <AE>) 
-          | (collatz <OWL>) +          | (collatz <AE>) 
-          | (- <OWL>)      ​+          | (- <AE>)      ​
           | id           | id
-          | (if0 <OWL> <OWL> <OWL>) +          | (if0 <AE> <AE> <AE>) 
-          | (with ( (id <OWL>)* ) <OWL>) +          | (with ( (id <AE>)* ) <AE>) 
-          | (lambda (id*) <OWL>) +          | (lambda (id*) <AE>) 
-          | (and <OWL> <OWL> <OWL>​*) ​ # new operation '​and'​ +          | (and <AE> <AE> <AE>​*) ​ # new operation '​and'​ 
-          | (<OWL> <OWL>​*) ​        +          | (<AE> <AE>​*) ​        
 </​code>​ </​code>​
  
Line 60: Line 62:
 **Part 1: Multi-site ''​with''​ -> multi-site ''​lambda''​** **Part 1: Multi-site ''​with''​ -> multi-site ''​lambda''​**
  
-In class we showed how to implement ''​with'' ​statements ​using ''​lambda''​ expressions,​ but only for ''​with''​ and ''​lambda''​ expressions that involve one parameter. ​ For the first part of the lab, you must rewrite the AST of a program to eliminate all ''​with''​ nodes, even with multiple parameters, and replace them with equivalent function creation / function calls.+In class we showed how to implement ''​with'' ​expressions ​using ''​lambda''​ expressions,​ but only for ''​with''​ and ''​lambda''​ expressions that involve one parameter. ​ For the first part of the lab, you must rewrite the AST of a program to eliminate all ''​with''​ nodes, even with multiple parameters, and replace them with equivalent function creation / function calls.
  
 Remember from class that Remember from class that
  
 <code lisp> <code lisp>
-(with x 5 (+ x 1))+(with (x 5(+ x 1))
 </​code>​ </​code>​
  
Line 74: Line 76:
 </​code>​ </​code>​
  
-No changes to the grammar are necessary to support this change, and therefore, no changes to your parser are necessary.+Your code should make a similar transformation for multiple-identifier ''​with''​ expressions to applying multiple-parameter ''​lambda''​ expressions. For example, 
 + 
 +<code lisp> 
 +(with ((x 5) (y 6)) (+ x y)) 
 +</​code>​ 
 + 
 +becomes 
 + 
 +<code lisp> 
 +((lambda (x y) (+ x y)) 5 6) 
 +</​code>​ 
 + 
 +No changes to the grammar are necessary to support this change, and therefore, no changes to your parser ​from the Extended Interpreter ​are necessary ​to implement this under-the-hood syntactic rewrite. **The transformation should happen in the ''​analyze''​ function.**
  
 **Part 2: Addition operation with arbitrary number of parameters** **Part 2: Addition operation with arbitrary number of parameters**
Line 96: Line 110:
 </​code>​ </​code>​
  
-Note that this involves a change to the grammar, and therefore you will need to change your parser! ​ You may need to change the definition of the plus node -- it can no longer by implemented as a BinOp.+Note that this involves a change to the grammar, and therefore you will need to change your parser! ​ You may need to change the definition of the plus node -- it can no longer by implemented as a BinOp.  The ''​analyze''​ function should eventually convert it to a sequence of BinOp operations only, and your ''​calc''​ function should handle this without change.
  
 **Part 3: A simple ''​and''​ operator** **Part 3: A simple ''​and''​ operator**
  
-For the final part of this lab you will implement a simple ''​and''​ operation in terms of ''​if0''​ calls. ​ The semantis ​of the ''​and''​ node is that it should return 1 iff all subexpressions evaluate to nonzero, and return 0 otherwise. ​ Or in other words, it should return 0 if any subexpression evaluates to zero.+For the final part of this lab you will implement a simple ​short-circuited ​''​and''​ operation in terms of ''​if0''​ calls. ​ The semantics ​of the ''​and''​ node is that it should return 1 iff all subexpressions evaluate to nonzero, and return 0 otherwise. ​ Or in other words, it should return 0 if any subexpression evaluates to zero.
  
 As an example, we will transform this: As an example, we will transform this:
Line 120: Line 134:
 </​code>​ </​code>​
  
-Note that this is a new construct in our grammar, so you will need to create a new AST node type (call it ''​And''​) and parse it appropriately. ​ However, because it is being implemented in terms of ''​if0''​ calls, you will not need to modify your ''​calc''​ function to support it. +Note that this is a new construct in our grammar, so you will need to create a new AST node type (call it ''​And''​) and parse it appropriately. ​ However, because it is being implemented in terms of ''​if0''​ calls, you will not need to modify your ''​calc''​ function to support it. The transformation from the ''​And''​ node to the ''​if0''​ nodes should happen in the ''​analyze''​ function.
- +
cs330_f2016/labpaint.1475623732.txt.gz · Last modified: 2021/06/30 23:40 (external edit)