Class Counter
java.lang.Object
visitor.Visitor
visitor.Counter
Counter is a visitor that counts the numbers, operations,
and depth in an arithmetic expression.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionintgetDepth()Gets the depth.intgetNbNbs()Gets the number of numbers.intgetNbOps()Gets the number of operations.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 Visitor can traverse a Real number (a subtype of Expression)voidThe Visitor can traverse a binary function (a subtype of Expression)voidThe Visitor can traverse an unary function (a subtype of Expression)voidVisit an operation: increments the operation count, then recursively visits all child expressions to accumulate counts.
-
Constructor Details
-
Counter
public Counter()Default constructor.
-
-
Method Details
-
visit
-
visit
Description copied from class:VisitorThe Visitor can traverse an Integer (a subtype of Expression) -
visit
-
visit
-
visit
-
visit
Description copied from class:VisitorThe Visitor can traverse an unary function (a subtype of Expression) -
visit
Description copied from class:VisitorThe Visitor can traverse a binary function (a subtype of Expression) -
getNbOps
public int getNbOps()Gets the number of operations.- Returns:
- The number of operations in the expression
-
getNbNbs
public int getNbNbs()Gets the number of numbers.- Returns:
- The number of numbers in the expression
-
getDepth
public int getDepth()Gets the depth.- Returns:
- The depth (0 for a number, 1 for a simple operation, etc.)
-