Homework Problem !
2 messages in this thread
Hello all,
I got some questions regarding a Data Structure assignment I have. I
have read my assignment instructions a couple of times and I still don't
undestand part of it.
Example:
Purpose of the program: ********************** To evaluate an expression of
operands and operators. ex. a+b*342-c**2
Each operand is a single letter, in upper or lower case, or an integer.
An operator is one or two characters.
Inputs: ******
1. A file of symbolic operands and their integer value.
Format: letter<space>value
Ex.: c -28
Note: Do not distinguish between cases.
2. A file of operators followed by their ISP and ICP values.
3. Keyboard input of an expression.
Outputs: ******* Error message or value of expression.
Give an error for
a. operand not in the file but in the expression.
b. operator in the expression but not in the file.
c. inproper expression.
d. over obvious errors.
Considerations: **************
Allow the user to enter another expression after one has been processed.
****************************************** Those were my instructions but I
have several doubts. Naturally if I have a file with ISP and ICP values
I've got to do some INfix to Postfix evaluations, and my question is why ?
If my input is a regular expression, I guess I can evaluate it as Infix and
done I'll get an output. Why do I need the Postfix evaluation and where ?
Well, lets suppose I've got to evaluated and ex. from (a+b)*c I get ab+c*
what do I do with that ? I'm kind of confused with this assignment and I'll
appreciate someone with some experience that can analyze my assignment and
answer my silly questions.
Thank you very much, Michelle.
(program due on Monday 8:00am I'll be
checking for responses every hour )
Michelle,
The primary reason for PostFix notation is to do the actual evaluation.
Most assemblers and interpreters use postfix format for the actual
evaluation. First values are move into registers or pseudo registers, then
the operations are done. For example, the standard way to do (a+b)*c in
68000 assembler would be
move.l a,d0
move.l b,d1
add.l d1,d0
move.l c,d1
muls.l d1,d0
or in 80287 assembler,
fld a
fld b
fadd
fld c
fmul
>> Gary <<