Arithmetic parser

I am creating a parser on top of the TDArithmeticParser.m ParseKit tests. I extended TDArithmeticParserTest.m with test failing:

- (void)testMath {
    s = @"10+(2*3)-15";
    result = [p parse:s];
    TDEquals((double)1.0, result); // result == 0.0
}

The problem is that I do not understand why the grammar does not work with this test. Corresponding BNF grammar of an arithmetic analyzer:

expr           = term (plusTerm | minusTerm)*;
term           = factor (timesFactor | divFactor)*;
plusTerm       = '+' term;
minusTerm      = '-' term;
factor         = phrase exponentFactor | phrase;
timesFactor    = '*' factor;
divFactor      = '/' factor;
exponentFactor = '^' factor;
phrase         = '(' expr ')' | Number;

I would be very grateful for any ideas that help me identify the problem.

+4
source share
1 answer

ParseKit developer is here.

First, pay attention: TDArithmeticParser- this is just some (not terribly durable) example code included in the test suite for ParseKit. This is not part of ParseKit itself.

, / TDArithmeticParser, -15 , .

, :

s = @"10+(2*3)- 15";

, -15 ( ).

.

+3

All Articles