User Tools

Site Tools


cs330_f2016:labw

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
Next revision Both sides next revision
cs330_f2016:labw [2018/02/01 21:07]
morse
cs330_f2016:labw [2018/10/07 05:14]
morse
Line 1: Line 1:
-**This is a draft version of the assignment and may change until the due date of the preceding assignment. 
-** 
- 
 ====Objective:​==== ====Objective:​====
  
Line 9: Line 6:
 ====Pre-requisite:​==== ====Pre-requisite:​====
  
-For this lab, you should have Julia 0.6+ installed, the same as for the rudimentary interpreter. ​ You will need both the Lexer and Error modules.+For this lab, you should have Julia 1.installed, the same as for the rudimentary interpreter. ​ You will need both the Lexer and Error modules.
  
 ---- ----
Line 54: Line 51:
 </​code>​ </​code>​
  
-where ''​number''​ is a Julia Real and ''​id''​ is a Julia Symbol that is not '':​+'',​ '-, '*, '/, 'with, 'if0, 'mod, '​collatz,​ or '​lambda.+where ''​number''​ is a Julia Real and ''​id''​ is a Julia Symbol that is not '':​+'',​ '':-''​, '':*''​, '':/''​, '':with''​, '':if0''​, '':mod''​, '':collatz''​, or '':lambda''​. 
 Here the "​*"​ notation is the Kleene star (zero or more occurrences) you should have seen in CS 236 and/or CS 252. Here the "​*"​ notation is the Kleene star (zero or more occurrences) you should have seen in CS 236 and/or CS 252.
  
-Remember, this grammar is for the quoted S-expressions; ​the lexer will return data structures that put everything between parentheses into an array (removing the parentheses). ​+Remember, this grammar is for the concrete syntax: ​the lexer will return data structures that put everything between parentheses into an array (removing the parentheses). ​
  
 This grammar blends both the grammar for the simple interpreter and the in-class interpreter we have built, but also expands several of the functions. This grammar blends both the grammar for the simple interpreter and the in-class interpreter we have built, but also expands several of the functions.
Line 84: Line 82:
 (lambda x (+ x 1)) (lambda x (+ x 1))
 or or
-(with x 5 (+ x 1))+(with (x 5(+ x 1))
 </​code>​ </​code>​
  
Line 131: Line 129:
 # Abstract syntax # Abstract syntax
  
-abstract type OWL end+abstract type AE end
  
-type NumNode <: OWL+struct ​NumNode <: AE
     n::Real     n::Real
 end end
  
-type BinopNode <: OWL+struct ​BinopNode <: AE
     op::​Function     op::​Function
-    lhs::OWL +    lhs::AE 
-    rhs::OWL+    rhs::AE
 end end
  
-type If0Node <: OWL +struct ​If0Node <: AE 
-  condition::OWL +  condition::AE 
-  zero_branch::​OWL +  zero_branch::​AE 
-  nonzero_branch::​OWL+  nonzero_branch::​AE
 end end
  
-type WithNode <: OWL +struct ​WithNode <: AE 
-  ​name::Symbol +  ​sym::Symbol 
-  binding_expr::​OWL +  binding_expr::​AE 
-  body::OWL+  body::AE
 end end
  
-type IdNode ​<: OWL +struct VarRefNode ​<: AE 
-  ​name::Symbol+  ​sym::Symbol
 end end
  
-type FunDefNode <: OWL +struct ​FunDefNode <: AE 
-    ​formal_parameter::Symbol +  ​formal::Symbol 
-    fun_body::OWL+  fun_body::AE
 end end
  
-type FunAppNode <: OWL +struct ​FunAppNode <: AE 
-    fun_expr::OWL +  fun_expr::AE 
-    arg_expr::OWL+  arg_expr::AE
 end end
- 
-# Rejigger our type hierarchy to better support return values 
- 
-# Define both abstract types before we use them 
  
 abstract type RetVal end abstract type RetVal end
Line 177: Line 171:
 abstract type Environment end abstract type Environment end
  
-type NumVal <: RetVal+struct ​NumVal <: RetVal
   n::Real   n::Real
 end end
  
-type ClosureVal <: RetVal +struct ​ClosureVal <: RetVal 
-    param::Symbol +  ​formal::Symbol 
-    body::OWL +  body::AE 
-    env::​Environment ​ # this is the environment at definition time!+  env::​Environment
 end end
  
-# Definitions for our environment data structures +struct EmptyEnv ​<: Environment
- +
-type mtEnv <: Environment+
 end end
  
-type CEnvironment ​<: Environment +struct ExtendedEnv ​<: Environment 
-  ​name::Symbol +  ​sym::Symbol 
-  ​value::RetVal+  ​val::RetVal
   parent::​Environment   parent::​Environment
 end end
Line 209: Line 201:
  
 <code Julia> <code Julia>
-function parse(expr::​Array{Symbol or Real}+function parse(expr::​Any
-function calc(ast::OWL)+function calc(ast::AE)
 </​code>​ </​code>​
  
Line 217: Line 209:
 **Conditionals:​** **Conditionals:​**
  
-The semantics of (if0 test then else) is: if the test evaluates to zero, then the entire expression evaluates to the result of then, otherwise, it evaluates to else. Evaluation should signal an error for non-numeric test values.+The semantics of (if0 test then else) is as follows: if the test evaluates to zero, then the entire expression evaluates to the result of then expression, otherwise, it evaluates to the result of the else expression. Evaluation should signal an error for non-numeric test values.
  
 **Multi-argument fun** **Multi-argument fun**
cs330_f2016/labw.txt · Last modified: 2021/06/30 23:42 (external edit)