How to use doStatement method in autotest

Best Python code snippet using autotest_python

jack_compiler_test.py

Source:jack_compiler_test.py Github

copy

Full Screen

1#!/usr/bin/python2#3# Copyright (c) 2011 Ivan Vladimirov Ivanov (ivan.vladimirov.ivanov@gmail.com)4#5# Permission is hereby granted, free of charge, to any person obtaining a copy6# of this software and associated documentation files (the "Software"), to7# deal in the Software without restriction, including without limitation8# the rights to use, copy, modify, merge, publish, distribute, sublicense,9# and/or sell copies of the Software, and to permit persons to whom the10# Software is furnished to do so, subject to the following conditions:11#12# The above copyright notice and this permission notice shall be included13# in all copies or substantial portions of the Software.14#15# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS16# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,17# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL18# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR19# OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,20# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR21# OTHER DEALINGS IN THE SOFTWARE.22__author__ = "Ivan Vladimirov Ivanov (ivan.vladimirov.ivanov@gmail.com)"23import jack_to_vm_compiler24import jack_xml_serializer25import lexical_analyser26import syntax_analyser27def RemoveBlanks(xml):28 xml = xml.replace(" ", "")29 xml = xml.replace("\n", "")30 xml = xml.replace("\r", "")31 xml = xml.replace("\t", "")32 return xml33def Compare(xml_1, xml_2):34 return RemoveBlanks(xml_1) == RemoveBlanks(xml_2)35 36class TestJackCompiler(unittest.TestCase):37 def _CompileToXML(self, program):38 return jack_xml_serializer.JackXMLSerializer().Serialize(39 syntax_analyser.SyntaxAnalyser.Parse(40 lexical_analyser.LexicalAnalyser.Tokenize(program)))41 def _CompileToHackVM(self, program):42 return jack_to_vm_compiler.JackToVMCompiler().CompileVMCode(43 syntax_analyser.SyntaxAnalyser.Parse(44 lexical_analyser.LexicalAnalyser.Tokenize(program)))45 def testCompilation(self):46 main_jack = """47// This file is part of the materials accompanying the book 48// "The Elements of Computing Systems" by Nisan and Schocken, 49// MIT Press. Book site: www.idc.ac.il/tecs50// File name: projects/10/Square/Main.jack51/**52 * The Main class initializes a new Square Dance game and starts it.53 */54class Main {55 /** Initializes a new game and starts it. */ 56 function void main() {57 var SquareGame game;58 let game = SquareGame.new();59 do game.run();60 do game.dispose();61 return;62 }63}"""64 square_jack = """65// This file is part of the materials accompanying the book 66// "The Elements of Computing Systems" by Nisan and Schocken, 67// MIT Press. Book site: www.idc.ac.il/tecs68// File name: projects/10/Square/Square.jack69/**70 * The Square class implements a graphic square. A graphic square 71 * has a location on the screen and a size. It also has methods 72 * for drawing, erasing, moving on the screen, and changing its size.73 */74class Square {75 // Location on the screen76 field int x, y;77 // The size of the square78 field int size;79 /** Constructs a new square with a given location and size. */80 constructor Square new(int Ax, int Ay, int Asize) {81 let x = Ax;82 let y = Ay;83 let size = Asize;84 do draw();85 return this;86 }87 /** Deallocates the object's memory. */88 method void dispose() {89 do Memory.deAlloc(this);90 return;91 }92 /** Draws the square on the screen. */93 method void draw() {94 do Screen.setColor(true);95 do Screen.drawRectangle(x, y, x + size, y + size);96 return;97 }98 /** Erases the square from the screen. */99 method void erase() {100 do Screen.setColor(false);101 do Screen.drawRectangle(x, y, x + size, y + size);102 return;103 }104 /** Increments the size by 2. */105 method void incSize() {106 if (((y + size) < 254) & ((x + size) < 510)) {107 do erase();108 let size = size + 2;109 do draw();110 }111 return;112 }113 /** Decrements the size by 2. */114 method void decSize() {115 if (size > 2) {116 do erase();117 let size = size - 2;118 do draw();119 }120 return;121 }122 /** Moves up by 2. */123 method void moveUp() {124 if (y > 1) {125 do Screen.setColor(false);126 do Screen.drawRectangle(x, (y + size) - 1, x + size, y + size);127 let y = y - 2;128 do Screen.setColor(true);129 do Screen.drawRectangle(x, y, x + size, y + 1);130 }131 return;132 }133 /** Moves down by 2. */134 method void moveDown() {135 if ((y + size) < 254) {136 do Screen.setColor(false);137 do Screen.drawRectangle(x, y, x + size, y + 1);138 let y = y + 2;139 do Screen.setColor(true);140 do Screen.drawRectangle(x, (y + size) - 1, x + size, y + size);141 }142 return;143 }144 /** Moves left by 2. */145 method void moveLeft() {146 if (x > 1) {147 do Screen.setColor(false);148 do Screen.drawRectangle((x + size) - 1, y, x + size, y + size);149 let x = x - 2;150 do Screen.setColor(true);151 do Screen.drawRectangle(x, y, x + 1, y + size);152 }153 return;154 }155 /** Moves right by 2. */156 method void moveRight() {157 if ((x + size) < 510) {158 do Screen.setColor(false);159 do Screen.drawRectangle(x, y, x + 1, y + size);160 let x = x + 2;161 do Screen.setColor(true);162 do Screen.drawRectangle((x + size) - 1, y, x + size, y + size);163 }164 return;165 }166}167"""168 square_game_jack = """169// This file is part of the materials accompanying the book 170// "The Elements of Computing Systems" by Nisan and Schocken, 171// MIT Press. Book site: www.idc.ac.il/tecs172// File name: projects/10/Square/SquareGame.jack173/**174 * The SquareDance class implements the Square Dance game.175 * In this game you can move a black square around the screen and176 * change its size during the movement.177 * In the beggining, the square is located at the top left corner.178 * Use the arrow keys to move the square.179 * Use 'z' & 'x' to decrement & increment the size.180 * Use 'q' to quit.181 */182class SquareGame {183 // The square184 field Square square;185 // The square's movement direction186 field int direction; // 0=none,1=up,2=down,3=left,4=right187 /** Constructs a new Square Game. */188 constructor SquareGame new() {189 let square = Square.new(0, 0, 30);190 let direction = 0;191 return this;192 }193 /** Deallocates the object's memory. */194 method void dispose() {195 do square.dispose();196 do Memory.deAlloc(this);197 return;198 }199 /** Starts the game. Handles inputs from the user that controls200 * the square movement direction and size. */201 method void run() {202 var char key;203 var boolean exit;204 let exit = false;205 while (~exit) {206 // waits for a key to be pressed.207 while (key = 0) {208 let key = Keyboard.keyPressed();209 do moveSquare();210 }211 if (key = 81) {212 let exit = true;213 }214 if (key = 90) {215 do square.decSize();216 }217 if (key = 88) {218 do square.incSize();219 }220 if (key = 131) {221 let direction = 1;222 }223 if (key = 133) {224 let direction = 2;225 }226 if (key = 130) {227 let direction = 3;228 }229 if (key = 132) {230 let direction = 4;231 }232 // waits for the key to be released.233 while (~(key = 0)) {234 let key = Keyboard.keyPressed();235 do moveSquare();236 }237 }238 239 return;240 }241 /** Moves the square by 2 in the current direction. */242 method void moveSquare() {243 if (direction = 1) {244 do square.moveUp();245 }246 if (direction = 2) {247 do square.moveDown();248 }249 if (direction = 3) {250 do square.moveLeft();251 }252 if (direction = 4) {253 do square.moveRight();254 }255 do Sys.wait(5); // Delays the next movement.256 return;257 }258}259"""260 main_xml = """261<class>262 <keyword> class </keyword>263 <identifier> Main </identifier>264 <symbol> { </symbol>265 <subroutineDec>266 <keyword> function </keyword>267 <keyword> void </keyword>268 <identifier> main </identifier>269 <symbol> ( </symbol>270 <parameterList>271 </parameterList>272 <symbol> ) </symbol>273 <subroutineBody>274 <symbol> { </symbol>275 <varDec>276 <keyword> var </keyword>277 <identifier> SquareGame </identifier>278 <identifier> game </identifier>279 <symbol> ; </symbol>280 </varDec>281 <statements>282 <letStatement>283 <keyword> let </keyword>284 <identifier> game </identifier>285 <symbol> = </symbol>286 <expression>287 <term>288 <identifier> SquareGame </identifier>289 <symbol> . </symbol>290 <identifier> new </identifier>291 <symbol> ( </symbol>292 <expressionList>293 </expressionList>294 <symbol> ) </symbol>295 </term>296 </expression>297 <symbol> ; </symbol>298 </letStatement>299 <doStatement>300 <keyword> do </keyword>301 <identifier> game </identifier>302 <symbol> . </symbol>303 <identifier> run </identifier>304 <symbol> ( </symbol>305 <expressionList>306 </expressionList>307 <symbol> ) </symbol>308 <symbol> ; </symbol>309 </doStatement>310 <doStatement>311 <keyword> do </keyword>312 <identifier> game </identifier>313 <symbol> . </symbol>314 <identifier> dispose </identifier>315 <symbol> ( </symbol>316 <expressionList>317 </expressionList>318 <symbol> ) </symbol>319 <symbol> ; </symbol>320 </doStatement>321 <returnStatement>322 <keyword> return </keyword>323 <symbol> ; </symbol>324 </returnStatement>325 </statements>326 <symbol> } </symbol>327 </subroutineBody>328 </subroutineDec>329 <symbol> } </symbol>330</class>331"""332 square_xml = """333<class>334 <keyword> class </keyword>335 <identifier> Square </identifier>336 <symbol> { </symbol>337 <classVarDec>338 <keyword> field </keyword>339 <keyword> int </keyword>340 <identifier> x </identifier>341 <symbol> , </symbol>342 <identifier> y </identifier>343 <symbol> ; </symbol>344 </classVarDec>345 <classVarDec>346 <keyword> field </keyword>347 <keyword> int </keyword>348 <identifier> size </identifier>349 <symbol> ; </symbol>350 </classVarDec>351 <subroutineDec>352 <keyword> constructor </keyword>353 <identifier> Square </identifier>354 <identifier> new </identifier>355 <symbol> ( </symbol>356 <parameterList>357 <keyword> int </keyword>358 <identifier> Ax </identifier>359 <symbol> , </symbol>360 <keyword> int </keyword>361 <identifier> Ay </identifier>362 <symbol> , </symbol>363 <keyword> int </keyword>364 <identifier> Asize </identifier>365 </parameterList>366 <symbol> ) </symbol>367 <subroutineBody>368 <symbol> { </symbol>369 <statements>370 <letStatement>371 <keyword> let </keyword>372 <identifier> x </identifier>373 <symbol> = </symbol>374 <expression>375 <term>376 <identifier> Ax </identifier>377 </term>378 </expression>379 <symbol> ; </symbol>380 </letStatement>381 <letStatement>382 <keyword> let </keyword>383 <identifier> y </identifier>384 <symbol> = </symbol>385 <expression>386 <term>387 <identifier> Ay </identifier>388 </term>389 </expression>390 <symbol> ; </symbol>391 </letStatement>392 <letStatement>393 <keyword> let </keyword>394 <identifier> size </identifier>395 <symbol> = </symbol>396 <expression>397 <term>398 <identifier> Asize </identifier>399 </term>400 </expression>401 <symbol> ; </symbol>402 </letStatement>403 <doStatement>404 <keyword> do </keyword>405 <identifier> draw </identifier>406 <symbol> ( </symbol>407 <expressionList>408 </expressionList>409 <symbol> ) </symbol>410 <symbol> ; </symbol>411 </doStatement>412 <returnStatement>413 <keyword> return </keyword>414 <expression>415 <term>416 <keyword> this </keyword>417 </term>418 </expression>419 <symbol> ; </symbol>420 </returnStatement>421 </statements>422 <symbol> } </symbol>423 </subroutineBody>424 </subroutineDec>425 <subroutineDec>426 <keyword> method </keyword>427 <keyword> void </keyword>428 <identifier> dispose </identifier>429 <symbol> ( </symbol>430 <parameterList>431 </parameterList>432 <symbol> ) </symbol>433 <subroutineBody>434 <symbol> { </symbol>435 <statements>436 <doStatement>437 <keyword> do </keyword>438 <identifier> Memory </identifier>439 <symbol> . </symbol>440 <identifier> deAlloc </identifier>441 <symbol> ( </symbol>442 <expressionList>443 <expression>444 <term>445 <keyword> this </keyword>446 </term>447 </expression>448 </expressionList>449 <symbol> ) </symbol>450 <symbol> ; </symbol>451 </doStatement>452 <returnStatement>453 <keyword> return </keyword>454 <symbol> ; </symbol>455 </returnStatement>456 </statements>457 <symbol> } </symbol>458 </subroutineBody>459 </subroutineDec>460 <subroutineDec>461 <keyword> method </keyword>462 <keyword> void </keyword>463 <identifier> draw </identifier>464 <symbol> ( </symbol>465 <parameterList>466 </parameterList>467 <symbol> ) </symbol>468 <subroutineBody>469 <symbol> { </symbol>470 <statements>471 <doStatement>472 <keyword> do </keyword>473 <identifier> Screen </identifier>474 <symbol> . </symbol>475 <identifier> setColor </identifier>476 <symbol> ( </symbol>477 <expressionList>478 <expression>479 <term>480 <keyword> true </keyword>481 </term>482 </expression>483 </expressionList>484 <symbol> ) </symbol>485 <symbol> ; </symbol>486 </doStatement>487 <doStatement>488 <keyword> do </keyword>489 <identifier> Screen </identifier>490 <symbol> . </symbol>491 <identifier> drawRectangle </identifier>492 <symbol> ( </symbol>493 <expressionList>494 <expression>495 <term>496 <identifier> x </identifier>497 </term>498 </expression>499 <symbol> , </symbol>500 <expression>501 <term>502 <identifier> y </identifier>503 </term>504 </expression>505 <symbol> , </symbol>506 <expression>507 <term>508 <identifier> x </identifier>509 </term>510 <symbol> + </symbol>511 <term>512 <identifier> size </identifier>513 </term>514 </expression>515 <symbol> , </symbol>516 <expression>517 <term>518 <identifier> y </identifier>519 </term>520 <symbol> + </symbol>521 <term>522 <identifier> size </identifier>523 </term>524 </expression>525 </expressionList>526 <symbol> ) </symbol>527 <symbol> ; </symbol>528 </doStatement>529 <returnStatement>530 <keyword> return </keyword>531 <symbol> ; </symbol>532 </returnStatement>533 </statements>534 <symbol> } </symbol>535 </subroutineBody>536 </subroutineDec>537 <subroutineDec>538 <keyword> method </keyword>539 <keyword> void </keyword>540 <identifier> erase </identifier>541 <symbol> ( </symbol>542 <parameterList>543 </parameterList>544 <symbol> ) </symbol>545 <subroutineBody>546 <symbol> { </symbol>547 <statements>548 <doStatement>549 <keyword> do </keyword>550 <identifier> Screen </identifier>551 <symbol> . </symbol>552 <identifier> setColor </identifier>553 <symbol> ( </symbol>554 <expressionList>555 <expression>556 <term>557 <keyword> false </keyword>558 </term>559 </expression>560 </expressionList>561 <symbol> ) </symbol>562 <symbol> ; </symbol>563 </doStatement>564 <doStatement>565 <keyword> do </keyword>566 <identifier> Screen </identifier>567 <symbol> . </symbol>568 <identifier> drawRectangle </identifier>569 <symbol> ( </symbol>570 <expressionList>571 <expression>572 <term>573 <identifier> x </identifier>574 </term>575 </expression>576 <symbol> , </symbol>577 <expression>578 <term>579 <identifier> y </identifier>580 </term>581 </expression>582 <symbol> , </symbol>583 <expression>584 <term>585 <identifier> x </identifier>586 </term>587 <symbol> + </symbol>588 <term>589 <identifier> size </identifier>590 </term>591 </expression>592 <symbol> , </symbol>593 <expression>594 <term>595 <identifier> y </identifier>596 </term>597 <symbol> + </symbol>598 <term>599 <identifier> size </identifier>600 </term>601 </expression>602 </expressionList>603 <symbol> ) </symbol>604 <symbol> ; </symbol>605 </doStatement>606 <returnStatement>607 <keyword> return </keyword>608 <symbol> ; </symbol>609 </returnStatement>610 </statements>611 <symbol> } </symbol>612 </subroutineBody>613 </subroutineDec>614 <subroutineDec>615 <keyword> method </keyword>616 <keyword> void </keyword>617 <identifier> incSize </identifier>618 <symbol> ( </symbol>619 <parameterList>620 </parameterList>621 <symbol> ) </symbol>622 <subroutineBody>623 <symbol> { </symbol>624 <statements>625 <ifStatement>626 <keyword> if </keyword>627 <symbol> ( </symbol>628 <expression>629 <term>630 <symbol> ( </symbol>631 <expression>632 <term>633 <symbol> ( </symbol>634 <expression>635 <term>636 <identifier> y </identifier>637 </term>638 <symbol> + </symbol>639 <term>640 <identifier> size </identifier>641 </term>642 </expression>643 <symbol> ) </symbol>644 </term>645 <symbol> &lt; </symbol>646 <term>647 <integerConstant> 254 </integerConstant>648 </term>649 </expression>650 <symbol> ) </symbol>651 </term>652 <symbol> &amp; </symbol>653 <term>654 <symbol> ( </symbol>655 <expression>656 <term>657 <symbol> ( </symbol>658 <expression>659 <term>660 <identifier> x </identifier>661 </term>662 <symbol> + </symbol>663 <term>664 <identifier> size </identifier>665 </term>666 </expression>667 <symbol> ) </symbol>668 </term>669 <symbol> &lt; </symbol>670 <term>671 <integerConstant> 510 </integerConstant>672 </term>673 </expression>674 <symbol> ) </symbol>675 </term>676 </expression>677 <symbol> ) </symbol>678 <symbol> { </symbol>679 <statements>680 <doStatement>681 <keyword> do </keyword>682 <identifier> erase </identifier>683 <symbol> ( </symbol>684 <expressionList>685 </expressionList>686 <symbol> ) </symbol>687 <symbol> ; </symbol>688 </doStatement>689 <letStatement>690 <keyword> let </keyword>691 <identifier> size </identifier>692 <symbol> = </symbol>693 <expression>694 <term>695 <identifier> size </identifier>696 </term>697 <symbol> + </symbol>698 <term>699 <integerConstant> 2 </integerConstant>700 </term>701 </expression>702 <symbol> ; </symbol>703 </letStatement>704 <doStatement>705 <keyword> do </keyword>706 <identifier> draw </identifier>707 <symbol> ( </symbol>708 <expressionList>709 </expressionList>710 <symbol> ) </symbol>711 <symbol> ; </symbol>712 </doStatement>713 </statements>714 <symbol> } </symbol>715 </ifStatement>716 <returnStatement>717 <keyword> return </keyword>718 <symbol> ; </symbol>719 </returnStatement>720 </statements>721 <symbol> } </symbol>722 </subroutineBody>723 </subroutineDec>724 <subroutineDec>725 <keyword> method </keyword>726 <keyword> void </keyword>727 <identifier> decSize </identifier>728 <symbol> ( </symbol>729 <parameterList>730 </parameterList>731 <symbol> ) </symbol>732 <subroutineBody>733 <symbol> { </symbol>734 <statements>735 <ifStatement>736 <keyword> if </keyword>737 <symbol> ( </symbol>738 <expression>739 <term>740 <identifier> size </identifier>741 </term>742 <symbol> &gt; </symbol>743 <term>744 <integerConstant> 2 </integerConstant>745 </term>746 </expression>747 <symbol> ) </symbol>748 <symbol> { </symbol>749 <statements>750 <doStatement>751 <keyword> do </keyword>752 <identifier> erase </identifier>753 <symbol> ( </symbol>754 <expressionList>755 </expressionList>756 <symbol> ) </symbol>757 <symbol> ; </symbol>758 </doStatement>759 <letStatement>760 <keyword> let </keyword>761 <identifier> size </identifier>762 <symbol> = </symbol>763 <expression>764 <term>765 <identifier> size </identifier>766 </term>767 <symbol> - </symbol>768 <term>769 <integerConstant> 2 </integerConstant>770 </term>771 </expression>772 <symbol> ; </symbol>773 </letStatement>774 <doStatement>775 <keyword> do </keyword>776 <identifier> draw </identifier>777 <symbol> ( </symbol>778 <expressionList>779 </expressionList>780 <symbol> ) </symbol>781 <symbol> ; </symbol>782 </doStatement>783 </statements>784 <symbol> } </symbol>785 </ifStatement>786 <returnStatement>787 <keyword> return </keyword>788 <symbol> ; </symbol>789 </returnStatement>790 </statements>791 <symbol> } </symbol>792 </subroutineBody>793 </subroutineDec>794 <subroutineDec>795 <keyword> method </keyword>796 <keyword> void </keyword>797 <identifier> moveUp </identifier>798 <symbol> ( </symbol>799 <parameterList>800 </parameterList>801 <symbol> ) </symbol>802 <subroutineBody>803 <symbol> { </symbol>804 <statements>805 <ifStatement>806 <keyword> if </keyword>807 <symbol> ( </symbol>808 <expression>809 <term>810 <identifier> y </identifier>811 </term>812 <symbol> &gt; </symbol>813 <term>814 <integerConstant> 1 </integerConstant>815 </term>816 </expression>817 <symbol> ) </symbol>818 <symbol> { </symbol>819 <statements>820 <doStatement>821 <keyword> do </keyword>822 <identifier> Screen </identifier>823 <symbol> . </symbol>824 <identifier> setColor </identifier>825 <symbol> ( </symbol>826 <expressionList>827 <expression>828 <term>829 <keyword> false </keyword>830 </term>831 </expression>832 </expressionList>833 <symbol> ) </symbol>834 <symbol> ; </symbol>835 </doStatement>836 <doStatement>837 <keyword> do </keyword>838 <identifier> Screen </identifier>839 <symbol> . </symbol>840 <identifier> drawRectangle </identifier>841 <symbol> ( </symbol>842 <expressionList>843 <expression>844 <term>845 <identifier> x </identifier>846 </term>847 </expression>848 <symbol> , </symbol>849 <expression>850 <term>851 <symbol> ( </symbol>852 <expression>853 <term>854 <identifier> y </identifier>855 </term>856 <symbol> + </symbol>857 <term>858 <identifier> size </identifier>859 </term>860 </expression>861 <symbol> ) </symbol>862 </term>863 <symbol> - </symbol>864 <term>865 <integerConstant> 1 </integerConstant>866 </term>867 </expression>868 <symbol> , </symbol>869 <expression>870 <term>871 <identifier> x </identifier>872 </term>873 <symbol> + </symbol>874 <term>875 <identifier> size </identifier>876 </term>877 </expression>878 <symbol> , </symbol>879 <expression>880 <term>881 <identifier> y </identifier>882 </term>883 <symbol> + </symbol>884 <term>885 <identifier> size </identifier>886 </term>887 </expression>888 </expressionList>889 <symbol> ) </symbol>890 <symbol> ; </symbol>891 </doStatement>892 <letStatement>893 <keyword> let </keyword>894 <identifier> y </identifier>895 <symbol> = </symbol>896 <expression>897 <term>898 <identifier> y </identifier>899 </term>900 <symbol> - </symbol>901 <term>902 <integerConstant> 2 </integerConstant>903 </term>904 </expression>905 <symbol> ; </symbol>906 </letStatement>907 <doStatement>908 <keyword> do </keyword>909 <identifier> Screen </identifier>910 <symbol> . </symbol>911 <identifier> setColor </identifier>912 <symbol> ( </symbol>913 <expressionList>914 <expression>915 <term>916 <keyword> true </keyword>917 </term>918 </expression>919 </expressionList>920 <symbol> ) </symbol>921 <symbol> ; </symbol>922 </doStatement>923 <doStatement>924 <keyword> do </keyword>925 <identifier> Screen </identifier>926 <symbol> . </symbol>927 <identifier> drawRectangle </identifier>928 <symbol> ( </symbol>929 <expressionList>930 <expression>931 <term>932 <identifier> x </identifier>933 </term>934 </expression>935 <symbol> , </symbol>936 <expression>937 <term>938 <identifier> y </identifier>939 </term>940 </expression>941 <symbol> , </symbol>942 <expression>943 <term>944 <identifier> x </identifier>945 </term>946 <symbol> + </symbol>947 <term>948 <identifier> size </identifier>949 </term>950 </expression>951 <symbol> , </symbol>952 <expression>953 <term>954 <identifier> y </identifier>955 </term>956 <symbol> + </symbol>957 <term>958 <integerConstant> 1 </integerConstant>959 </term>960 </expression>961 </expressionList>962 <symbol> ) </symbol>963 <symbol> ; </symbol>964 </doStatement>965 </statements>966 <symbol> } </symbol>967 </ifStatement>968 <returnStatement>969 <keyword> return </keyword>970 <symbol> ; </symbol>971 </returnStatement>972 </statements>973 <symbol> } </symbol>974 </subroutineBody>975 </subroutineDec>976 <subroutineDec>977 <keyword> method </keyword>978 <keyword> void </keyword>979 <identifier> moveDown </identifier>980 <symbol> ( </symbol>981 <parameterList>982 </parameterList>983 <symbol> ) </symbol>984 <subroutineBody>985 <symbol> { </symbol>986 <statements>987 <ifStatement>988 <keyword> if </keyword>989 <symbol> ( </symbol>990 <expression>991 <term>992 <symbol> ( </symbol>993 <expression>994 <term>995 <identifier> y </identifier>996 </term>997 <symbol> + </symbol>998 <term>999 <identifier> size </identifier>1000 </term>1001 </expression>1002 <symbol> ) </symbol>1003 </term>1004 <symbol> &lt; </symbol>1005 <term>1006 <integerConstant> 254 </integerConstant>1007 </term>1008 </expression>1009 <symbol> ) </symbol>1010 <symbol> { </symbol>1011 <statements>1012 <doStatement>1013 <keyword> do </keyword>1014 <identifier> Screen </identifier>1015 <symbol> . </symbol>1016 <identifier> setColor </identifier>1017 <symbol> ( </symbol>1018 <expressionList>1019 <expression>1020 <term>1021 <keyword> false </keyword>1022 </term>1023 </expression>1024 </expressionList>1025 <symbol> ) </symbol>1026 <symbol> ; </symbol>1027 </doStatement>1028 <doStatement>1029 <keyword> do </keyword>1030 <identifier> Screen </identifier>1031 <symbol> . </symbol>1032 <identifier> drawRectangle </identifier>1033 <symbol> ( </symbol>1034 <expressionList>1035 <expression>1036 <term>1037 <identifier> x </identifier>1038 </term>1039 </expression>1040 <symbol> , </symbol>1041 <expression>1042 <term>1043 <identifier> y </identifier>1044 </term>1045 </expression>1046 <symbol> , </symbol>1047 <expression>1048 <term>1049 <identifier> x </identifier>1050 </term>1051 <symbol> + </symbol>1052 <term>1053 <identifier> size </identifier>1054 </term>1055 </expression>1056 <symbol> , </symbol>1057 <expression>1058 <term>1059 <identifier> y </identifier>1060 </term>1061 <symbol> + </symbol>1062 <term>1063 <integerConstant> 1 </integerConstant>1064 </term>1065 </expression>1066 </expressionList>1067 <symbol> ) </symbol>1068 <symbol> ; </symbol>1069 </doStatement>1070 <letStatement>1071 <keyword> let </keyword>1072 <identifier> y </identifier>1073 <symbol> = </symbol>1074 <expression>1075 <term>1076 <identifier> y </identifier>1077 </term>1078 <symbol> + </symbol>1079 <term>1080 <integerConstant> 2 </integerConstant>1081 </term>1082 </expression>1083 <symbol> ; </symbol>1084 </letStatement>1085 <doStatement>1086 <keyword> do </keyword>1087 <identifier> Screen </identifier>1088 <symbol> . </symbol>1089 <identifier> setColor </identifier>1090 <symbol> ( </symbol>1091 <expressionList>1092 <expression>1093 <term>1094 <keyword> true </keyword>1095 </term>1096 </expression>1097 </expressionList>1098 <symbol> ) </symbol>1099 <symbol> ; </symbol>1100 </doStatement>1101 <doStatement>1102 <keyword> do </keyword>1103 <identifier> Screen </identifier>1104 <symbol> . </symbol>1105 <identifier> drawRectangle </identifier>1106 <symbol> ( </symbol>1107 <expressionList>1108 <expression>1109 <term>1110 <identifier> x </identifier>1111 </term>1112 </expression>1113 <symbol> , </symbol>1114 <expression>1115 <term>1116 <symbol> ( </symbol>1117 <expression>1118 <term>1119 <identifier> y </identifier>1120 </term>1121 <symbol> + </symbol>1122 <term>1123 <identifier> size </identifier>1124 </term>1125 </expression>1126 <symbol> ) </symbol>1127 </term>1128 <symbol> - </symbol>1129 <term>1130 <integerConstant> 1 </integerConstant>1131 </term>1132 </expression>1133 <symbol> , </symbol>1134 <expression>1135 <term>1136 <identifier> x </identifier>1137 </term>1138 <symbol> + </symbol>1139 <term>1140 <identifier> size </identifier>1141 </term>1142 </expression>1143 <symbol> , </symbol>1144 <expression>1145 <term>1146 <identifier> y </identifier>1147 </term>1148 <symbol> + </symbol>1149 <term>1150 <identifier> size </identifier>1151 </term>1152 </expression>1153 </expressionList>1154 <symbol> ) </symbol>1155 <symbol> ; </symbol>1156 </doStatement>1157 </statements>1158 <symbol> } </symbol>1159 </ifStatement>1160 <returnStatement>1161 <keyword> return </keyword>1162 <symbol> ; </symbol>1163 </returnStatement>1164 </statements>1165 <symbol> } </symbol>1166 </subroutineBody>1167 </subroutineDec>1168 <subroutineDec>1169 <keyword> method </keyword>1170 <keyword> void </keyword>1171 <identifier> moveLeft </identifier>1172 <symbol> ( </symbol>1173 <parameterList>1174 </parameterList>1175 <symbol> ) </symbol>1176 <subroutineBody>1177 <symbol> { </symbol>1178 <statements>1179 <ifStatement>1180 <keyword> if </keyword>1181 <symbol> ( </symbol>1182 <expression>1183 <term>1184 <identifier> x </identifier>1185 </term>1186 <symbol> &gt; </symbol>1187 <term>1188 <integerConstant> 1 </integerConstant>1189 </term>1190 </expression>1191 <symbol> ) </symbol>1192 <symbol> { </symbol>1193 <statements>1194 <doStatement>1195 <keyword> do </keyword>1196 <identifier> Screen </identifier>1197 <symbol> . </symbol>1198 <identifier> setColor </identifier>1199 <symbol> ( </symbol>1200 <expressionList>1201 <expression>1202 <term>1203 <keyword> false </keyword>1204 </term>1205 </expression>1206 </expressionList>1207 <symbol> ) </symbol>1208 <symbol> ; </symbol>1209 </doStatement>1210 <doStatement>1211 <keyword> do </keyword>1212 <identifier> Screen </identifier>1213 <symbol> . </symbol>1214 <identifier> drawRectangle </identifier>1215 <symbol> ( </symbol>1216 <expressionList>1217 <expression>1218 <term>1219 <symbol> ( </symbol>1220 <expression>1221 <term>1222 <identifier> x </identifier>1223 </term>1224 <symbol> + </symbol>1225 <term>1226 <identifier> size </identifier>1227 </term>1228 </expression>1229 <symbol> ) </symbol>1230 </term>1231 <symbol> - </symbol>1232 <term>1233 <integerConstant> 1 </integerConstant>1234 </term>1235 </expression>1236 <symbol> , </symbol>1237 <expression>1238 <term>1239 <identifier> y </identifier>1240 </term>1241 </expression>1242 <symbol> , </symbol>1243 <expression>1244 <term>1245 <identifier> x </identifier>1246 </term>1247 <symbol> + </symbol>1248 <term>1249 <identifier> size </identifier>1250 </term>1251 </expression>1252 <symbol> , </symbol>1253 <expression>1254 <term>1255 <identifier> y </identifier>1256 </term>1257 <symbol> + </symbol>1258 <term>1259 <identifier> size </identifier>1260 </term>1261 </expression>1262 </expressionList>1263 <symbol> ) </symbol>1264 <symbol> ; </symbol>1265 </doStatement>1266 <letStatement>1267 <keyword> let </keyword>1268 <identifier> x </identifier>1269 <symbol> = </symbol>1270 <expression>1271 <term>1272 <identifier> x </identifier>1273 </term>1274 <symbol> - </symbol>1275 <term>1276 <integerConstant> 2 </integerConstant>1277 </term>1278 </expression>1279 <symbol> ; </symbol>1280 </letStatement>1281 <doStatement>1282 <keyword> do </keyword>1283 <identifier> Screen </identifier>1284 <symbol> . </symbol>1285 <identifier> setColor </identifier>1286 <symbol> ( </symbol>1287 <expressionList>1288 <expression>1289 <term>1290 <keyword> true </keyword>1291 </term>1292 </expression>1293 </expressionList>1294 <symbol> ) </symbol>1295 <symbol> ; </symbol>1296 </doStatement>1297 <doStatement>1298 <keyword> do </keyword>1299 <identifier> Screen </identifier>1300 <symbol> . </symbol>1301 <identifier> drawRectangle </identifier>1302 <symbol> ( </symbol>1303 <expressionList>1304 <expression>1305 <term>1306 <identifier> x </identifier>1307 </term>1308 </expression>1309 <symbol> , </symbol>1310 <expression>1311 <term>1312 <identifier> y </identifier>1313 </term>1314 </expression>1315 <symbol> , </symbol>1316 <expression>1317 <term>1318 <identifier> x </identifier>1319 </term>1320 <symbol> + </symbol>1321 <term>1322 <integerConstant> 1 </integerConstant>1323 </term>1324 </expression>1325 <symbol> , </symbol>1326 <expression>1327 <term>1328 <identifier> y </identifier>1329 </term>1330 <symbol> + </symbol>1331 <term>1332 <identifier> size </identifier>1333 </term>1334 </expression>1335 </expressionList>1336 <symbol> ) </symbol>1337 <symbol> ; </symbol>1338 </doStatement>1339 </statements>1340 <symbol> } </symbol>1341 </ifStatement>1342 <returnStatement>1343 <keyword> return </keyword>1344 <symbol> ; </symbol>1345 </returnStatement>1346 </statements>1347 <symbol> } </symbol>1348 </subroutineBody>1349 </subroutineDec>1350 <subroutineDec>1351 <keyword> method </keyword>1352 <keyword> void </keyword>1353 <identifier> moveRight </identifier>1354 <symbol> ( </symbol>1355 <parameterList>1356 </parameterList>1357 <symbol> ) </symbol>1358 <subroutineBody>1359 <symbol> { </symbol>1360 <statements>1361 <ifStatement>1362 <keyword> if </keyword>1363 <symbol> ( </symbol>1364 <expression>1365 <term>1366 <symbol> ( </symbol>1367 <expression>1368 <term>1369 <identifier> x </identifier>1370 </term>1371 <symbol> + </symbol>1372 <term>1373 <identifier> size </identifier>1374 </term>1375 </expression>1376 <symbol> ) </symbol>1377 </term>1378 <symbol> &lt; </symbol>1379 <term>1380 <integerConstant> 510 </integerConstant>1381 </term>1382 </expression>1383 <symbol> ) </symbol>1384 <symbol> { </symbol>1385 <statements>1386 <doStatement>1387 <keyword> do </keyword>1388 <identifier> Screen </identifier>1389 <symbol> . </symbol>1390 <identifier> setColor </identifier>1391 <symbol> ( </symbol>1392 <expressionList>1393 <expression>1394 <term>1395 <keyword> false </keyword>1396 </term>1397 </expression>1398 </expressionList>1399 <symbol> ) </symbol>1400 <symbol> ; </symbol>1401 </doStatement>1402 <doStatement>1403 <keyword> do </keyword>1404 <identifier> Screen </identifier>1405 <symbol> . </symbol>1406 <identifier> drawRectangle </identifier>1407 <symbol> ( </symbol>1408 <expressionList>1409 <expression>1410 <term>1411 <identifier> x </identifier>1412 </term>1413 </expression>1414 <symbol> , </symbol>1415 <expression>1416 <term>1417 <identifier> y </identifier>1418 </term>1419 </expression>1420 <symbol> , </symbol>1421 <expression>1422 <term>1423 <identifier> x </identifier>1424 </term>1425 <symbol> + </symbol>1426 <term>1427 <integerConstant> 1 </integerConstant>1428 </term>1429 </expression>1430 <symbol> , </symbol>1431 <expression>1432 <term>1433 <identifier> y </identifier>1434 </term>1435 <symbol> + </symbol>1436 <term>1437 <identifier> size </identifier>1438 </term>1439 </expression>1440 </expressionList>1441 <symbol> ) </symbol>1442 <symbol> ; </symbol>1443 </doStatement>1444 <letStatement>1445 <keyword> let </keyword>1446 <identifier> x </identifier>1447 <symbol> = </symbol>1448 <expression>1449 <term>1450 <identifier> x </identifier>1451 </term>1452 <symbol> + </symbol>1453 <term>1454 <integerConstant> 2 </integerConstant>1455 </term>1456 </expression>1457 <symbol> ; </symbol>1458 </letStatement>1459 <doStatement>1460 <keyword> do </keyword>1461 <identifier> Screen </identifier>1462 <symbol> . </symbol>1463 <identifier> setColor </identifier>1464 <symbol> ( </symbol>1465 <expressionList>1466 <expression>1467 <term>1468 <keyword> true </keyword>1469 </term>1470 </expression>1471 </expressionList>1472 <symbol> ) </symbol>1473 <symbol> ; </symbol>1474 </doStatement>1475 <doStatement>1476 <keyword> do </keyword>1477 <identifier> Screen </identifier>1478 <symbol> . </symbol>1479 <identifier> drawRectangle </identifier>1480 <symbol> ( </symbol>1481 <expressionList>1482 <expression>1483 <term>1484 <symbol> ( </symbol>1485 <expression>1486 <term>1487 <identifier> x </identifier>1488 </term>1489 <symbol> + </symbol>1490 <term>1491 <identifier> size </identifier>1492 </term>1493 </expression>1494 <symbol> ) </symbol>1495 </term>1496 <symbol> - </symbol>1497 <term>1498 <integerConstant> 1 </integerConstant>1499 </term>1500 </expression>1501 <symbol> , </symbol>1502 <expression>1503 <term>1504 <identifier> y </identifier>1505 </term>1506 </expression>1507 <symbol> , </symbol>1508 <expression>1509 <term>1510 <identifier> x </identifier>1511 </term>1512 <symbol> + </symbol>1513 <term>1514 <identifier> size </identifier>1515 </term>1516 </expression>1517 <symbol> , </symbol>1518 <expression>1519 <term>1520 <identifier> y </identifier>1521 </term>1522 <symbol> + </symbol>1523 <term>1524 <identifier> size </identifier>1525 </term>1526 </expression>1527 </expressionList>1528 <symbol> ) </symbol>1529 <symbol> ; </symbol>1530 </doStatement>1531 </statements>1532 <symbol> } </symbol>1533 </ifStatement>1534 <returnStatement>1535 <keyword> return </keyword>1536 <symbol> ; </symbol>1537 </returnStatement>1538 </statements>1539 <symbol> } </symbol>1540 </subroutineBody>1541 </subroutineDec>1542 <symbol> } </symbol>1543</class>1544"""1545 square_game_xml = """1546<class>1547 <keyword> class </keyword>1548 <identifier> SquareGame </identifier>1549 <symbol> { </symbol>1550 <classVarDec>1551 <keyword> field </keyword>1552 <identifier> Square </identifier>1553 <identifier> square </identifier>1554 <symbol> ; </symbol>1555 </classVarDec>1556 <classVarDec>1557 <keyword> field </keyword>1558 <keyword> int </keyword>1559 <identifier> direction </identifier>1560 <symbol> ; </symbol>1561 </classVarDec>1562 <subroutineDec>1563 <keyword> constructor </keyword>1564 <identifier> SquareGame </identifier>1565 <identifier> new </identifier>1566 <symbol> ( </symbol>1567 <parameterList>1568 </parameterList>1569 <symbol> ) </symbol>1570 <subroutineBody>1571 <symbol> { </symbol>1572 <statements>1573 <letStatement>1574 <keyword> let </keyword>1575 <identifier> square </identifier>1576 <symbol> = </symbol>1577 <expression>1578 <term>1579 <identifier> Square </identifier>1580 <symbol> . </symbol>1581 <identifier> new </identifier>1582 <symbol> ( </symbol>1583 <expressionList>1584 <expression>1585 <term>1586 <integerConstant> 0 </integerConstant>1587 </term>1588 </expression>1589 <symbol> , </symbol>1590 <expression>1591 <term>1592 <integerConstant> 0 </integerConstant>1593 </term>1594 </expression>1595 <symbol> , </symbol>1596 <expression>1597 <term>1598 <integerConstant> 30 </integerConstant>1599 </term>1600 </expression>1601 </expressionList>1602 <symbol> ) </symbol>1603 </term>1604 </expression>1605 <symbol> ; </symbol>1606 </letStatement>1607 <letStatement>1608 <keyword> let </keyword>1609 <identifier> direction </identifier>1610 <symbol> = </symbol>1611 <expression>1612 <term>1613 <integerConstant> 0 </integerConstant>1614 </term>1615 </expression>1616 <symbol> ; </symbol>1617 </letStatement>1618 <returnStatement>1619 <keyword> return </keyword>1620 <expression>1621 <term>1622 <keyword> this </keyword>1623 </term>1624 </expression>1625 <symbol> ; </symbol>1626 </returnStatement>1627 </statements>1628 <symbol> } </symbol>1629 </subroutineBody>1630 </subroutineDec>1631 <subroutineDec>1632 <keyword> method </keyword>1633 <keyword> void </keyword>1634 <identifier> dispose </identifier>1635 <symbol> ( </symbol>1636 <parameterList>1637 </parameterList>1638 <symbol> ) </symbol>1639 <subroutineBody>1640 <symbol> { </symbol>1641 <statements>1642 <doStatement>1643 <keyword> do </keyword>1644 <identifier> square </identifier>1645 <symbol> . </symbol>1646 <identifier> dispose </identifier>1647 <symbol> ( </symbol>1648 <expressionList>1649 </expressionList>1650 <symbol> ) </symbol>1651 <symbol> ; </symbol>1652 </doStatement>1653 <doStatement>1654 <keyword> do </keyword>1655 <identifier> Memory </identifier>1656 <symbol> . </symbol>1657 <identifier> deAlloc </identifier>1658 <symbol> ( </symbol>1659 <expressionList>1660 <expression>1661 <term>1662 <keyword> this </keyword>1663 </term>1664 </expression>1665 </expressionList>1666 <symbol> ) </symbol>1667 <symbol> ; </symbol>1668 </doStatement>1669 <returnStatement>1670 <keyword> return </keyword>1671 <symbol> ; </symbol>1672 </returnStatement>1673 </statements>1674 <symbol> } </symbol>1675 </subroutineBody>1676 </subroutineDec>1677 <subroutineDec>1678 <keyword> method </keyword>1679 <keyword> void </keyword>1680 <identifier> run </identifier>1681 <symbol> ( </symbol>1682 <parameterList>1683 </parameterList>1684 <symbol> ) </symbol>1685 <subroutineBody>1686 <symbol> { </symbol>1687 <varDec>1688 <keyword> var </keyword>1689 <keyword> char </keyword>1690 <identifier> key </identifier>1691 <symbol> ; </symbol>1692 </varDec>1693 <varDec>1694 <keyword> var </keyword>1695 <keyword> boolean </keyword>1696 <identifier> exit </identifier>1697 <symbol> ; </symbol>1698 </varDec>1699 <statements>1700 <letStatement>1701 <keyword> let </keyword>1702 <identifier> exit </identifier>1703 <symbol> = </symbol>1704 <expression>1705 <term>1706 <keyword> false </keyword>1707 </term>1708 </expression>1709 <symbol> ; </symbol>1710 </letStatement>1711 <whileStatement>1712 <keyword> while </keyword>1713 <symbol> ( </symbol>1714 <expression>1715 <term>1716 <symbol> ~ </symbol>1717 <term>1718 <identifier> exit </identifier>1719 </term>1720 </term>1721 </expression>1722 <symbol> ) </symbol>1723 <symbol> { </symbol>1724 <statements>1725 <whileStatement>1726 <keyword> while </keyword>1727 <symbol> ( </symbol>1728 <expression>1729 <term>1730 <identifier> key </identifier>1731 </term>1732 <symbol> = </symbol>1733 <term>1734 <integerConstant> 0 </integerConstant>1735 </term>1736 </expression>1737 <symbol> ) </symbol>1738 <symbol> { </symbol>1739 <statements>1740 <letStatement>1741 <keyword> let </keyword>1742 <identifier> key </identifier>1743 <symbol> = </symbol>1744 <expression>1745 <term>1746 <identifier> Keyboard </identifier>1747 <symbol> . </symbol>1748 <identifier> keyPressed </identifier>1749 <symbol> ( </symbol>1750 <expressionList>1751 </expressionList>1752 <symbol> ) </symbol>1753 </term>1754 </expression>1755 <symbol> ; </symbol>1756 </letStatement>1757 <doStatement>1758 <keyword> do </keyword>1759 <identifier> moveSquare </identifier>1760 <symbol> ( </symbol>1761 <expressionList>1762 </expressionList>1763 <symbol> ) </symbol>1764 <symbol> ; </symbol>1765 </doStatement>1766 </statements>1767 <symbol> } </symbol>1768 </whileStatement>1769 <ifStatement>1770 <keyword> if </keyword>1771 <symbol> ( </symbol>1772 <expression>1773 <term>1774 <identifier> key </identifier>1775 </term>1776 <symbol> = </symbol>1777 <term>1778 <integerConstant> 81 </integerConstant>1779 </term>1780 </expression>1781 <symbol> ) </symbol>1782 <symbol> { </symbol>1783 <statements>1784 <letStatement>1785 <keyword> let </keyword>1786 <identifier> exit </identifier>1787 <symbol> = </symbol>1788 <expression>1789 <term>1790 <keyword> true </keyword>1791 </term>1792 </expression>1793 <symbol> ; </symbol>1794 </letStatement>1795 </statements>1796 <symbol> } </symbol>1797 </ifStatement>1798 <ifStatement>1799 <keyword> if </keyword>1800 <symbol> ( </symbol>1801 <expression>1802 <term>1803 <identifier> key </identifier>1804 </term>1805 <symbol> = </symbol>1806 <term>1807 <integerConstant> 90 </integerConstant>1808 </term>1809 </expression>1810 <symbol> ) </symbol>1811 <symbol> { </symbol>1812 <statements>1813 <doStatement>1814 <keyword> do </keyword>1815 <identifier> square </identifier>1816 <symbol> . </symbol>1817 <identifier> decSize </identifier>1818 <symbol> ( </symbol>1819 <expressionList>1820 </expressionList>1821 <symbol> ) </symbol>1822 <symbol> ; </symbol>1823 </doStatement>1824 </statements>1825 <symbol> } </symbol>1826 </ifStatement>1827 <ifStatement>1828 <keyword> if </keyword>1829 <symbol> ( </symbol>1830 <expression>1831 <term>1832 <identifier> key </identifier>1833 </term>1834 <symbol> = </symbol>1835 <term>1836 <integerConstant> 88 </integerConstant>1837 </term>1838 </expression>1839 <symbol> ) </symbol>1840 <symbol> { </symbol>1841 <statements>1842 <doStatement>1843 <keyword> do </keyword>1844 <identifier> square </identifier>1845 <symbol> . </symbol>1846 <identifier> incSize </identifier>1847 <symbol> ( </symbol>1848 <expressionList>1849 </expressionList>1850 <symbol> ) </symbol>1851 <symbol> ; </symbol>1852 </doStatement>1853 </statements>1854 <symbol> } </symbol>1855 </ifStatement>1856 <ifStatement>1857 <keyword> if </keyword>1858 <symbol> ( </symbol>1859 <expression>1860 <term>1861 <identifier> key </identifier>1862 </term>1863 <symbol> = </symbol>1864 <term>1865 <integerConstant> 131 </integerConstant>1866 </term>1867 </expression>1868 <symbol> ) </symbol>1869 <symbol> { </symbol>1870 <statements>1871 <letStatement>1872 <keyword> let </keyword>1873 <identifier> direction </identifier>1874 <symbol> = </symbol>1875 <expression>1876 <term>1877 <integerConstant> 1 </integerConstant>1878 </term>1879 </expression>1880 <symbol> ; </symbol>1881 </letStatement>1882 </statements>1883 <symbol> } </symbol>1884 </ifStatement>1885 <ifStatement>1886 <keyword> if </keyword>1887 <symbol> ( </symbol>1888 <expression>1889 <term>1890 <identifier> key </identifier>1891 </term>1892 <symbol> = </symbol>1893 <term>1894 <integerConstant> 133 </integerConstant>1895 </term>1896 </expression>1897 <symbol> ) </symbol>1898 <symbol> { </symbol>1899 <statements>1900 <letStatement>1901 <keyword> let </keyword>1902 <identifier> direction </identifier>1903 <symbol> = </symbol>1904 <expression>1905 <term>1906 <integerConstant> 2 </integerConstant>1907 </term>1908 </expression>1909 <symbol> ; </symbol>1910 </letStatement>1911 </statements>1912 <symbol> } </symbol>1913 </ifStatement>1914 <ifStatement>1915 <keyword> if </keyword>1916 <symbol> ( </symbol>1917 <expression>1918 <term>1919 <identifier> key </identifier>1920 </term>1921 <symbol> = </symbol>1922 <term>1923 <integerConstant> 130 </integerConstant>1924 </term>1925 </expression>1926 <symbol> ) </symbol>1927 <symbol> { </symbol>1928 <statements>1929 <letStatement>1930 <keyword> let </keyword>1931 <identifier> direction </identifier>1932 <symbol> = </symbol>1933 <expression>1934 <term>1935 <integerConstant> 3 </integerConstant>1936 </term>1937 </expression>1938 <symbol> ; </symbol>1939 </letStatement>1940 </statements>1941 <symbol> } </symbol>1942 </ifStatement>1943 <ifStatement>1944 <keyword> if </keyword>1945 <symbol> ( </symbol>1946 <expression>1947 <term>1948 <identifier> key </identifier>1949 </term>1950 <symbol> = </symbol>1951 <term>1952 <integerConstant> 132 </integerConstant>1953 </term>1954 </expression>1955 <symbol> ) </symbol>1956 <symbol> { </symbol>1957 <statements>1958 <letStatement>1959 <keyword> let </keyword>1960 <identifier> direction </identifier>1961 <symbol> = </symbol>1962 <expression>1963 <term>1964 <integerConstant> 4 </integerConstant>1965 </term>1966 </expression>1967 <symbol> ; </symbol>1968 </letStatement>1969 </statements>1970 <symbol> } </symbol>1971 </ifStatement>1972 <whileStatement>1973 <keyword> while </keyword>1974 <symbol> ( </symbol>1975 <expression>1976 <term>1977 <symbol> ~ </symbol>1978 <term>1979 <symbol> ( </symbol>1980 <expression>1981 <term>1982 <identifier> key </identifier>1983 </term>1984 <symbol> = </symbol>1985 <term>1986 <integerConstant> 0 </integerConstant>1987 </term>1988 </expression>1989 <symbol> ) </symbol>1990 </term>1991 </term>1992 </expression>1993 <symbol> ) </symbol>1994 <symbol> { </symbol>1995 <statements>1996 <letStatement>1997 <keyword> let </keyword>1998 <identifier> key </identifier>1999 <symbol> = </symbol>2000 <expression>2001 <term>2002 <identifier> Keyboard </identifier>2003 <symbol> . </symbol>2004 <identifier> keyPressed </identifier>2005 <symbol> ( </symbol>2006 <expressionList>2007 </expressionList>2008 <symbol> ) </symbol>2009 </term>2010 </expression>2011 <symbol> ; </symbol>2012 </letStatement>2013 <doStatement>2014 <keyword> do </keyword>2015 <identifier> moveSquare </identifier>2016 <symbol> ( </symbol>2017 <expressionList>2018 </expressionList>2019 <symbol> ) </symbol>2020 <symbol> ; </symbol>2021 </doStatement>2022 </statements>2023 <symbol> } </symbol>2024 </whileStatement>2025 </statements>2026 <symbol> } </symbol>2027 </whileStatement>2028 <returnStatement>2029 <keyword> return </keyword>2030 <symbol> ; </symbol>2031 </returnStatement>2032 </statements>2033 <symbol> } </symbol>2034 </subroutineBody>2035 </subroutineDec>2036 <subroutineDec>2037 <keyword> method </keyword>2038 <keyword> void </keyword>2039 <identifier> moveSquare </identifier>2040 <symbol> ( </symbol>2041 <parameterList>2042 </parameterList>2043 <symbol> ) </symbol>2044 <subroutineBody>2045 <symbol> { </symbol>2046 <statements>2047 <ifStatement>2048 <keyword> if </keyword>2049 <symbol> ( </symbol>2050 <expression>2051 <term>2052 <identifier> direction </identifier>2053 </term>2054 <symbol> = </symbol>2055 <term>2056 <integerConstant> 1 </integerConstant>2057 </term>2058 </expression>2059 <symbol> ) </symbol>2060 <symbol> { </symbol>2061 <statements>2062 <doStatement>2063 <keyword> do </keyword>2064 <identifier> square </identifier>2065 <symbol> . </symbol>2066 <identifier> moveUp </identifier>2067 <symbol> ( </symbol>2068 <expressionList>2069 </expressionList>2070 <symbol> ) </symbol>2071 <symbol> ; </symbol>2072 </doStatement>2073 </statements>2074 <symbol> } </symbol>2075 </ifStatement>2076 <ifStatement>2077 <keyword> if </keyword>2078 <symbol> ( </symbol>2079 <expression>2080 <term>2081 <identifier> direction </identifier>2082 </term>2083 <symbol> = </symbol>2084 <term>2085 <integerConstant> 2 </integerConstant>2086 </term>2087 </expression>2088 <symbol> ) </symbol>2089 <symbol> { </symbol>2090 <statements>2091 <doStatement>2092 <keyword> do </keyword>2093 <identifier> square </identifier>2094 <symbol> . </symbol>2095 <identifier> moveDown </identifier>2096 <symbol> ( </symbol>2097 <expressionList>2098 </expressionList>2099 <symbol> ) </symbol>2100 <symbol> ; </symbol>2101 </doStatement>2102 </statements>2103 <symbol> } </symbol>2104 </ifStatement>2105 <ifStatement>2106 <keyword> if </keyword>2107 <symbol> ( </symbol>2108 <expression>2109 <term>2110 <identifier> direction </identifier>2111 </term>2112 <symbol> = </symbol>2113 <term>2114 <integerConstant> 3 </integerConstant>2115 </term>2116 </expression>2117 <symbol> ) </symbol>2118 <symbol> { </symbol>2119 <statements>2120 <doStatement>2121 <keyword> do </keyword>2122 <identifier> square </identifier>2123 <symbol> . </symbol>2124 <identifier> moveLeft </identifier>2125 <symbol> ( </symbol>2126 <expressionList>2127 </expressionList>2128 <symbol> ) </symbol>2129 <symbol> ; </symbol>2130 </doStatement>2131 </statements>2132 <symbol> } </symbol>2133 </ifStatement>2134 <ifStatement>2135 <keyword> if </keyword>2136 <symbol> ( </symbol>2137 <expression>2138 <term>2139 <identifier> direction </identifier>2140 </term>2141 <symbol> = </symbol>2142 <term>2143 <integerConstant> 4 </integerConstant>2144 </term>2145 </expression>2146 <symbol> ) </symbol>2147 <symbol> { </symbol>2148 <statements>2149 <doStatement>2150 <keyword> do </keyword>2151 <identifier> square </identifier>2152 <symbol> . </symbol>2153 <identifier> moveRight </identifier>2154 <symbol> ( </symbol>2155 <expressionList>2156 </expressionList>2157 <symbol> ) </symbol>2158 <symbol> ; </symbol>2159 </doStatement>2160 </statements>2161 <symbol> } </symbol>2162 </ifStatement>2163 <doStatement>2164 <keyword> do </keyword>2165 <identifier> Sys </identifier>2166 <symbol> . </symbol>2167 <identifier> wait </identifier>2168 <symbol> ( </symbol>2169 <expressionList>2170 <expression>2171 <term>2172 <integerConstant> 5 </integerConstant>2173 </term>2174 </expression>2175 </expressionList>2176 <symbol> ) </symbol>2177 <symbol> ; </symbol>2178 </doStatement>2179 <returnStatement>2180 <keyword> return </keyword>2181 <symbol> ; </symbol>2182 </returnStatement>2183 </statements>2184 <symbol> } </symbol>2185 </subroutineBody>2186 </subroutineDec>2187 <symbol> } </symbol>2188</class>2189"""2190 c_main_xml = self._CompileToXML(main_jack)2191 c_square_xml = self._CompileToXML(square_jack)2192 c_square_game_xml = self._CompileToXML(square_game_jack)2193 self.assertTrue(Compare(main_xml, c_main_xml))2194 self.assertTrue(Compare(square_xml, c_square_xml))2195 self.assertTrue(Compare(square_game_xml, c_square_game_xml))2196 # Test code generation does not crash.2197 main_vm = self._CompileToHackVM(main_jack)2198 square_vm = self._CompileToHackVM(square_jack)2199 square_game_vm = self._CompileToHackVM(square_game_jack)2200if __name__ == "__main__":...

