
Program 1: Due 2/3
Implement a calculator that reads infix expressions and computes a value. A simple grammar for
infix expressions is given in the following BNF.
<ident> ::= {a-z}{0-9}
<expr> ::= [+ | -] <term> [ {+|-} <term>]*
<term> ::= <factor> [ {*|/} <factor> ]*
<factor> ::= <ident> | <function> | <number> | ( <expr> )
<function> ::= <name> <vlist>
<vlist> ::= ( [<expr> [ , <expr>]*] )
<name> ::= sin | cos | sqrt
Note that the operations are the same as the previous assignment. Input formulas also use
parentheses to enforce precedence. Formulas also contain constants, which are assumed to
be floating point numbers.
Your program should read an input string from the keyboard and then compute the value of the
formula. Your program needs a simple command line user interface to run. Do not build a GUI
for this program.