Question: OCaml does not perform automatic type conversions, even if there is no loss of information. For example, if will not automatically convert the integer 2
OCaml does not perform automatic type conversions, even if there is no loss of information. For example,
if will not automatically convert the integer to the float This, however, makes it less userfriendly
than many other languages. Your implementation must perform such type conversions so that the user
is able to write expressions like You are not expected to overload operators, however. Your
only job here is to make sure that if the user mixes up integers and floats, then any integer is converted to
a float eg becomes if the user input is ; and both become and respectively,
if the user input is
As such, the lossless type conversion from int to float is done internally by your method. The enduser
remains abstracted away from this detail.
The function takes one argument:
An arithmetic expression, which may involve integers or floatingpoint numbers and their corre
sponding operators.
Examples:
buildtree should create a tree representing this expression.
buildtree should create a tree for the floatingpoint expression.
Assumptions:
The input expression is fully parenthesized, including the outermost parentheses.
Operators are separated from their operands by a single space eg
The operators provided are valid for the type of operands eg for integers, for floats
Preconditions:
The input expression is fully parenthesized.
The expression has correctly placed spaces between operands and operators.
The operators provided by the user are valid for the numeric type used in the expression.
CSE Programming Abstractions Homework II Due by November Friday
Postconditions:
The function will return a binary tree where the internal nodes represent the arithmetic operators,
and the leaf nodes represent the numeric operands.
If the input expression is invalid eg missing parentheses, invalid spacing, or incompatible opera
tors the function should return an error or raise an exception.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
