let this = value;

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

let this = value;

John
After writing my OS routines I was looking at the supplied OS routines to see how I did.  When decoding some of the vm statements it appears that one of the source lines must have been "let this = Memory.alloc(3);"  and later "return this".  I won't say what .vm files I was looking at since I don't want to give away any code.  In my version I had "var Array value;" and later "return value;".  My question is whether "let this = expression" is considered a valid statement or am decoding the vm code wrong?  Nothing in the JACK language definition seems to prevent this, but it doesn't really seem to allow it either.

Thanks
Reply | Threaded
Open this post in threaded view
|

Re: let this = value;

John
I forgot to mention I am unable to run the supplied JACK compiler to see if the statement is valid because I get a program not found message whenever I try to execute JackCompiler.bat so I only have my JACK compiler and it is definitely illegal in my version.
Reply | Threaded
Open this post in threaded view
|

Re: let this = value;

John
Upon further study of my vm code and the supplied vm code I noticed that I was indeed decoding the supplied vm code wrong.  My vm code also produced what I would have interpreted as "let this = Memory.alloc(3);" but was instead assigning a value to the first "field" in the class.

John
Reply | Threaded
Open this post in threaded view
|

Re: let this = value;

cadet1620
Administrator
The supplied compiler reports
    In Test.jack (line 4): In subroutine foo: Expected field, parameter
    or local or static variable name
in response to "let this = Memory.alloc(3);"

--Mark
Reply | Threaded
Open this post in threaded view
|

Re: let this = value;

WBahn
Administrator
In reply to this post by John
An examination of the grammar shows that the only things that can be lvalues for an assignment statement are

varName = ... ;
varName[...] = ... ;

And varName has to be an identifier token, which rules out using 'this' since it is a keyword token.