小编Ped*_*amH的帖子

一元减去在调车场表达解析器

这是我的表达式解析器使用shunting-yard算法它工作得很好,除了在一种情况下,当我使用一元减去像-2*3它不会工作(我认为它不应该因为我没有在算法中找到任何东西处理这个问题是否有一种简单的方法可以解决这个问题?(这是一个简单的解析器,我只需要()+ - */^)关心Pedram

#include <cctype>
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cmath>
using namespace std;
int olaviat (char c) {
   /*************
    **Operator precedence 
    *************/
  switch(c) {
       case '-' : case '+' :
           return 1 ;
       case '*' : case '/' :
           return 2 ;
       case '^' :
           return 3 ;
       default :
           return 0 ;
  }
}
double eval(char *exp) {
    /*************
    **Convert to reverse polish
    *************/
    char n [50] , o[50] ;
    static int nl = 0  , …
Run Code Online (Sandbox Code Playgroud)

c++ parsing unary-operator shunting-yard

7
推荐指数
1
解决办法
3558
查看次数

标签 统计

c++ ×1

parsing ×1

shunting-yard ×1

unary-operator ×1