Docsity

Software Design Lab 7: Identifying Design Patterns in Mathematical Interpreter, Lab Reports of Computer Science

Toggle sidebar
bg1
CS350/SE310 Software Design/Software Architcture I
Lab 7: Mathematical Interpreter
Due November 24th, 2008
Group ID: ___________
Goal: Identifying interpreter, iterator, and visitor patterns
Background
The Mathematical Interpreter in Java (Mij) is a system that accepts simple mathematical expressions
from the user and calculates the numeric results. For example, here is a sample run of the program
(user input shown in italics):
> 4 * 3^2 โ€“ 2 * 3 + 1
31.0
> set(x, 3)
3.0
> 4 * x^2 โ€“ 2 * x + 1
31.0
> cos(Pi)
-1.0
> int(2*sin(x), x, 0, 2 * Pi)
-1.1038300434557547E-16
The expressions entered by the user must match the following grammar:
AddExpr โ‡’ AddExpr AddOp MultExpr | MultExpr
AddOp โ‡’ + | -
MultExpr โ‡’ MultExpr MultOp ExponExpr | ExponExpr
MultOp โ‡’ * | /
ExponExpr โ‡’ UnaryExpr ^ ExponExpr | UnaryExpr
UnaryExpr โ‡’ AddOp ValueExpr | ValueExpr
ValueExpr โ‡’ id | number | ( AddExpr )
| id ( ) | id ( Params )
Params โ‡’ AddExpr | AddExpr , Params
Within the grammar, the id type is an identifier name, like variable names in Java. These identifiers
can start with a letter or underscore, and can contain any number of letters, numbers, or
underscores.
pf3
pf4

Partial preview of the text

Download Software Design Lab 7: Identifying Design Patterns in Mathematical Interpreter and more Lab Reports Computer Science in PDF only on Docsity!

CS350/SE310 Software Design/Software Architcture I

Lab 7: Mathematical Interpreter

Due November 24th, 2008

Group ID: ___________

Goal: Identifying interpreter, iterator, and visitor patterns

Background

The Mathematical Interpreter in Java (Mij) is a system that accepts simple mathematical expressions from the user and calculates the numeric results. For example, here is a sample run of the program (user input shown in italics):

4 * 3^2 โ€“ 2 * 3 + 1

set(x, 3)

4 * x^2 โ€“ 2 * x + 1

cos(Pi) -1. int(2*sin(x), x, 0, 2 * Pi) -1.1038300434557547E-

The expressions entered by the user must match the following grammar:

AddExpr โ‡’ AddExpr AddOp MultExpr | MultExpr AddOp โ‡’ + | - MultExpr โ‡’ MultExpr MultOp ExponExpr | ExponExpr MultOp โ‡’ * | / ExponExpr โ‡’ UnaryExpr ^ ExponExpr | UnaryExpr UnaryExpr โ‡’ AddOp ValueExpr | ValueExpr ValueExpr โ‡’ id | number | ( AddExpr ) | id ( ) | id ( Params ) Params โ‡’ AddExpr | AddExpr , Params

Within the grammar, the id type is an identifier name, like variable names in Java. These identifiers can start with a letter or underscore, and can contain any number of letters, numbers, or underscores.

Instructions

This lab has the following two stages:

Stage 1: Identifying Iterator Pattern

Identify the classes that participate in each of the two instances of the iterator pattern in the system. Follow the official iterator pattern UML class diagram and identify the role of each of these classes within the pattern.

Stage 3: Identifying the interpreter pattern.

Identify the classes that participate in the interpreter pattern, and their roles within the pattern. Draw its UML class diagram.