Equation (expression) parser with precedence?

前端 未结 23 1506
遇见更好的自我
遇见更好的自我 2020-11-22 11:44

I\'ve developed an equation parser using a simple stack algorithm that will handle binary (+, -, |, &, *, /, etc) operators, unary (!) operators, and parenthesis.

<
23条回答
  •  渐次进展
    2020-11-22 12:27

    Have you thought about using Boost Spirit? It allows you to write EBNF-like grammars in C++ like this:

    group       = '(' >> expression >> ')';
    factor      = integer | group;
    term        = factor >> *(('*' >> factor) | ('/' >> factor));
    expression  = term >> *(('+' >> term) | ('-' >> term));
    

提交回复
热议问题