Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix precedence with PointerSymbols #268

Merged
merged 4 commits into from
Oct 7, 2020
Merged

Conversation

jgosmann
Copy link
Collaborator

@jgosmann jgosmann commented Oct 2, 2020

Motivation and context:
PointerSymbol wasn't handling precedence correctly, i.e. (sym.A + sym.B) * sym.C would evaluate to sym.A + (sym.B * sym.C). This PR changes PointerSymbol to keep track of the full syntax tree to handle the precedence correctly. The class to construct this syntax tree is fairly general and covers also some operators not in use by NengoSPA currently, but this allows to reuse it more easily or implement additional PointerSymbol operators without changes to the syntax tree implementation. I intend to reuse that implementation to also provide better SemanticPointer Names with fewer parenthesis, but this will be a separate PR.

Changes to PointerSymbol have been done in a backwards compatible manner with regard to the public interface.

Fixes #267.

Interactions with other PRs:

none

How has this been tested?

  • Unit tests for the syntax tree implementation.
  • Regression test for the case described above.

How long should this take to review?

  • Average (neither quick nor lengthy)

Where should a reviewer start?

Types of changes:

  • Bug fix (non-breaking change which fixes an issue)

Checklist:

  • I have read the CONTRIBUTING.rst document.
  • [n/a] I have updated the documentation accordingly.
  • I have included a changelog entry.
  • I have added tests to cover my changes.
  • I have run the test suite locally and all tests passed.

@jgosmann jgosmann added this to the 1.1.1 milestone Oct 2, 2020
@jgosmann jgosmann requested review from bjkomer and Seanny123 October 2, 2020 17:51
@jgosmann jgosmann force-pushed the fix-pointersym-precedence branch from 86a98d8 to 7627ee3 Compare October 2, 2020 17:55
This will allow correct handling of operator precedence for
PointerSymbol and might also be used to reduce the amount of
parenthesis in automatically generated SemanticPointer names.
This enables correct handling of precedence, e.g.

s = sym.A + sym.B
s * sym.C

will be correctly handled as (sym.A + sym.B) * sym.C instead of
sym.A + (sym.B * sym.C).

Fixes #267.
@jgosmann jgosmann force-pushed the fix-pointersym-precedence branch from 7627ee3 to 4a716eb Compare October 3, 2020 15:28
@jgosmann jgosmann force-pushed the fix-pointersym-precedence branch from 4a716eb to bd765b9 Compare October 3, 2020 16:28
@jgosmann jgosmann merged commit b91074f into master Oct 7, 2020
@jgosmann jgosmann deleted the fix-pointersym-precedence branch October 7, 2020 17:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

PointerSymbol is handling precedence incorrectly
2 participants