I'm working on my compiler homework and I have the following question:
Consider the following grammar:
lexp -> number : (op lexp-seq)
op -> + | - | *
lexp-seq -> lexp-seq lexp | lexp
This grammar can be thought of as representing simple integer arithmetic expressions in LISP=like prefix form. For example the expression 34-3*42 would be written (- 34 (* 3 42)).
What interpretation should be given to the legal expressions (- 2 3 4) and (- 2)? What about the expression (+ 2) and ( 2)?*
Now, I'm not really sure what they mean by "What should the intrepretation be". For example, do they want a derivation?
The first one seems like it would be simple enough:
(- 2 3 4)
(- 1 4)
(- 3)
And the unary (- 2) and (+ 2) I suppose would be interpreted as negative and explicit positive?
I have no clue what (* 2) would be interpreted as?
The derivation works and is easy enough:
lexp -> (op lexp-seq)
-> (* lexp-seq)
-> (* lexp)
-> (* number)
But is this all they are asking for? Or is it asking how I would interpret what (* 2) means semantically?
Please help me decipher my ambiguous homework problem!