calculator (Windows) - library API 1.1.1
calculator - Libraries
Loading...
Searching...
No Matches
expressionParser.h
Go to the documentation of this file.
1
8#ifndef EXPRESSION_PARSER_H
9#define EXPRESSION_PARSER_H
10
11#include <string>
12
13namespace Coruh
14{
15 namespace Calculator
16 {
27 {
28 public:
43 static std::string toPostfix(const std::string& infix);
44
56 static double evaluatePostfix(const std::string& postfix);
57
67 static double evaluateInfix(const std::string& infix);
68
69 private:
71 static bool isOperator(char c);
72
74 static int precedence(char c);
75 };
76 }
77}
78
79#endif // EXPRESSION_PARSER_H
Parses and evaluates infix arithmetic expressions built from +, -, *, /, parentheses,...
Definition expressionParser.h:27
static int precedence(char c)
Operator precedence: 2 for '*','/'; 1 for '+','-'; 0 otherwise.
Definition expressionParser.cpp:15
static std::string toPostfix(const std::string &infix)
Converts an infix expression to postfix (RPN) notation using the shunting-yard algorithm.
Definition expressionParser.cpp:21
static double evaluateInfix(const std::string &infix)
Convenience helper: parses and evaluates an infix expression in one call (toPostfix() + evaluatePostf...
Definition expressionParser.cpp:141
static bool isOperator(char c)
True for '+', '-', '*', '/'.
Definition expressionParser.cpp:11
static double evaluatePostfix(const std::string &postfix)
Evaluates a postfix (RPN) expression as produced by toPostfix().
Definition expressionParser.cpp:100
Definition calculator.h:13