CSE 428

Midterm 1 Solution

  1. E ::= E "+" F | E "-" F | F
    F ::= F "*" F | G
    G ::= "-"G | H
    H ::= N | Id | "(" E ")"
    a) x * (y--5) : unambiguous
    b) +x * y : cannot be generated
    c) x * y + z * v : unambiguous
    d) (x + z) * -u * (v) : ambiguous
    e) -(-(x + y)) : unambiguous


  2.  senv[f:t1->t2][g:t3->t4][x:t1] |- Ef:t2
     senv[f:t1->t2][g:t3->t4][y:t3] |- Eg:t4    senv[f:t1->t2][g:t3->t4] |- e:t
    ----------------------------------------------------------------------------
                  let f(x:t1):t2 = Ef;  g(y:t3):t4 = Eg in e : t


  3. a) bool
    b) no type
    c) int
    d) bool


  4. a) 0 7 1 43
    b) 0 7 0 7
    c) 43 7 43 7
    d) 43 7 1 43


  5. a) procedures can only reference their parameters and local variables: yes
    b) dynamic typig: no
    c) static scoping: no
    d) only call-by-value parameter passing: no
    e) no recursive functions: yes
    f) no nested procedure declarations: yes
    g) static typing: no
    h) no overloading of procedure names: no
    i) dynamic scoping: yes
    j) recursive procedure names: yes