Complete the PostFixExpression class that is partially defined below.public class PostFixExpression {private List<object> L;public PostFixExpression (string s) { … }private void Analyzer (string s) { … }private void Convert ( ) { … }public float? Evaluate ( ) { … }public override string ToString( ) { … }}1. The constructor creates but does not initialize a List L of objects. It then calls private methodsAnalyzer and Convert to perform the initialization of L. (2 marks)2. The method Analyzer processes the given string character by character, separates out its integerand operator components, and inserts them into list L. If a character is not a digit or an operator,then an ArgumentException is thrown with an appropriate message. (9 marks)3. The method Convert transforms list L into a postfix expression usinga. a local instance of an operator (character) stack andb. the rules of precedence given earlier.No error checking is performed except for balanced parentheses. If parentheses are not balanced,then an ArgumentException is thrown with an appropriate message. (9 marks)Page 3 of 64. The method Evaluate returns the result of the current postfix expression using a local instance ofan operand (floating point) stack. If the postfix expression is syntactically incorrect, then the erroris identified, and null is returned. Syntax errors include:a. Too few or too many operandsb. Too few or too many operatorsA syntax error throws an ArgumentException with an appropriate message. A runtime check fordivision by 0 also throws an ArgumentException with an appropriate message. (8 marks)5. The method ToString returns the string representation of the postfix expression. (2 marks)The main program is straightforward. It reads in a string s from the console and then declares, definesand evaluates an instance of PostFixExpression based on string s. The main program also catches anyexceptions that are raised elsewhere.
Complete the PostFixExpression class that is partially defined below.
public class PostFixExpression {
private List<object> L;
public PostFixExpression (string s) { … }
private void Analyzer (string s) { … }
private void Convert ( ) { … }
public float? Evaluate ( ) { … }
public override string ToString( ) { … }
}
1. The constructor creates but does not initialize a List L of objects. It then calls private methods
Analyzer and Convert to perform the initialization of L. (2 marks)
2. The method Analyzer processes the given string character by character, separates out its integer
and operator components, and inserts them into list L. If a character is not a digit or an operator,
then an ArgumentException is thrown with an appropriate message. (9 marks)
3. The method Convert transforms list L into a postfix expression using
a. a local instance of an operator (character) stack and
b. the rules of precedence given earlier.
No error checking is performed except for balanced parentheses. If parentheses are not balanced,
then an ArgumentException is thrown with an appropriate message. (9 marks)
Page 3 of 6
4. The method Evaluate returns the result of the current postfix expression using a local instance of
an operand (floating point) stack. If the postfix expression is syntactically incorrect, then the error
is identified, and null is returned. Syntax errors include:
a. Too few or too many operands
b. Too few or too many operators
A syntax error throws an ArgumentException with an appropriate message. A runtime check for
division by 0 also throws an ArgumentException with an appropriate message. (8 marks)
5. The method ToString returns the string representation of the postfix expression. (2 marks)
The main program is straightforward. It reads in a string s from the console and then declares, defines
and evaluates an instance of PostFixExpression based on string s. The main program also catches any
exceptions that are raised elsewhere.
Step by step
Solved in 2 steps