This programming project implements a BARES(Basic ARithmetic Expression Evaluator based on Stacks) program. Which is capable of receive simple arithmetics expresssions, formed by:
- Integer numeric constants (-32.768 to 32.767);
- Operators (+, , /, ⇤,ˆ, %), with precedence; and
- Parentheses.
The supported operations and scope delimiters are:
^
: power, right association, weight=3.*
: multiplication, left association, weight=2./
: division, left association, weight=2.%
: module, left association, weight=2.+
: addition, left association, weight=1.-
: subtraction, left association, wight=1.(
: opening scope, weight=0.)
: closing scope, weight=n/a.
For support the BARES was implemented a parser for an EBNF (Extended Backus-Naur Form) grammar.
Information on EBNF grammar may be found here.
Information on recursive descendent parsing may be found here.
The gramar we want to parse represents arithmetic expressions with addition and subtraction of integers.
<expr> := <term>,{ ("+"|"-"),<term> };
<term> := <integer>;
<integer> := 0 | ["-"],<natural_number>;
<natural_number> := <digit_excl_zero>,{<digit>};
<digit_excl_zero> := "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9";
<digit> := "0"| <digit_excl_zero>;
This grammar accepts expressions like:
- "23 + 43 - 0 + -124 - 21"
- " 21"
- "-21 + -18"
- " -54"
- "-21 - 23 + 1234"
And rejects expressions like:
- "01 + 3"
- "2 +"
- " "
- "+2 + 5"
- "-02 + 4"
Later on we might want to improve this grammar to accept other binary operations and more robust expressions.
If you using a linux based system, only type make at your project folder to generate the executable file.
The code was organized in several folders, such as:
- src (for .cpp files),
- data (for input files),
- include (for header files), and
- bin (for .o and executable files)
Once your executable file is generated, you can execute this by:
./bares input file
Program developed by Abraão Dantas (abraaovld@gmail.com) at EDB1 classes, 2018.1
© IMD/UFRN 2017-2018.