PLQ #2Done on:   Tuesday, September 28th

Question 1 @ 2021-09-28 19:01

(define (eval sexpr)
  (match sexpr
    [(number: n) n]
    [(list '+ left right) (+ (eval left) (eval right))]
    [(list '- left right) (- (eval left) (eval right))]
    [else (error 'eval "bad syntax in ~s" sexpr)]))

What’s the problem with this function?


Question 2 @ 2021-09-28 19:03

Which of the following BNF grammars are ambiguous?


Question 3 @ 2021-09-28 19:05

<AE>  ::= <AE> + <PROD>
        | <AE> - <PROD>
        | <PROD>

<PROD> ::= <num>
        | <PROD> * <num>
        | <PROD> / <num>

How is a language based on this grammar going to evaluate the expressions?


Question 4 @ 2021-09-28 19:07

What is the reason we’re using BNFs to specify our language(s)?