• Stars
    star
    315
  • Rank 132,951 (Top 3 %)
  • Language
    Objective-C
  • License
    MIT License
  • Created almost 8 years ago
  • Updated over 4 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

a calculating engine~

Algebraic Engine (Fraction)

Why write this engine?

The reason is I coded a supercalculator last year in Appstore, which is based on one more completed parser.

This parser is just a simplified prototype. It calculates not only fraction but normal expression, so you can enrich this library in normal calculation. Detail illustration will be added in the near future.

Parser Process:

解析流程

For example:1+2*(3-4) parsing process:

  1. Tokenizer: Tokens:1, +, 2, *, (, 3, -, 4, )

  2. Interpreter: Specify the vague tokens,i.e '+' means add or positive ,the same as '-'.

  3. Parser

解析数据

AST(抽象树):

抽象树

In fact, the math expression is parsed into one custom nested cluster in coding,and then resolve sub-expression on each level from inside to outside one.


Tips:

  1. adjust number, which is regarded as fraction through process,such as

    2 convert to 2/1 ; 0.2 convert to 2/10; 0.9998 convert to 9998/10000

  2. because of object-c without function operator,we need to convert operators to function name, i.e @"+" to "add"

Todo :processing more symbol