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);
}
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.
source
share