World Conquest Chronicles

World Conquest Chronicles

Robot Calculator, v1.0.0-alpha

The electronic calculator.

Implement evaluation of expressions.

Features

  • evaluation:
    • number evaluation:
      • support for a whole number;
      • support for a fractional number:
        • support for a fractional number without a whole part;
        • support for a fractional number without a fractional part;
      • ignore duplicated zeros at the beginning of a number;
      • return NaN:
        • return NaN for an incorrect number;
        • return NaN for a number causing overflow;
      • truncate a number longer than the internal buffer;
    • operation evaluation:
      • supported operations:
        • addition;
        • subtraction;
        • multiplication;
        • division;
      • typo processing:
        • support for several operations in a row (only the first operation will be used);
        • support for expression starting with an operation (the leading operation will be ignored);
        • support for expression ending with an operation (the trailing operation will be ignored).

Grammar

Grammar in an EBNF:

expression = addition;

addition = multiplication, {("+" | "-"), multiplication};
multiplication = NUMBER, {("*" | "/"), NUMBER};

NUMBER = ? /(\d+\.\d*)|(\d*\.\d+)|\d+/ ?;

Example of an expression: 1.2+2.3*4.2.