1.输入优先等级和栈优先等级定义:目的,解决右结合表达式问题,例如2^2^2为右结合表达式
2.累计等级与无效表达式分析:
3.使用栈处理相同或较低优先级的运算符
Example:a*b/c+d
4.处理右结合表达式运算符^
Example:a^b^c
5.处理子表达式的左右圆括号。
Example:处理a*(b+c)中的子表达式(b+c)
实现代码:并未包含异常处理
//操作符优先级类
#ifndef op_priority_H
#define op_priority_H
class op_priority
{
private:
int inputPriority; //输入优先级
int stackPriority; //栈优先级
char op; //运算操作符
public:
op_priority()
{
}
op_priority( char ch):op(ch) //设置运算符的优先级
{
switch(ch)
{
2.累计等级与无效表达式分析:
3.使用栈处理相同或较低优先级的运算符
Example:a*b/c+d
4.处理右结合表达式运算符^
Example:a^b^c
5.处理子表达式的左右圆括号。
Example:处理a*(b+c)中的子表达式(b+c)
实现代码:并未包含异常处理
//操作符优先级类
#ifndef op_priority_H
#define op_priority_H
class op_priority
{
private:
int inputPriority; //输入优先级
int stackPriority; //栈优先级
char op; //运算操作符
public:
op_priority()
{
}
op_priority( char ch):op(ch) //设置运算符的优先级
{
switch(ch)
{