dealing with negative variables

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

dealing with negative variables

virote328
lets say we are dealing with an expression and transfering it to xml.  What is the correct version 1 or 2?  I don't really see it said anywhere in the book.

expression is "-foo"

(Version 1)
<expression>
    <term>
        <symbol> - </symbol>
        <identifier> foo </identifier>
    </term>
</expression> 

(version 2)
<expression>
    <symbol> - </symbol>
    <term> 
        <identifier> foo </identifier>
    </term>
</expression>
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: dealing with negative variables

ybakos
The - symbol before an identifier is a unary op. See the pages in the book with the tables listing the rules of the Jack grammar.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: dealing with negative variables

virote328
Well, sir, I understand that it is indeed an unary operator.  I do not see any XML in the book showing how unary operators are being handled.

Luckily I was able to find an example of the "~" operator in the SquareGame.XML file .
And to answer my own question:

expression of "-foo"

<expression>
    <term>
        <symbol> ~ </symbol>
        <term>
            <identifier> foo </identifier>
        </term>
    </term>
</expression>
Loading...