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

Possible to extract variables from Expression? #73

Open
herrytco opened this issue Oct 26, 2022 · 4 comments
Open

Possible to extract variables from Expression? #73

herrytco opened this issue Oct 26, 2022 · 4 comments
Labels
enhancement Indicates new feature requests

Comments

@herrytco
Copy link

For my project, I need to parse expressions and get a list of used symbols in that expression. This would look something like this:

String input = "x+y*z+3";
Expression e = Parser().parse(input);

List<String> symbols = e.symbols; // ["x", "y", "z"]

Is that possible with the current state? I couldn't find the function on my own.

@fkleon fkleon added the enhancement Indicates new feature requests label Oct 26, 2022
@fkleon
Copy link
Owner

fkleon commented Oct 26, 2022

Hi @herrytco thanks for creating this issue. It's currently not possible to get a list of symbols/variables directly from the expression tree.

@herrytco
Copy link
Author

Thank you for the answer. Than I fall back to my current strategy to do the following:

  1. try to evaluate the expression
  2. catch all errors related to unbound variables
  3. set the variable to a random value
  4. repeat 2-3 until the expression is evaluated
  5. return the list of symbols found
  6. profit

@VittorioParagallo
Copy link

any plan to implement this feature?

@fkleon
Copy link
Owner

fkleon commented Aug 5, 2024

any plan to implement this feature?

No, but feel free to open a PR if you're wanting to contribute this.

@fkleon fkleon reopened this Aug 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Indicates new feature requests
Projects
None yet
Development

No branches or pull requests

3 participants