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

expr: refactor AST and parsing #5586

Merged
merged 1 commit into from Nov 28, 2023

Conversation

tertsdiepraam
Copy link
Member

@tertsdiepraam tertsdiepraam commented Nov 27, 2023

Since we had some problems with expr I rewrote the parsing logic, which then again ballooned into rewriting everything (as seems to happen to me often these days...).

I removed the tokenization, because that's not correct; each token could also be a valid string in another position. I also made the AST so that it does not have slices of values, but a fixed number for each operation. This makes the whole thing much less error prone. The parser is replaced with a fairly simple yet effective recursive descent parser.

The total implementation is also much smaller (especially considering that some lines are new tests).

Limitations:

  • Currently I've only added String values, which leads to unnecessary conversions between strings and integers.
  • Evaluation should happen during parsing not after (try for instance expr '(' 1 / 0, which in GNU gives a division by zero error and a syntax error here)

@tertsdiepraam tertsdiepraam force-pushed the expr-ast-refactor branch 4 times, most recently from ad96fb9 to 2c19f9e Compare November 27, 2023 13:34
@sylvestre
Copy link
Sponsor Contributor

terrific
and it is making the fuzzer happier :)

@sylvestre sylvestre merged commit 0e8197e into uutils:main Nov 28, 2023
49 of 53 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants