Emergency C++ Programming Help

[b][red]This message was edited by raquel54 at 2002-8-26 17:37:20[/red][/b][hr]
Following is a project that must be completed by Thursday, 8/29/2002. Please review and email me with rates (if applicable) and turnaround time. Thanks!
******
PROJECT: An Interpreter for a Simple Mathematical Expression Language

____________________________________________________________________

Project Objective:
=================

Your task will be to implement an interpreter for a Simple Mathematical
Expression Language (Call it "SMEL," if you like. ;-) ).

Permissible Implementation Languages:
------------------------------------

You must implement the interpreter in C++

____________________________________________________________________

Description of the Language:
===========================

Language Support for Operations and Functions:
---------------------------------------------

The language supports both unary and binary operations, along with some
built-in functions. The unary operations are unary minus and unary plus.
The binary operations are +, -, *, /, % (remainder), and ^ (exponentiation).
The built-in functions are sin, cos, tan, sqrt, exp, and abs (i.e., sine,
cosine, tangent, square root, the constant E raised to some power, and
absolute value). Notes: The values passed to the trigonometric functions
MUST be in radians. (Converting from degrees to radians is accomplished
by multiplying the degree value by PI/180.) In addition, the value passed
to the square root function MUST be non-negative.


Language Support for Numeric Types:
----------------------------------

Numeric types supported by the language include integer and floating point
numbers.


Language Support for Constants:
------------------------------

The language also provides some built-in constants, namely PI (3.141593)
and E (2.718282), required by the functions sin, cos, tan, and exp.


Language Support for Inclusion Symbols:
--------------------------------------

SMEL allows for the use of parentheses, which can be nested arbitrarily
deeply.


Language Support for Error-Checking:
-----------------------------------

The reporting of errors in the event of:

- A malformed mathematical expression (e.g., mismatched parentheses);
- An unrecognized function, constant, or operation;
- An attempt to divide by zero;
- An attempt to take the square root of a negative number;
- An attempt to compute the tangent of PI/2 or (3*PI)/2; and ...
- An attempt to compute the remainder of two numbers,
both of which are not integers;

is also provided for by SMEL.

__________________________________________________________________________


Interactive Features of the Language:
====================================

Mathematical expressions entered by the user are processed as they are
entered. The user types a single-line expression, followed by hitting .
If the mathematical expression is valid, its value is printed immediately;
otherwise, an error is reported.

_________________________________________________________________________


The Grammar (Structure) of the Language:
=======================================

lines -> lines expression '
'
| lines '
'
| /* empty string */

expression ->
predefined_function_name (expression)
| expression + term
| expression - term
| term

term -> term * e_term
| term / e_term
| term % e_term
| e_term

e_term -> e_term ^ factor
| - e_term
| + e_term
| factor

factor -> (expression)
| number

number -> digits optional_fraction
| predefined_constant

optional_fraction ->
. digits
| /* empty string */

digits -> digit digit*

digit -> 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9

predefined_constant -> PI | E

predefined_function_name ->
SIN | COS | TAN | SQRT | EXP | ABS

_________________________________________________________________________


Sample Interactive Session:
==========================

> 4 + 3 * 10

34

> sin(PI/6)

0.5

> 1.5 ^ 3

3.375

> sec(PI/2)

Error: unrecognized function

> (25 - 5) / (-2 - 2)

-5

> exp(0)

1

> sqrt(-6.3)

Error: negative argument

> quit

Good-bye
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories