This is a BARES (Basic ARithmetic Expression Evaluator based on Stacks) programming project, that includes a recursive descending parser for EBNF (Extended Backus-Naur Form) grammar.
In order to generate a BARES executable at the "bin" dir, run:
$ make
To run this project using input and output files:
$ ./bin/bares <input_file> [output_file]
By using std::cin (input) and std::cout (output):
$ ./bin/bares
The EBNF grammar used in this project represents arithmetic expressions that supports scope definition and operations with integers (-32768 to 32767):
- Addition (+)
- Subtraction (-)
- Multiplication (*)
- Division (/)
- Power (^)
- Module (%)
This EBNF grammar is defined by the statements:
<expression> := <term>, { ( "+" | "-" | "*" | "/" | "%" | "^" ), <term> };
<term> := "(", <expression>, ")" | <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>;
Syntax and run-time errors are both supported by the program.
- Integer constant out of range beginning at column (n)!
- Missing term at column (n)!
- Extraneous symbol after valid expression found at column (n)!
- Ill formed integer at column (n)!
- Missing closing ”)” at column (n)!
- Unexpected end of expression at column (n)!
- Division by zero!
- Numeric overflow error!
To test the BARES program, try to run the executable setting "data/expressions" file as input and "data/solve" file as output.
$ ./bin/bares data/expressions data/solve
It is known that this program treats the ill formed integers that appears after a valid operator as a missing term.
Developed by Lucas Miguel.