Extensible Token Project
Problem description
In this project, design and write an extensible token program so that other
people can extend it without changing the base code. You will make
heavy use of polymorphism and inheritance to write in a style often known
as"the visitor pattern" (see Recommended reading
at the end of this page).
In this particular problem, assume that one starts with basic tokens
ID and
Number. Each token has operations modify
and print. Then someone may want to add a new token type Symbol.
Someone else may want to add a new method length(). Can you
design token classes in a way such that Symbol and length()
can be added without changing the code of ID and Number.
The specific requirements are
-
Although the token class should be written to allow later extension, it
should not know the exact name and interface of the added token type or
method. You may add in Symbol and length() in any order
but the basic token should not know the name and interface of the first
addition, nor should the first addition know the name and interface
of the second addition.
-
The extensions should not require any change to the existing source code.
You may add in Symbol and length() in any order but the first
addition should not change program of the basic token; furthermore, the
second addition should not change the program you wrote for the first addition.
-
Any program that uses basic tokens should behave exactly like it does before
the extension. Any program that uses the new tokens should be able
to use the added token type and function.
Project organization
-
This project is carried out by a group of three people. One person
writes the code for basic tokens. The other two write the two extensions.
All three write a program that uses the basic token and both extensions.
Each person should write his or her part of the code in a program file
separate from others. All three write a single written report.
Group discussion and group work are intended part of this assignment.
Since the assignment and the grading is the same for both CS254 and CS454,
groups can form between members of both classes.
-
Turn in a written report for grading.
-
(50 out of 100 points) The design of extensible token classes that allows
for the extension of both new token types and new member functions.
If you cannot come up with a design, you can still get partial points by
making token classes extensible to a lesser degree.
-
(10 out of 100 points) A design that allows for new tokens to be added
-
(10 out of 100 points) A design that allows for new functions to be added
-
(20 out of 100 points) Implementation of the extensible tokens in either
C++ or Java. Talk to the instructor if you want to used a different
language. Compile and test your program. Document the result.
Include the source code at the end of your report. Do not submit
any files other than the report.
-
(30 out of 100 points) The description of the design, implementation, and
testing, which should be complete, clear, and concise.
-
A single grade will be assigned to each group. The grade is the same
for all members in the group.
-
Extra credit. (10 points) Make the scanner extensible.
That is, allow new token recognition be added without changing the source
code of the basic scanner.
Recommended reading
Design Patterns: Elements of Reusable Object-Oriented Software,
Gamma, Helm, Johnson, and Vlissides, Addision-Wesley, 1995. Read
the section on Visitor pattern, pp. 331-344. I have a copy of the
book that you can borrow for a short period of time (so that other groups
can use it).
Synthesizing
Object-Oriented and Functional Design to Promote Re-Use. Krishnamurthi,
Felleisen and Friedman, Technical report TR 98-299, Rice University, 1998.
(Local copy in postscript and pdf)
Thinking in C++. Eckel, Prentice Hall, 1995. (Use it as
a C++ reference book, it contains clear explanations and concise examples).
I have a copy of the book that you can borrow for a short period of time
(so that other groups can use it).