[GiNaC-list] GiNaC::parser parses "3^+2+1" in the wrong order

Vitaly Magerya vmagerya at gmail.com
Mon Feb 20 13:21:36 CET 2023


Hi, all. When parsing expressions with sign in the exponent, GiNaC's
parses confuses the priorities somehow. Here are some examples:

    3^2+1 is parsed as (3^2)+1, which is correct;
    3^+2+1 is parsed as 3^(+2+1), which is wrong;
    3^-2+1 is parsed as 3^(-2+1), which is wrong;
    3^+2/3 is parsed as 3^(+2/3), which is wrong;
    etc.

Here's a test case, it will print 27, not the correct 10:

#include <ginac/ginac.h>
#include <ginac/parser.h>
#include <iostream>
#include <sstream>
#include <string>
int main() {
    std::string input = "3^+2+1";
    std::istringstream instream(input);
    GiNaC::parser reader;
    GiNaC::ex expr = reader(instream);
    std::cout << input << " = " << expr << "\n";
}


More information about the GiNaC-list mailing list