Class Printer
java.lang.Object
visitor.Visitor
visitor.Printer
Printer is a Visitor that converts arithmetic expressions into Strings, using
a specified notation (prefix, infix or postfix).
It is used in the Calculator class to print arithmetic expressions in a
human-readable format.
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionGetter method to obtain the string representation of the expression that has been built by the visit methods.voidThe Visitor can traverse a Complex number (a subtype of Expression)voidvisit(IntegerAtom i) The Visitor can traverse an Integer (a subtype of Expression)voidThe Visitor can traverse a Rationnal number (a subtype of Expression)voidThe visit methods for Real.voidThe Visitor can traverse a binary function (a subtype of Expression)voidThe Visitor can traverse an unary function (a subtype of Expression)voidThe visit method for Operation.
-
Constructor Details
-
Printer
Constructor of the Printer class, which takes a Notation as a parameter to specify the notation to be used for printing expressions.- Parameters:
notation- The notation to be used for printing expressions (prefix, infix or postfix)
-
Printer
public Printer()Constructor of the Printer class, which initializes the notation to infix by default.
-
-
Method Details
-
visit
-
visit
Description copied from class:VisitorThe Visitor can traverse an Integer (a subtype of Expression) -
visit
-
visit
-
visit
The visit method for Operation. Needs to handle the different notations (prefix, infix and postfix) and the different number of arguments that an operation can have. It uses helper methods visitArgs and visitArgsInfix to handle the different notations. -
visit
Description copied from class:VisitorThe Visitor can traverse an unary function (a subtype of Expression) -
getResult
Getter method to obtain the string representation of the expression that has been built by the visit methods.- Returns:
- The string representation of the expression that has been built by the visit methods
-
visit
Description copied from class:VisitorThe Visitor can traverse a binary function (a subtype of Expression)
-