Full Screen

Full Screen

finder.py

Source:finder.py Github

copy

Full Screen

1# uncompyle6 version 2.11.32# Python bytecode 3.5 (3350)3# Decompiled from: Python 3.5.2 |Anaconda 4.1.1 (64-bit)| (default, Jul 5 2016, 11:41:13) [MSC v.1900 64 bit (AMD64)]4# Embedded file name: Finder.py5import os6import sys7import time8import xml.etree.ElementTree as ET9def finder(env, stringToSearch, stringToExclude, useExcludeFlag, isOnlySystem):10 numOfFoundJobs = 011 stringToSearch = stringToSearch.lower()12 stringToExclude = stringToExclude.lower()13 pathForExportFiles = '\\\\ntsrv1\\tohna\\Control-M_Project\\Full-Drafts-' + env14 os.chdir(pathForExportFiles)15 draftFiles = sorted(os.listdir(os.getcwd()), key=os.path.getmtime)16 lastDraftFile = draftFiles[-1]17 tree = ET.parse(lastDraftFile)18 root = tree.getroot()19 resultList = []20 for Table in root:21 tableName = str(Table.get('FOLDER_NAME'))22 orderMethod = str(Table.get('FOLDER_ORDER_METHOD'))23 if orderMethod == 'None' and isOnlySystem == True:24 continue25 if Table.tag == 'SMART_FOLDER':26 tableList = []27 tableListRow = '\n**************************************\n\nSmart Table : ' + tableName + ' - UserDaily : ' + orderMethod28 tableList.append(tableListRow)29 loopObjectResult = []30 if useExcludeFlag == True:31 loopObjectResult = loopObjectWithExclude(Table, stringToSearch, stringToExclude)32 else:33 loopObjectResult = loopObject(Table, stringToSearch)34 if loopObjectResult != False and loopObjectResult != None:35 for loopListRow in loopObjectResult:36 tableList.append(loopListRow)37 numOfFoundJobs += 138 resultList.append(tableList)39 for subTable in Table.iter('SUB_FOLDER'):40 subTableName = str(subTable.get('JOBNAME'))41 subTableList = []42 subTableListRow = '\n**************************************\n\nSub Table : ' + subTableName + ' - Under : ' + tableName43 subTableList.append(subTableListRow)44 loopObjectResult = []45 if useExcludeFlag == True:46 loopObjectResult = loopObjectWithExclude(subTable, stringToSearch, stringToExclude)47 else:48 loopObjectResult = loopObject(subTable, stringToSearch)49 if loopObjectResult != False and loopObjectResult != None:50 for loopListRow in loopObjectResult:51 subTableList.append(loopListRow)52 numOfFoundJobs += 153 resultList.append(subTableList)54 for job in Table.iter('JOB'):55 tempList = []56 listRow = '\n**************************************\n\nTable : ' + tableName + ' - UserDaily : ' + orderMethod57 tempList.append(listRow)58 jobName = job.get('JOBNAME')59 nodeId = job.get('NODEID')60 if not nodeId:61 nodeId = 'None'62 listRow = '-->> Job : ' + jobName + ' - Agent : ' + nodeId63 tempList.append(listRow)64 loopObjectResult = []65 if useExcludeFlag == True:66 loopObjectResult = loopObjectWithExclude(job, stringToSearch, stringToExclude)67 else:68 loopObjectResult = loopObject(job, stringToSearch)69 if loopObjectResult != False and loopObjectResult != None:70 for loopListRow in loopObjectResult:71 tempList.append(loopListRow)72 numOfFoundJobs += 173 resultList.append(tempList)74 if numOfFoundJobs == 0:75 return 'No Data Found... :-('76 return resultList77def getVariableType(i_VarName):78 dict = {'%%FTP-LPATH1': 'File Trans Left Path',79 '%%FTP-LPATH2': 'File Trans Left Path',80 '%%FTP-LPATH3': 'File Trans Left Path',81 '%%FTP-LPATH4': 'File Trans Left Path',82 '%%FTP-LPATH5': 'File Trans Left Path',83 '%%FTP-RPATH1': 'File Trans Right Path',84 '%%FTP-RPATH2': 'File Trans Right Path',85 '%%FTP-RPATH3': 'File Trans Right Path',86 '%%FTP-RPATH4': 'File Trans Right Path',87 '%%FTP-RPATH5': 'File Trans Right Path',88 '%%FTP-RUSER': 'File Trans Left User',89 '%%FTP-RUSER': 'File Trans Right User',90 '%%FTP-ACCOUNT': 'File Trans Account',91 '%%FTP-LHOST': 'File Trans Left Host',92 '%%FTP-RHOST': 'File Trans Right Host',93 '%%DB-STP_PACKAGE': 'DB PKG Name',94 '%%DB-STP_NAME': 'DB SP Name',95 '%%INF-WORKFLOW': 'INF WF Name'}96 if i_VarName in dict:97 return dict[i_VarName]98 return i_VarName99def loopObject(objectName, stringToSearch):100 tempList = []101 foundIndicator = False102 jobBasicAttribs = objectName.attrib103 lowerJobBasicAttribs = dict(((k, v.lower()) for k, v in jobBasicAttribs.items()))104 for valueIndex in lowerJobBasicAttribs:105 lowValue = lowerJobBasicAttribs[valueIndex]106 value = jobBasicAttribs[valueIndex]107 if stringToSearch in lowValue:108 foundIndicator = True109 listRow = '---->> ' + valueIndex.upper() + ' = ' + value110 tempList.append(listRow)111 for subItem in objectName:112 parameterType = subItem.tag113 lowerDict = dict(((k.lower(), v.lower()) for k, v in subItem.attrib.items()))114 if parameterType == 'VARIABLE':115 pass116 varName = subItem.attrib.get('NAME')117 varValue = str(subItem.attrib.get('VALUE'))118 lowerVarValue = varValue.lower()119 if stringToSearch in lowerVarValue:120 foundIndicator = True121 translatedFieldName = getVariableType(varName)122 listRow = '---->> ' + translatedFieldName + ' = ' + varValue123 tempList.append(listRow)124 else:125 if parameterType == 'QUANTITATIVE':126 initName = subItem.attrib.get('NAME')127 initValue = subItem.attrib.get('VALUE')128 lowerInitName = initName.lower()129 if stringToSearch in lowerInitName:130 foundIndicator = True131 listRow = '---->> INIT = ' + initName132 tempList.append(listRow)133 else:134 if parameterType == 'INCOND':135 condName = subItem.attrib.get('NAME')136 lowerCondName = condName.lower()137 condDate = subItem.attrib.get('ODATE')138 if stringToSearch in lowerCondName:139 foundIndicator = True140 listRow = '---->> IN Cond Name = ' + condName + ' | Date = ' + condDate141 tempList.append(listRow)142 else:143 if parameterType == 'OUTCOND':144 condName = subItem.attrib.get('NAME')145 lowerCondName = condName.lower()146 condSign = subItem.attrib.get('SIGN')147 condDate = subItem.attrib.get('ODATE')148 if stringToSearch in lowerCondName:149 foundIndicator = True150 listRow = '---->> OUT Cond Name = ' + condName + ' | Sign = ' + condSign + ' | Date = ' + condDate151 tempList.append(listRow)152 elif parameterType == 'ON':153 onCode = subItem.attrib.get('CODE')154 onStmt = subItem.attrib.get('STMT')155 for doStatement in subItem.iter():156 doType = doStatement.tag157 if doType == 'DOSHOUT':158 pass159 destName = doStatement.attrib.get('DEST')160 lowerDestName = destName.lower()161 msgText = doStatement.attrib.get('MESSAGE')162 lowerMsgText = msgText.lower()163 if stringToSearch in lowerDestName or stringToSearch in lowerMsgText:164 foundIndicator = True165 listRow = '---->> On Code = ' + onCode + ' Stmt = ' + onStmt + ' | Shout Destination Name = ' + destName + ' | MSG = ' + msgText166 tempList.append(listRow)167 else:168 if doType == 'DOCOND':169 condName = doStatement.attrib.get('NAME')170 lowerCondName = condName.lower()171 condSign = doStatement.attrib.get('SIGN')172 condDate = doStatement.attrib.get('ODATE')173 if stringToSearch in lowerCondName:174 foundIndicator = True175 listRow = '---->> On Code = ' + onCode + ' OUT Cond Name = ' + condName + ' | Sign = ' + condSign + ' | Date = ' + condDate176 tempList.append(listRow)177 else:178 if doType == 'DOMAIL':179 mailDestination = doStatement.attrib.get('DEST')180 lowerMailDest = mailDestination.lower()181 mailMsg = doStatement.attrib.get('MESSAGE')182 if mailMsg != None:183 lowerMailMsg = mailMsg.lower()184 else:185 mailMsg = lowerMailMsg = 'Empty Body'186 mailSubject = doStatement.attrib.get('SUBJECT')187 if mailSubject != None:188 lowerMailSubject = mailSubject.lower()189 else:190 mailSubject = lowerMailSubject = 'Empty Subject'191 if stringToSearch in lowerMailDest or stringToSearch in lowerMailMsg or stringToSearch in lowerMailSubject:192 foundIndicator = True193 listRow = '---->> Mail Message:' + '\n-------->> TO : ' + mailDestination + '\n-------->> Subject : ' + mailSubject + '\n-------->> Message : ' + mailMsg194 tempList.append(listRow)195 elif doType == 'DOFORCEJOB':196 jobNameToOrder = doStatement.attrib.get('NAME')197 if jobNameToOrder != None:198 lowerJobNameToOrder = jobNameToOrder.lower()199 else:200 lowerJobNameToOrder = jobNameToOrder = 'Empty Job Name'201 tableNameToOrder = doStatement.attrib.get('TABLE_NAME')202 if tableNameToOrder != None:203 lowerTableNameToOrder = tableNameToOrder.lower()204 else:205 lowerTableNameToOrder = tableNameToOrder = 'Empty Table Name'206 if stringToSearch in lowerJobNameToOrder or stringToSearch in lowerTableNameToOrder:207 foundIndicator = True208 listRow = '---->> Force Job:' + '\n-------->> Job Name : ' + jobNameToOrder + '\n-------->> Table Name : ' + tableNameToOrder209 tempList.append(listRow)210 elif parameterType == 'SHOUT':211 whenTime = subItem.attrib.get('TIME')212 destName = subItem.attrib.get('DEST')213 lowerDestName = destName.lower()214 msgText = subItem.attrib.get('MESSAGE')215 lowerMsgText = msgText.lower()216 whenText = subItem.attrib.get('WHEN')217 if stringToSearch in lowerDestName or stringToSearch in lowerMsgText:218 foundIndicator = True219 if whenTime:220 listRow = '---->> PostProc Shout Name = ' + destName + ' | MSG = ' + msgText + ' | WHEN = ' + whenText + ' ' + whenTime221 tempList.append(listRow)222 else:223 listRow = '---->> PostProc Shout Name = ' + destName + ' | MSG = ' + msgText + ' | WHEN = ' + whenText224 tempList.append(listRow)225 if foundIndicator:226 return tempList227 return False228def loopObjectWithExclude(objectName, stringToSearch, stringToExclude):229 tempList = []230 foundIndicator = False231 jobBasicAttribs = objectName.attrib232 lowerJobBasicAttribs = dict(((k, v.lower()) for k, v in jobBasicAttribs.items()))233 for valueIndex in lowerJobBasicAttribs:234 lowValue = lowerJobBasicAttribs[valueIndex]235 value = jobBasicAttribs[valueIndex]236 if stringToSearch in lowValue and stringToExclude not in lowValue:237 foundIndicator = True238 listRow = '---->> ' + valueIndex.upper() + ' = ' + value239 tempList.append(listRow)240 for subItem in objectName:241 parameterType = subItem.tag242 lowerDict = dict(((k.lower(), v.lower()) for k, v in subItem.attrib.items()))243 if parameterType == 'AUTOEDIT2':244 pass245 varName = subItem.attrib.get('NAME')246 varValue = str(subItem.attrib.get('VALUE'))247 lowerVarValue = varValue.lower()248 if stringToSearch in lowerVarValue and stringToExclude not in lowerVarValue:249 foundIndicator = True250 translatedFieldName = getVariableType(varName)251 listRow = '---->> ' + translatedFieldName + ' = ' + varValue252 tempList.append(listRow)253 else:254 if parameterType == 'QUANTITATIVE':255 initName = subItem.attrib.get('NAME')256 initValue = subItem.attrib.get('VALUE')257 lowerInitName = initName.lower()258 if stringToSearch in lowerInitName and stringToExclude not in lowerInitName:259 foundIndicator = True260 listRow = '---->> INIT = ' + initName261 tempList.append(listRow)262 else:263 if parameterType == 'INCOND':264 condName = subItem.attrib.get('NAME')265 lowerCondName = condName.lower()266 condDate = subItem.attrib.get('ODATE')267 if stringToSearch in lowerCondName and stringToExclude not in lowerCondName:268 foundIndicator = True269 listRow = '---->> IN Cond Name = ' + condName + ' | Date = ' + condDate270 tempList.append(listRow)271 else:272 if parameterType == 'OUTCOND':273 condName = subItem.attrib.get('NAME')274 lowerCondName = condName.lower()275 condSign = subItem.attrib.get('SIGN')276 condDate = subItem.attrib.get('ODATE')277 if stringToSearch in lowerCondName and stringToExclude not in lowerCondName:278 foundIndicator = True279 listRow = '---->> OUT Cond Name = ' + condName + ' | Sign = ' + condSign + ' | Date = ' + condDate280 tempList.append(listRow)281 elif parameterType == 'ON':282 onCode = subItem.attrib.get('CODE')283 onStmt = subItem.attrib.get('STMT')284 for doStatement in subItem.iter():285 doType = doStatement.tag286 if doType == 'DOSHOUT':287 destName = doStatement.attrib.get('DEST')288 lowerDestName = destName.lower()289 msgText = doStatement.attrib.get('MESSAGE')290 lowerMsgText = msgText.lower()291 if stringToSearch in lowerDestName and stringToExclude not in lowerDestName or stringToSearch in lowerMsgText and stringToExclude not in lowerMsgText:292 foundIndicator = True293 listRow = '---->> On Code = ' + onCode + ' Stmt = ' + onStmt + ' | Shout Destination Name = ' + destName + ' | MSG = ' + msgText294 tempList.append(listRow)295 if doType == 'DOCOND':296 condName = doStatement.attrib.get('NAME')297 lowerCondName = condName.lower()298 condSign = doStatement.attrib.get('SIGN')299 condDate = doStatement.attrib.get('ODATE')300 if stringToSearch in lowerCondName and stringToExclude not in lowerCondName:301 foundIndicator = True302 listRow = '---->> On Code = ' + onCode + ' OUT Cond Name = ' + condName + ' | Sign = ' + condSign + ' | Date = ' + condDate303 tempList.append(listRow)304 if doType == 'DOMAIL':305 mailDestination = doStatement.attrib.get('DEST')306 lowerMailDest = mailDestination.lower()307 mailMsg = doStatement.attrib.get('MESSAGE')308 if mailMsg != None:309 lowerMailMsg = mailMsg.lower()310 else:311 mailMsg = lowerMailMsg = 'Empty Body'312 mailSubject = doStatement.attrib.get('SUBJECT')313 if mailSubject != None:314 lowerMailSubject = mailSubject.lower()315 else:316 mailSubject = lowerMailSubject = 'Empty Subject'317 if stringToSearch in lowerMailDest and stringToExclude not in lowerMailDest or stringToSearch in lowerMailMsg and stringToExclude not in lowerMailMsg or stringToSearch in lowerMailSubject and stringToExclude not in lowerMailSubject:318 foundIndicator = True319 listRow = '---->> Mail Message:' + '\n-------->> TO : ' + mailDestination + '\n-------->> Subject : ' + mailSubject + '\n-------->> Message : ' + mailMsg320 tempList.append(listRow)321 elif parameterType == 'SHOUT':322 whenTime = subItem.attrib.get('TIME')323 destName = subItem.attrib.get('DEST')324 lowerDestName = destName.lower()325 msgText = subItem.attrib.get('MESSAGE')326 lowerMsgText = msgText.lower()327 whenText = subItem.attrib.get('WHEN')328 if stringToSearch in lowerDestName and stringToExclude not in lowerDestName or stringToSearch in lowerMsgText and stringToExclude not in lowerMsgText:329 foundIndicator = True330 if whenTime:331 pass332 listRow = '---->> PostProc Shout Name = ' + destName + ' | MSG = ' + msgText + ' | WHEN = ' + whenText + ' ' + whenTime333 else:334 listRow = '---->> PostProc Shout Name = ' + destName + ' | MSG = ' + msgText + ' | WHEN = ' + whenText335 tempList.append(listRow)336 if foundIndicator:337 return tempList338 return False339def main(env, stringToSearch, stringToExclude, useExcludeFlag, isOnlySystem):340 yes = set(['YES', 'Y', 'YE'])341 if useExcludeFlag:342 stringToSearch = stringToSearch.strip()343 stringToExclude = stringToExclude.strip()344 resultsList = finder(env, stringToSearch, stringToExclude, useExcludeFlag, isOnlySystem)345 else:346 stringToSearch = stringToSearch.strip()347 resultsList = finder(env, stringToSearch, 'None', useExcludeFlag, isOnlySystem)348 return resultsList...

