Skip to content

Use LR parser to parse expressions coming from the Clipboard and generate commands #344

@rudyhuyn

Description

@rudyhuyn

The current code to manage the clipboard only supports a subset of functions managed by the calculator, has some issues to parse them (many false positives or issues with locales due to the conversion to en-us format but ignoring that '.' and ',' can be used for other purposes in the original locale) and very complicated to maintain/add new features (sin, pin, square, etc..).

In order to simplify and make this function more robust, we should instead use a language parser, more suited to our needs.

My proposal would be to use a custom Lexer to support all the different number formats (hex, bin, dec, bin, dec with exponent, ...) and modes (standard, programmer, etc...) we support and use a LR parser to verify and generate the list of commands. This solution would have many advantages:

  • very easy to add new operator whatever their types (binary, pre-unitary or post-unitary)
  • the parser will generate the sequence of commands while verifying the text, easier to maintain
  • no false positive possible

In my proto-PR, I used Bison, a GPL v3 tool but providing an explicit exception to allow the use of the generated code without license.

It already manages a variety of features not currently available:

sinus/cos/tan
complex operations

** Power, square, cube ** (#299)
Power

more sign operators
moresigns

Binary operations: OR, NOT, AND, XOR
binaryOp
binary

and fix some reported bugs:

Proto-PR available here

https://github.com/rudyhuyn/calculator/tree/AddExpressionParser

remaining:

  • add unit tests
  • it only supports 0;0 and 0;3 grouping for the moment

Metadata

Metadata

Assignees

No one assigned

    Labels

    codebase qualityIssues that are not bugs, but still might be worth improving (eg, code hygiene or maintainability)needs attention

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions