Ptt12 2

(C) 2012 — Software Languages Team, University of Koblenz-Landau

Navigation

The PTT course

Check-in deadline

20.06.2012 (End Of Day, Koblenz timezone)

Pointers

TBD

Title

STACKY Language

Consider the following grammar of a tiny stack-based language STACKY:

(op “;”)∗

prog = op =

int =

… // integer literals

“init”
| “push” int

| “pop”

| “add”

| “show”

The semantics of STACKY programs is this. Execute all operations in the sequence in sequential order. The run-time system uses a stack of integers. The “init” operation resets the stack. The “push” operation pushes an integer onto the stack. The “pop” operation forgets the top-of-stack. The “add” operation adds the top-of-stack and second-to-top-of-stack; it also pops the two operands; and pushes the result of addition onto the stack. The “show” operation shows the top-of-stack on the screen. Consider the following program:

push 1; push 2; push 3; pop; push 4; add; show;

The execution results in the output of “6”. The resulting stack is “6” on top of “1”.

Assignment

  • Devise an object model for STACKY.
  • Using a designated polymorphic method interpret, implement an interpreter for executing STACKY programs.
  • Using a designated polymorphic method prettyPrint, implement a pretty printer for printing STACKY objects in concrete syntax.

Extend your STACKY project with functionality to load stacks from a database and to save stacks in a database. The STACKY language is extended by two operations: load and save. For clarity, you are not supposed to store STACKY programs, but just the stacks. Load and save operations can be now part of STACKY programs as further kinds of operations.

Details: Each persisted stack has a name (a string) and a date when it was stored. The name should serve as the primary key. You need two tables: one for the stack’s date, and another for the elements of the stack. If you use a name for saving that is already used in the database, then you need to first delete all rows for that name. Provide a test case to illustrate the load and save operations in STACKY programs.

Hint: use the programming style of the “Database Access” lecture. That is, use embedded SQL statements in your Java code. You need to run a MySQL server either locally on your machine, or remotely at the department. You can also use hibernate as a data-access layer.

Important request: please make sure that the teaching assistants can easily and smoothly test your database functionality. Option 1: if you use the remote database at the department, please make sure that you share sufficient login credentials—possibly encoded in the program itself. Option 2: if you use a local MySQL database on your machine, please make sure to script up everything so that the teaching assistant can reproduce your environment. (If you want to bypass Option 1 and 2, please make sure to get clearance from the newsgroup and/or your teaching assistant.)

If you're a super achiever, please implement a simple IDE for STACKY language.