Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ad5b3fe

Browse files
author
Troy Melhase
committed
Adds better support for nested parenthesis. See issue natural#2.
1 parent 873f67a commit ad5b3fe

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

java2python/compiler/visitor.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -774,6 +774,19 @@ def acceptMethodCall(self, node, memo):
774774
arg.left.walk(child, memo)
775775
arg.right = arg = expr(parent=self)
776776

777+
skipParensParents = (
778+
tokens.IF,
779+
tokens.WHILE,
780+
tokens.SWITCH,
781+
tokens.SYNCHRONIZED,
782+
)
783+
784+
def acceptParentesizedExpr(self, node, memo):
785+
if node.parent.type not in self.skipParensParents:
786+
right = self.pushRight()
787+
right.fs = '(' + FS.lr + ')'
788+
return right
789+
return self
777790

778791
def acceptThisConstructorCall(self, node, memo):
779792
""" Accept and process a 'this(...)' constructor call. """

test/Expr2.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
class Expr2 {
2+
public static void main(String[] args) {
3+
int a = 1;
4+
int b = 2;
5+
int c = 3;
6+
int radius = 4;
7+
int y = (radius*radius*a*(a + radius)*radius*b*b) / (c*c+a*a+b*b);
8+
System.out.println(y);
9+
10+
}
11+
}

0 commit comments

Comments
 (0)