PLQ #2Done on:   Tuesday, February 2nd

Question 1 @ 2021-02-02 19:11

The AE BNF is:

<AE> ::= <num>
      | { + <AE> <AE> }
      | { - <AE> <AE> }
      | { * <AE> <AE> }
      | { / <AE> <AE> }

Is this for a language that evaluates expressions left-to-right or right-to-left?

  1. It is LtR
  2. It is RtL
  3. It can be both
  4. Order is unrelated
  5. Depends on the calling compiler

Question 2 @ 2021-02-02 19:25

Reminder: this is the code that we wrote last class to evaluate AE expressions:

(define (eval expr)
  (cases expr
    [(Num n)  n]
    [(Add l r) (+ (eval l) (eval r))]
    [(Sub l r) (- (eval l) (eval r))]
    [(Mul l r) (* (eval l) (eval r))]
    [(Div l r) (/ (eval l) (eval r))]))

Does this implement addition from left-to-right or right-to-left?

  1. LtR
  2. RtL
  3. Whatever the typechecker does when it validates the code
  4. Whatever Racket does
  5. Whatever is easier to compile

Question 3 @ 2021-02-02 19:37

Reminder: this is the code that we wrote last class to evaluate AE expressions:

(define (eval expr)
  (cases expr
    [(Num n)  n]
    [(Add l r) (+ (eval l) (eval r))]
    [(Sub l r) (- (eval l) (eval r))]
    [(Mul l r) (* (eval l) (eval r))]
    [(Div l r) (/ (eval l) (eval r))]))

What kind of addition arity does this implment?

  1. This is a trick question, since there is a bug in this code
  2. Unary, because eval takes in one argument.
  3. Binary, because Racket’s + is binary
  4. Binary, because of the AE BNF & data type
  5. Any-arity, because Racket’s + can take any number of arguments
  6. Whatever Racket does