Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Postfix arithmetic Operators, in postfix arithmetical expressions, follow operands. For example, 3 4 + means 3 + 4 . The postfix expression 3 4 5
Postfix arithmetic
Operators, in postfix arithmetical expressions, follow operands. For example, means
The postfix expression is evaluated as follows:
replace with the result of adding to
replace with
Postfix expressions are conveniently evaluated using a stack. An expression consisting of
operands and operators collectivelytokens is read from left to right. Successive operands are
pushed on a stack until an operator arrives. The appropriate number of operands are then popped
from the stack, combined with the operator, and the result is pushed back on the stack. The result
of a calculation is always to be found at the top of the stack. A stack is notated a b c in the
following example; the stack top is the leftmost token.
Postfix with variables
The refers to an enhanced form of postfix: a postfix with variables. Expressions can contain
variable names; the value of the variable is used for the calculation. The assignment operator
assigns a value to a variable. For example
A
will set the value of A to It is equivalent to the infix assignment statement A that is to be
found in many computer languages.
Tokens Stack before Action Stack after
Read
Read
Read
Pop twice, evaluate, and
push
Pop two twice, evaluate,
and push
An interactive session might proceed as follows
A
B
A B
Symbol Table
A symbol table data structure associates keys with values. For example,
A generic symbol table should support two operations, INSERT and SEARCH. There may also be
a DELETE operation. No assumptions are made on the type and format of keys and values.
You will need a symbol table in your Postfix interpreter. The table will map variable name key
to value.
The target hardware
A Postfix interpreter might run on a small device with very limited memory. This means that the
variable namespace is small, for example, AZ
Work plan
You must consider what data structures and algorithms are required in your Postfix interpreter.
Phase : Design
Tokens Stack before Action Stack after
A Read A A
A Read A
A Pop twice and set the
value of A to
Example Key Value
Phone book Name Telephone number
DNS URL IP address
Education Student ID Module grades
Compiler Variable name Memory address
Dictionary Word Definition
Consider first your choice of data structures. Why are they appropriate? How will they be
implemented? Make a list of the data structures and alongside each structure write a few words
of justification.
Then consider the major algorithms. There be will algorithms to access and modify the symbol
table, and an algorithm to perform postfix arithmetic. Your report will contain pseudocode for
each algorithm.
Phase : Implementation
You can use any language you wish. Javascript or C are good choices.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started