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

Evaluate expressions sequentially #37

Open
jkeiser opened this issue Jan 16, 2019 · 0 comments
Open

Evaluate expressions sequentially #37

jkeiser opened this issue Jan 16, 2019 · 0 comments
Labels

Comments

@jkeiser
Copy link
Member

jkeiser commented Jan 16, 2019

Currently we evaluate expressions by recursively going up a tree. With , we had to make that work.

Switch to evaluating expressions in lexical order, since that's what we do. 1+(2*3)+4 means evaluating in this order: 1, + (2*3), + 4. (2*3), being a group, is recursively evaluated. This limits recursion to expressions that require it.

Pros:

  • This would allow us to store way less information in the ast--just the extra groupings given to us by precedence and spaces.
  • It also means a much more linear traversal since you don't start somewhere in the middle of the ast, so more will be in cache.

Cons:

  • It ... might? make it harder to actually build the tree, if we're using that data while we build it. I'm pretty sure it won't make it any harder to traverse (it should be easier).

Notes:

  • The ; = and : operators have a high tendency to create precedence groups, which necessarily cause recursion that might not be necessary. (, needs the recursion for sure.) Not exactly a con--we're recursing right now so this won't make it worse.
  • You could actually execute code while it is being parsed (use case? Maybe maybe not.).
  • There is an operator extensibility story there that might let us build ?:, if, and , as standard operators instead of treating them special in the evaluator as we do now. Might even be possible with { and (, not sure about that one.
  • It's possible (though not sure if desired) to forego precedence groups altogether and end up with a cleaner tree that represents the actual syntax more closely. Doing this might actually allow operators to have different precedence in different situations, if that's needed or desired.
@jkeiser jkeiser self-assigned this Jan 16, 2019
@jkeiser jkeiser closed this as completed Jan 16, 2019
@ghost ghost removed the in progress label Jan 16, 2019
@jkeiser jkeiser reopened this Jan 16, 2019
@jkeiser jkeiser added to do and removed in progress labels Jan 30, 2019
@jkeiser jkeiser removed their assignment Jan 30, 2019
@jkeiser jkeiser removed the to do label Jan 30, 2019
@jkeiser jkeiser added the to do label Feb 16, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant