Why doesn't this program compile?

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Why doesn't this program compile?

pguertin
Okay, maybe I'm seeing things, but I can't understand why the supplied Jack compiler doesn't want to compile this:

class Main {
    function void main() {
        var int a;
        let a = 1;
        if (a>0) { 
            do Output.printInt(1); 
        }
        return;
    }
}

On my system, it fails with the error:

In Main.jack (line 5): In subroutine main: Expected statement(do, let, while, return or if)

The file is called Main.jack and is the only file in its directory named "test", and I'm calling "JackCompiler test".

This is especially weird beause the supplied compiler compiles much more complicated programs without a hitch. I'm in the middle of doing Project 12, so I've used the compiler many times before, but never ran into this. My own compiler, which I wrote in project 11, compiles the file without errors.

So:

1. Is there something trivial I'm overlooking?

2. Can you try the above program on your system? Does it compile using the supplied compiler?

3. Any explanation?
Reply | Threaded
Open this post in threaded view
|

Re: Why doesn't this program compile?

WBahn
Administrator
It compiled for me with no problems, both as a single file and also when compiling the entire directory.

You might have a hidden character in your file that didn't survive copying/pasting to the forum post.

Try copying the code from your post and pasting it over the existing code and see what happens.

Reply | Threaded
Open this post in threaded view
|

Re: Why doesn't this program compile?

pguertin
You got it. Thanks! There was an errant 0xc2 character in the file. No idea how it got there. I should have thought of it but I was too busy banging my head against the desk.