CS 330 Home Schedule Resources

MidSemester Project Part 2

Estimated time: 5-6 hours (not including extra credit)

Objectives:

TO DO List
  1. Implement your own semantic stack operations, and make them secure using a Wrapper. (15 minutes)
  2. Implement your own environment operations using records. You may find the following built-in operations helpful: List.toRecord, Map, AdjoinList. (30 minutes)
  3. Implement your own store operations using dictionaries. (30 minutes)
  4. Make a utilities functor that exports your stack, environment, and store operations. Wrap your interpreter into a stand-alone application functor that imports your utilities. (30 minutes)
  5. Write a parser that translates the C-like language into abstract syntax, following the model on page 164 of the textbook. (2 hours)
  6. Translate the nested records of formals and actual arguments into lists, as expected by the interpreter. (30 minutes)
  7. (20% Extra Credit) Add concrete syntax to your parser for a 'for' loop. Write an Abstract Syntax Tree transformer that translates the 'for' loop into the kernel abstract syntax for a procedure call to a 'ForLoop' procedure. (Hint: Prestock your interpreter's environment with a ForLoop procedure, and translate the abstract syntax of the for loop into the abstract syntax of an fappStmt. You may design your own concrete syntax for the 'for' loop.) (2 hours)
  8. Run your parser/interpreter and show the contents of the stack, environment, and store at two or three key moments that verify that lexical scoping and tail call optimization are working properly. You may use one or more of the sample test programs to do this. To verify tail call optimization write a recursive Factorial function in the C-like language. Submit your output with a brief explanation of what is going on. (30 minutes)

Last update: Friday afternoon, April 7th, 1:00pm.

  • posted code for SubtractList utility under "Links"
  • added/fixed hint for sequences in comment at bottom of skeleton
  • fixed reference to 'formals' in parser skeleton; changed it to 'ids'
  • Added new test cases P6, P7, P8, P9.
  • Replaced tokenizer.ozf with .oz file that can be compiled on Windows or linux machines.
  • Changed line 21 of C_Like.oz to use lower-case 'e' in calling I.executeProgram
  • Zipped all the *.clike files together in one zip for your convenience.

    LINKS:
    See page 164 in the textbook for an example Pascal parser!
    SubtractList utility used by interpreter in Part 1
    Main command-line program that executes parser and interpreter
    Parser skeleton
    Tokenizer.oz (Needs to be compiled.)
    Skeleton for part 1

    C_Like test programs:
    These correspond to the sample programs from Part 1 having the same name.

  • P0.clike
  • Program1.clike
  • Program2.clike
  • P1.clike
  • P2.clike
  • P3.clike
  • P4.clike Should output 4
  • P5.clike Should output 7 twice
  • P6.clike Should output 50 and some kind of procedure (fdef, etc.)
  • P7.clike Should output 4, 4, and 7
  • All nine *.clike programs are zipped together here if you'd prefer to download them all at once.

  • Feedback.
    Scale
    1. Not at all
    2. Not very
    3. Slightly
    4. Somewhat
    5. Mostly
    6. Very
    7. Extremely