In this assignment, you implement a restricted form of the classic problem of simplifying arithmetic expressions. You first implement two simplification operations, then a general algorithm to transform such expressions into a normal form.
The main restriction is that we only deal with the operations +
, -
,
and *
, and that the arguments are only integers and a single variable
symbol x
. Therefore, all expressions eventually simplify to a polynomial
in x
, with integer coefficients.
We have two main types of expressions in this assignment:
- Assignment 2 expressions or A2Expr are built as explained above
- polynomials in
x
orPExpr
are represented in a specific short form.
- An integer is an
A2Expr
x
is anA2Expr
- If
E1
andE2
areA2Expr
, then(+ E1 E2)
,(- E1 E2)
and(* E1 E2)
areA2Expr
Nothing else is anA2Expr