CMPT 212
Object-Oriented Applications Design in C++
Spring 1998
Assignment 1
Hints
Grammar of an expression:
An expression is a sequence of one or more terms
separated by + or -.
A term is a sequence of one or more factors
separated by * or /.
A factor is either an expression in parentheses
or a constant.
Description of some of the parsing functions:
The function parseExpr will read the next expression
from the given character string and move the character pointer
to the next character after the expression.
The function parseTerm will read the next term from
the given character string and move the character pointer to
the next character after the term.
The function parseFactor will read the next factor from
the given character string and move the character pointer to
the next character after the factor.
Suppose that we have this expression:
1+2*3-(4+5)*6
Here is the expression tree.
Here is the expression data structure that
your program would produce. Each box represents an
expr struct, where the top left quarter is
the operator (oper), the top right quarter
is the value if the expression is a constant (number),
and the bottom quarters are the first and second
operands (op1 and op2).