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?
- It is LtR
- It is RtL
- It can be both
- Order is unrelated
- 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?
- LtR
- RtL
- Whatever the typechecker does when it validates the code
- Whatever Racket does
- 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?
- This is a trick question, since there is a bug in this code
- Unary, because
eval
takes in one argument.
- Binary, because Racket’s
+
is binary
- Binary, because of the AE BNF & data type
- Any-arity, because Racket’s
+
can take any number of arguments
- Whatever Racket does