Docsity

Infix Expression Calculator Program - Prof. Steven Roach, Assignments of Computer Science

Toggle sidebar
bg1
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.

Partial preview of the text

Download Infix Expression Calculator Program - Prof. Steven Roach and more Assignments Computer Science in PDF only on Docsity!

Program 1: Due 2/

Implement a calculator that reads infix expressions and computes a value. A simple grammar for

infix expressions is given in the following BNF.

::= {a-z}{0-9} ::= [+ | -] [ {+|-} ]* ::= [ {|/} ] ::= | | | ( ) ::= ::= ( [ [ , ]*] ) ::= 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.