<tokens>
<keyword> class </keyword>
<identifier> Main </identifier>
<symbol> { </symbol>
<keyword> function </keyword>
<keyword> void </keyword>
<identifier> main </identifier>
<symbol> ( </symbol>
<symbol> ) </symbol>
<symbol> { </symbol>
<keyword> var </keyword>
<keyword> int </keyword>
<identifier> value </identifier>
<symbol> ; </symbol>
<keyword> do </keyword>
<identifier> Main </identifier>
<symbol> . </symbol>
<identifier> fillMemory </identifier>
<symbol> ( </symbol>
<integerConstant> 8001 </integerConstant>
<symbol> , </symbol>
<integerConstant> 16 </integerConstant>
<symbol> , </symbol>
<symbol> - </symbol>
<integerConstant> 1 </integerConstant>
<symbol> ) </symbol>
<symbol> ; </symbol>
<keyword> let </keyword>
<identifier> value </identifier>
<symbol> = </symbol>
<identifier> Memory </identifier>
<symbol> . </symbol>
<identifier> peek </identifier>
<symbol> ( </symbol>
<integerConstant> 8000 </integerConstant>
<symbol> ) </symbol>
<symbol> ; </symbol>
<keyword> do </keyword>
<identifier> Main </identifier>
<symbol> . </symbol>
<identifier> convert </identifier>
<symbol> ( </symbol>
<identifier> value </identifier>
<symbol> ) </symbol>
<symbol> ; </symbol>
<keyword> return </keyword>
<symbol> ; </symbol>
<symbol> } </symbol>
<keyword> function </keyword>
<keyword> void </keyword>
<identifier> convert </identifier>
<symbol> ( </symbol>
<keyword> int </keyword>
<identifier> value </identifier>
<symbol> ) </symbol>
<symbol> { </symbol>
<keyword> var </keyword>
<keyword> int </keyword>
<identifier> mask </identifier>
<symbol> , </symbol>
<identifier> position </identifier>
<symbol> ; </symbol>
<keyword> var </keyword>
<keyword> boolean </keyword>
<identifier> loop </identifier>
<symbol> ; </symbol>
<keyword> let </keyword>
<identifier> loop </identifier>
<symbol> = </symbol>
<keyword> true </keyword>
<symbol> ; </symbol>
<keyword> while </keyword>
<symbol> ( </symbol>
<identifier> loop </identifier>
<symbol> ) </symbol>
<symbol> { </symbol>
<keyword> let </keyword>
<identifier> position </identifier>
<symbol> = </symbol>
<identifier> position </identifier>
<symbol> + </symbol>
<integerConstant> 1 </integerConstant>
<symbol> ; </symbol>
<keyword> let </keyword>
<identifier> mask </identifier>
<symbol> = </symbol>
<identifier> Main </identifier>
<symbol> . </symbol>
<identifier> nextMask </identifier>
<symbol> ( </symbol>
<identifier> mask </identifier>
<symbol> ) </symbol>
<symbol> ; </symbol>
<keyword> if </keyword>
<symbol> ( </symbol>
<symbol> ~ </symbol>
<symbol> ( </symbol>
<identifier> position </identifier>
<symbol> &gt; </symbol>
<integerConstant> 16 </integerConstant>
<symbol> ) </symbol>
<symbol> ) </symbol>
<symbol> { </symbol>
<keyword> if </keyword>
<symbol> ( </symbol>
<symbol> ~ </symbol>
<symbol> ( </symbol>
<symbol> ( </symbol>
<identifier> value </identifier>
<symbol> &amp; </symbol>
<identifier> mask </identifier>
<symbol> ) </symbol>
<symbol> = </symbol>
<integerConstant> 0 </integerConstant>
<symbol> ) </symbol>
<symbol> ) </symbol>
<symbol> { </symbol>
<keyword> do </keyword>
<identifier> Memory </identifier>
<symbol> . </symbol>
<identifier> poke </identifier>
<symbol> ( </symbol>
<integerConstant> 8000 </integerConstant>
<symbol> + </symbol>
<identifier> position </identifier>
<symbol> , </symbol>
<integerConstant> 1 </integerConstant>
<symbol> ) </symbol>
<symbol> ; </symbol>
<symbol> } </symbol>
<keyword> else </keyword>
<symbol> { </symbol>
<keyword> do </keyword>
<identifier> Memory </identifier>
<symbol> . </symbol>
<identifier> poke </identifier>
<symbol> ( </symbol>
<integerConstant> 8000 </integerConstant>
<symbol> + </symbol>
<identifier> position </identifier>
<symbol> , </symbol>
<integerConstant> 0 </integerConstant>
<symbol> ) </symbol>
<symbol> ; </symbol>
<symbol> } </symbol>
<symbol> } </symbol>
<keyword> else </keyword>
<symbol> { </symbol>
<keyword> let </keyword>
<identifier> loop </identifier>
<symbol> = </symbol>
<keyword> false </keyword>
<symbol> ; </symbol>
<symbol> } </symbol>
<symbol> } </symbol>
<keyword> return </keyword>
<symbol> ; </symbol>
<symbol> } </symbol>
<keyword> function </keyword>
<keyword> int </keyword>
<identifier> nextMask </identifier>
<symbol> ( </symbol>
<keyword> int </keyword>
<identifier> mask </identifier>
<symbol> ) </symbol>
<symbol> { </symbol>
<keyword> if </keyword>
<symbol> ( </symbol>
<identifier> mask </identifier>
<symbol> = </symbol>
<integerConstant> 0 </integerConstant>
<symbol> ) </symbol>
<symbol> { </symbol>
<keyword> return </keyword>
<integerConstant> 1 </integerConstant>
<symbol> ; </symbol>
<symbol> } </symbol>
<keyword> else </keyword>
<symbol> { </symbol>
<keyword> return </keyword>
<identifier> mask </identifier>
<symbol> * </symbol>
<integerConstant> 2 </integerConstant>
<symbol> ; </symbol>
<symbol> } </symbol>
<symbol> } </symbol>
<keyword> function </keyword>
<keyword> void </keyword>
<identifier> fillMemory </identifier>
<symbol> ( </symbol>
<keyword> int </keyword>
<identifier> startAddress </identifier>
<symbol> , </symbol>
<keyword> int </keyword>
<identifier> length </identifier>
<symbol> , </symbol>
<keyword> int </keyword>
<identifier> value </identifier>
<symbol> ) </symbol>
<symbol> { </symbol>
<keyword> while </keyword>
<symbol> ( </symbol>
<identifier> length </identifier>
<symbol> &gt; </symbol>
<integerConstant> 0 </integerConstant>
<symbol> ) </symbol>
<symbol> { </symbol>
<keyword> do </keyword>
<identifier> Memory </identifier>
<symbol> . </symbol>
<identifier> poke </identifier>
<symbol> ( </symbol>
<identifier> startAddress </identifier>
<symbol> , </symbol>
<identifier> value </identifier>
<symbol> ) </symbol>
<symbol> ; </symbol>
<keyword> let </keyword>
<identifier> length </identifier>
<symbol> = </symbol>
<identifier> length </identifier>
<symbol> - </symbol>
<integerConstant> 1 </integerConstant>
<symbol> ; </symbol>
<keyword> let </keyword>
<identifier> startAddress </identifier>
<symbol> = </symbol>
<identifier> startAddress </identifier>
<symbol> + </symbol>
<integerConstant> 1 </integerConstant>
<symbol> ; </symbol>
<symbol> } </symbol>
<keyword> return </keyword>
<symbol> ; </symbol>
<symbol> } </symbol>
<symbol> } </symbol>
</tokens>
