COM S 342 Homework 06

$30.00

Download Details:

  • Name: homework06-wbjhop.zip
  • Type: zip
  • Size: 11.14 KB

Category:

Description

5/5 - (1 vote)
1. [5p]
Look in your answer sheet for “the-lexical-spec”. Please describe in your own
words how the program strings are “chopped up” based on this specification ?
**write it under (define problem-1-answer …) in your answer sheet.
===============================================================================
2. [15p]
Write the grammar specification for the above described language under
(define the-grammar ‘( ….) ) in your answer sheet.
===============================================================================
3. [30p]
Implement the above language.
**find the right place in your answer sheet to inject your code
===============================================================================
4. [20p]
Add at least a new language feature of your own design. Please describe the semantics
of your features, argue why you think they’re useful and provide several test programs
that use these features.
***********IMPORTANT***********
Please write these programs in the hw06-p4-tests-yourlastname.rkt file, separate
from hw06-answer-sheet.rkt
**********
===============================================================================
As you can notice the above version of the language does not have a concept
of an identifier. Consider these new additions to the grammar of the language:
<expr> ::=
           <initial-language>
         | identifier              “iden-expr”
         | { <var-expr>* <expr> *} “block-expr”
<var-expr> ::=
               | val identifier = <expr>         “val”
               | final val identifier = <expr>   “final-val”
We had to make the distinction between <var-expr> and <expr> in order
to be able to write the <block-expr> as is described. To better understand how sllgen
works try writing the grammar without any distinction and see what happens.
Semantic annotations
   – whenever an identifier is encountered, it is evaluated to its bound value.
   – block-expr, can have any number of variable declarations, i.e. <var-expr>
     followed by any number of expressions <expr>. The value returned by the block-expr
     ,just like in racket, is the value of the last statement. ALL previous expressions
     still have to be evaluated.
   – val identifier = <expr>, it will create a variable with the name “identifier” that
     is bound to the value returned by the <expr>
   – final val, similar to val, but the variable’s definition cannot be overridden.
     This is similar to what you implemented in the last homework, exercise 2.b.
   – the return value of a val or final-val var-expr are undefined. i.e. you can
     have them return whatever you wish.
===============================================================================
5. [30p]
Implement the language features that support identifiers.
***Note:
To solve this last part you will have to make use of the environment datatype (already
provided in the hw06-env-values.rkt file). This will require a few changes to the
structure of your code so it is strongly recommended that after solving problem 3 you back
up that implementation and start implementing these new features on a copy. If you cannot
finish problem 5 then you can submit two separate files, one containing the untarnished,
(hopefully, correct) solution for problem 3, and another file containing your solution for
problem 5. If all language features are implemented correctly, please submit only one file.