djrieger / mjplusplus

A compiler for the MiniJava language
http://djrieger.github.io/mjplusplus/doc/doxygen/html/
6 stars 1 forks source link

Add missing parentheses around certain expressions #8

Closed djrieger closed 9 years ago

djrieger commented 9 years ago

Compared to the reference pretty-print solution, our output still lacks some parentheses around certain Expressions. I tried adding them but could not pinpoint the exact spot where they need to be added. Can anyone help please?

Our output (red) as of 723894e38247a40b22b3198dc8ee9167bb8f120f compared to what it should look like:

--- Our output
+++ HelloWord-output.mj
@@ -3,15 +3,15 @@
        return c = (a + b);
    }
    public static void main(String[] args) {
-       System.out.println((43110 + 0));
+       (System.out).println(43110 + 0);
        boolean b = true && (!false);
-       if (23 + 19 == (42 + 0) * 1)
+       if ((23 + 19) == ((42 + 0) * 1))
            b = (0 < 1);
-       else        if (!array[2 + 2]) {
+       else if (!(array[2 + 2])) {
            int x = 0;
-           x = x + 1;
+           x = (x + 1);
        } else {
-           (new HelloWorld()).bar(42 + 0 * 1, -1);
+           (new HelloWorld()).bar(42 + (0 * 1), -1);
        }
    }
    public boolean[] array;
djrieger commented 9 years ago

Fixed in b3b661a60c85cbbb5a52807dfcd939a25da8ca57