266# include <tclap/CmdLine.h>
270using namespace Aleph;
291 case '(':
return Lpar;
292 case ')':
return Rpar;
297 case '\0':
return End;
303 char* base = str + 1;
315 static char buffer[256];
337 cerr <<
"Invalid operator: " << op <<
endl;
349 cerr <<
"Error: operator stack empty" <<
endl;
354 cerr <<
"Error: not enough operands" <<
endl;
371 cerr <<
"Error: division by zero" <<
endl;
424 cerr <<
"Error: mismatched parentheses" <<
endl;
439 cerr <<
"Error: malformed expression" <<
endl;
446 cerr <<
"Error: invalid token at position" <<
endl;
456 TCLAP::CmdLine
cmd(
"Arithmetic expression evaluator",
' ',
"1.0");
458 TCLAP::UnlabeledValueArg<string>
exprArg(
"expression",
459 "Arithmetic expression to evaluate (use quotes)",
460 true,
"",
"expression");
465 string expr =
exprArg.getValue();
467 cout <<
"Expression Evaluator" <<
endl;
468 cout <<
"====================" <<
endl;
472 char*
input =
new char[expr.size() + 1];
477 cout <<
"Result: " << result <<
endl;
481 catch (TCLAP::ArgException &e)
483 cerr <<
"Error: " << e.error() <<
" for arg " << e.argId() <<
endl;
Stack implemented with simple dynamic array and with bounds verification.
size_t size() const noexcept
Count the number of elements of the list.
char * str_to_token(const char *token_str, const size_t &len)
Convert token string to null-terminated string.
void apply(ArrayStack< int > &val_stack, ArrayStack< char > &op_stack)
Apply operator to top two values on stack.
Token_Type lexer(char *&str, size_t &len)
Lexer - extracts next token from input string.
unsigned precedence(const char &op)
Get operator precedence.
int eval(char *input)
Evaluate arithmetic expression.
Main namespace for Aleph-w library functions.
void exit(const char *file, int line, const char *format,...)
Print a message and exit the program.
DynList< T > maps(const C &c, Op op)
Classic map operation.
Stack implementations backed by dynamic or fixed arrays.