Skip to content

Fix the problem with operator precedence (#590)#671

Merged
opeongo merged 6 commits into
masterfrom
fix_590
Dec 19, 2022
Merged

Fix the problem with operator precedence (#590)#671
opeongo merged 6 commits into
masterfrom
fix_590

Conversation

@opeongo

@opeongo opeongo commented Dec 14, 2022

Copy link
Copy Markdown
Contributor
  • set up productions in reverse order of precedence
  • split productions that contain operators of different precedence
  • join productions that have operators of similar precedence
  • use tokens instead of strings
  • add test case
  • minor cleanup

This should fix the problem with 1+2*3=9 as noted in #590 and probably elsewhere. Simply reverting the patch that broke operator precedence wasn't acceptable, and with no one else stepping up I went ahead and redid this. So basically this RP is almost the same as before but fixes mod/power precedence. I retained the reduction of productions in the unary expression and elimination of one lookahead from the cast expression. Tokens are used instead of strings because a one point this was the strong recommendation for better performance from the javacc documentation. The test case is a work in progress.

- set up productions in reverse order of precedence
- split productions that contain operators of different precedence
- join productions that have operators of similar precedence
- use tokens instead of strings
- add test case
@codecov

codecov Bot commented Dec 14, 2022

Copy link
Copy Markdown

Codecov Report

Merging #671 (a69bbb5) into master (f1659c1) will increase coverage by 0.18%.
The diff coverage is n/a.

@@             Coverage Diff              @@
##             master     #671      +/-   ##
============================================
+ Coverage     71.11%   71.29%   +0.18%     
- Complexity     2773     2786      +13     
============================================
  Files           106      106              
  Lines          9069     9062       -7     
  Branches       1778     1765      -13     
============================================
+ Hits           6449     6461      +12     
+ Misses         2205     2194      -11     
+ Partials        415      407       -8     
Flag Coverage Δ
unittests 71.29% <ø> (+0.18%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
src/main/java/bsh/BSHType.java 80.59% <0.00%> (-1.10%) ⬇️
...n/java/bsh/classpath/DiscreteFilesClassLoader.java 86.66% <0.00%> (-0.84%) ⬇️
src/main/java/bsh/Primitive.java 83.06% <0.00%> (+0.32%) ⬆️
src/main/java/bsh/util/JConsole.java 14.09% <0.00%> (+0.46%) ⬆️
src/main/java/bsh/Name.java 86.60% <0.00%> (+0.62%) ⬆️
src/main/java/bsh/classpath/BshClassPath.java 86.89% <0.00%> (+1.41%) ⬆️
src/main/java/bsh/classpath/ClassManagerImpl.java 70.58% <0.00%> (+6.09%) ⬆️

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@nickl- nickl- left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was also thinking the easiest way to resolve this is to build the hierarchy in the grammar. This does not mean that there are no other way to deal with this.

The comment will not be useful 10 years from now.

Comment thread src/main/jjtree/bsh.jjt
* will do is rearrange them in to a different order. The java code
* will be compiled, jitted and inlined by c2 so you wont even know
* what the performance impact is unless you do micro benchmarks.
*/

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment should only shed light on what the code does, if it is unclear otherwise. It should not be the motivation for the change, that is what the PR and commit messages are for.

@nickl-

nickl- commented Dec 15, 2022

Copy link
Copy Markdown
Member

Also have you considered addressing the other outstanding parser issues while at this?

@nickl-

nickl- commented Dec 15, 2022

Copy link
Copy Markdown
Member

Please also add unit test for:

true && false ? true : true && false ? true : false;

Just to be sure.

@opeongo

opeongo commented Dec 15, 2022

Copy link
Copy Markdown
Contributor Author

Please also add unit test for:

done

@opeongo

opeongo commented Dec 15, 2022

Copy link
Copy Markdown
Contributor Author

the easiest way to resolve this

Are there still items that need to be resolved on this issue? I think at this point you will have to put your own code forward.

I need to train my editor to do this for me.
@nickl-

nickl- commented Dec 15, 2022

Copy link
Copy Markdown
Member

the easiest way to resolve this

Are there still items that need to be resolved on this issue? I think at this point you will have to put your own code forward.

Looks good, RTBC

@nickl-

nickl- commented Dec 16, 2022

Copy link
Copy Markdown
Member

This is RTBC - ready to be committed (merged)

Are you waiting for me?

@opeongo opeongo merged commit 4e77619 into master Dec 19, 2022
@opeongo opeongo deleted the fix_590 branch December 19, 2022 15:48
pgiffuni pushed a commit to pgiffuni/beanshell that referenced this pull request Jan 8, 2024
Fix the problem with operator precedence (beanshell#590)
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.

2 participants