Full Screen

Full Screen

flow.py

Source:flow.py Github

copy

Full Screen

1"Control flow model."2import ast 3from astvis.hgraph import HierarchicalGraph4import pynalyze.controlflow as cf5from pynalyze.controlflow import Block, BasicBlock, StartBlock, EndBlock, ConditionBlock6class IfBlock(Block):7 def __init__(self, model, parentBlock, ifStatement):8 Block.__init__(self, model, parentBlock)9 self.astObjects.append(ifStatement)10 condBlock = None11 if ifStatement.condition!=None:12 condBlock = ConditionBlock(self.model, self, [ifStatement.condition])13 self.subBlocks.append(condBlock)14 thenBlock = Block(self.model, self)15 thenBlocks = self.model.generateBlocks(thenBlock, list(ifStatement.blocks[0].statements))16 thenBlock.addSubBlocks(thenBlocks)17 self.subBlocks.append(thenBlock)18 19 if condBlock!=None:20 condBlock.branchBlocks.append(thenBlock) 21 self.firstBlock = condBlock22 else:23 self.firstBlock = thenBlock24class DoHeaderBlock(Block):25 def __init__(self, model, parentBlock, doStatement):26 Block.__init__(self, model, parentBlock)27 self.astObjects.append(doStatement)28 29 if doStatement.type=='for':30 self._initForBlocks(doStatement)31 elif doStatement.type=='while':32 self._initWhileBlocks(doStatement)33 34 def _initWhileBlocks(self, doStatement):35 self.conditionBlock = ConditionBlock(self.model, self, [doStatement.condition])36 self.initBlock = None37 self.stepBlock = None38 self.firstBlock = self.conditionBlock39 self.subBlocks.append(self.conditionBlock)40 def _initForBlocks(self, doStatement):41 astModel = doStatement.model42 self.initBlock = BasicBlock(self.model,43 self, [ast.Assignment(astModel,44 target=ast.Reference(astModel,45 name=doStatement.variable),46 value=doStatement.first)])47 self.conditionBlock = ConditionBlock(self.model,48 self, [ast.Operator(doStatement.model,49 type='.NEQ.',50 left=ast.Reference(astModel,51 name=doStatement.variable),52 right=doStatement.last)])53 # @todo: use step from doStatement54 statements = [ast.Assignment(astModel,55 target=ast.Reference(astModel,56 name=doStatement.variable),57 value=ast.Operator(astModel,58 type='+',59 left=ast.Reference(astModel,60 name=doStatement.variable),61 right=ast.Constant(astModel,62 value=1)))63 ]64 self.stepBlock = BasicBlock(self.model, self, statements)65 self.firstBlock = self.initBlock66 self.subBlocks.append(self.initBlock)67 self.subBlocks.append(self.conditionBlock)68 self.subBlocks.append(self.stepBlock)69 self.initBlock.endBlock = self.conditionBlock70 self.stepBlock.endBlock = self.conditionBlock71class IfConstructBlock(Block):72 def __init__(self, model, parentBlock, ifConstruct):73 Block.__init__(self, model, parentBlock)74 self.astObjects.append(ifConstruct)75 for stmt in ifConstruct.statements:76 ifBlock = IfBlock(self.model, self, stmt)77 self.subBlocks.append(ifBlock)78 if len(self.subBlocks)>1:79 self.subBlocks[-2].subBlocks[0].endBlock = self.subBlocks[-1] # elseif/else branch80 self.firstBlock = self.subBlocks[0]81class DoBlock(Block):82 def __init__(self, model, parentBlock, doStatement):83 Block.__init__(self, model, parentBlock)84 self.doId = doStatement.doId85 self.astObjects.append(doStatement)86 headerBlock = DoHeaderBlock(self.model, self, doStatement)87 self.subBlocks.append(headerBlock)88 block = Block(self.model, self)89 blocks = self.model.generateBlocks(block, list(doStatement.blocks[0].statements))90 block.addSubBlocks(blocks)91 if headerBlock.stepBlock!=None: # for92 block.endBlock = headerBlock.stepBlock93 else: # while94 block.endBlock = headerBlock.conditionBlock95 self.subBlocks.append(block)96 97 headerBlock.conditionBlock.branchBlocks.append(block) 98 self.firstBlock = headerBlock99class ControlFlowModel(cf.ControlFlowModel):100 "Model allows to navigate through AST tree of a subroutine or a program."101 def __init__(self, astObj):102 assert isinstance(astObj, ast.Code)103 cf.ControlFlowModel.__init__(self, astObj,list(astObj.statementBlock.statements))104 # add declarations to the start block105 self._startBlock.executions.extend(self.code.declarationBlock.statements)106 CLASS_MAP = {ast.IfStatement: IfBlock,107 ast.IfConstruct: IfConstructBlock,108 ast.DoStatement: DoBlock}109 110 JUMP_STATEMENT_CLASSES = (ast.Exit,)111 def _resolveJumpStatements(self):112 "For each Fortran 'exit' statement find 'do' block."113 def resolve(block):114 if isinstance(block, BasicBlock) and \115 isinstance(block.executions[-1], self.JUMP_STATEMENT_CLASSES):116 stmt = block.executions[-1]117 if isinstance(stmt, ast.Exit):118 # find do block for exit statement119 exitId = stmt.exitId120 jumpBlock = block.parentBlock121 while jumpBlock!=None:122 if isinstance(jumpBlock,DoBlock) and jumpBlock.doId==exitId:123 # found124 block.endBlock = jumpBlock.getEndBlock()125 break126 jumpBlock = jumpBlock.parentBlock127 128 self._codeBlock.itertree(resolve)129class BlockGraph(HierarchicalGraph):130 131 def _getParent(self, block):132 return block.parentBlock133 def _getChildren(self, block):...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run autotest automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful