Transforming Visual Programs Into Java and Vice Versa
Total Page:16
File Type:pdf, Size:1020Kb
Transforming Visual Programs into Java and Vice Versa by Lei Dong Submitted in partial fulfillment of the requirements for the degree of Master of Computer Science at Dalhousie University Halifax, Nova Scotia May 2002 © Copyright by Lei Dong, 2002 Dalhousie University I DALHOUSIE UNIVERSITY FACULTY OF COMPUTER SCIENCE The undersigned hereby certify that they have read and recommend to the Faculty of Graduate Studies for acceptance a thesis entitled _______Transforming Visual Programs into Java and Vice Versa______ by __________________Lei Dong___________________________________ in partial fulfillment of the requirements for the degree of Master of ________Computer Science________________. Dated: __________________________ Supervisor: _________________________________ Readers: _________________________________ _________________________________ _________________________________ ii DALHOUSIE UNIVERSITY DATE: ________________________ AUTHOR: ______________________________________________________ TITLE: ______________________________________________________ ______________________________________________________ DEPARTMENT OR SCHOOL: ______________________________________ DEGREE: __________ CONVOCATION: _________ YEAR: ______ Permission is herewith granted to Dalhousie University to circulate and to have copied for non-commercial purposes, at its discretion, the above title upon the request of individuals or institutions. _______________________________ Signature of Author The author reserves other publication rights, and neither the thesis nor extensive extracts from it may be printed or otherwise reproduced without the author s written permission. The author attests that permission has been obtained for the use of any copyrighted material appearing in the thesis (other than the brief excerpts requiring only proper acknowledgement in scholarly writing), and that all such use is clearly acknowledged. iii Table of Contents Table of Contents - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - iv Table of Figures- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ix List of Abbreviations - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - xi Acknowledgments - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - xii 1. Introduction - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 1 2. Visual Languages and Software Engineering - - - - - - - - - - - - - - - - - - - - - - 4 2.1. The evolution of programming languages - - - - - - - - - - - - - - - - - - 4 2.2. Introduction to Visual Programming Languages(VPLs)- - - - - - - - - 5 2.3. Some visual programming languages - - - - - - - - - - - - - - - - - - - - - 7 2.4. Advantages of visual languages - - - - - - - - - - - - - - - - - - - - - - - - - 11 2.5. General tools for software engineers- - - - - - - - - - - - - - - - - - - - - - 13 2.6. Visual software development tools for Java - - - - - - - - - - - - - - - - - 15 3. A formalisation of JGraph - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 19 3.1. Introduction - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 19 3.2. Formal definition of JGraph - - - - - - - - - - - - - - - - - - - - - - - - - - - 19 3.2.1. Package - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 20 3.2.2. Class and Interface - - - - - - - - - - - - - - - - - - - - - - - - - - - 20 3.2.3. Method and constructor. - - - - - - - - - - - - - - - - - - - - - - - 23 iv 3.2.4. Operations - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 27 3.2.5. Cases - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 32 3.3. Conclusion - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 37 4. Translating JGraph to Java - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 38 4.1. Introduction - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 38 4.2. Translation to Java - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 39 4.2.1. Package- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 40 4.2.2. Class and Interface - - - - - - - - - - - - - - - - - - - - - - - - - - - 41 4.2.2.1. Examples - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 42 4.2.3. Method. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 44 4.2.3.1. Example- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 46 4.2.4. Cases. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 51 4.2.4.1. Example. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 54 4.2.4.2. Example - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 56 4.2.5. Operations- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 58 4.2.5.1. Examples of translating operations - - - - - - - - - - - - 60 4.2.6. Controls - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 65 4.2.6.1. Examples of translating controls- - - - - - - - - - - - - - 65 4.2.7. A general example - - - - - - - - - - - - - - - - - - - - - - - - - - - - 66 v 5. Importing Java into JGraph - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 70 5.1. Introduction - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 70 5.2. Class files - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 70 5.3. Class - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 71 5.4. Inheritance - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 73 5.5. Attributes - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 74 5.6. Preprocessing - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 74 5.6.1. Simplifying control structures - - - - - - - - - - - - - - - - - - - - 75 5.6.2. Multiple declarations - - - - - - - - - - - - - - - - - - - - - - - - - - 75 5.6.3. Embedded sequences of statements. - - - - - - - - - - - - - - - - 76 5.6.4. Method returns- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 77 5.6.5. Unary increment and decrement operators - - - - - - - - - - - 79 5.6.6. The operators +=, -=, /=, *=- - - - - - - - - - - - - - - - - - - - - - 79 5.6.7. Condition of while loops and conditional statements - - - - 79 5.6.8. Embedded assignments - - - - - - - - - - - - - - - - - - - - - - - - 80 5.6.9. Missing else - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 83 5.6.10. Exceptions - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 84 5.6.11. Isolating variables. - - - - - - - - - - - - - - - - - - - - - - - - - - - 87 5.6.12. Removing multiple assignments- - - - - - - - - - - - - - - - - - 92 vi 5.6.13. Variable to variable assignments - - - - - - - - - - - - - - - - - - 94 5.7. Methods and Constructors- - - - - - - - - - - - - - - - - - - - - - - - - - - - 95 5.8. Expressions - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 96 5.8.1. Expressions which are not assignments - - - - - - - - - - - - - - 97 5.8.2. Assignment expressions - - - - - - - - - - - - - - - - - - - - - - - - 101 5.8.3. Bodies of methods and control structures - - - - - - - - - - - - 103 5.8.4. Method- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 104 5.9. Control structures- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 108 5.9.1. If statements - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 108 5.9.2. While statements - - - - - - - - - - - - - - - - - - - - - - - - - - - - 110 5.9.3. Try-catch structure - - - - - - - - - - - - - - - - - - - - - - - - - - - 111 5.10. A comprehensive example- - - - - - - - - - - - - - - - - - - - - - - - - - - - 112 5.11. Conclusion - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 115 6. Conclusions and Future Work - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 116 6.1. Introduction - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 116 6.2. Comparison of Java and JGraph - - - - - - - - - - - - - - - - - - - - - - - - 117 6.3. Characteristics of Java generated from JGraph and vice versa. - - - - - 119 6.4. Assessment of the translations- - - - - - - - - - - - - - - - - - - - - - - - - - 120 6.5. Future work- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 123 vii References - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 124 APPENDIX A - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 127 viii Table of Figures Figure 2-1: Von Neumann computer- - - - - - - - - - - - - - - - - - - - - - - - - - - - - 4 Figure 2-2: A Prograph quicksort method. - - - - - - - - - - - - - - - - - - - - - - - - - 8 Figure 2-3: A sample program of LabVIEW - - - - - - - - - - - - - - - - - - - - - - - - 9 Figure 2-4: A sample Forms/3 program.- - - - - - - - - - - - - - - - - - - - - - - - - - - 10 Figure 2-5: A program of KidSim - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 11 Figure 2-6: A sample Visual Age program- - - - - - - - - - - - - - - - - - - - - - - - - - 16 Figure 2-7: Java studio main window - - - - - - - - - - - - - - - - - - - - - - - - - - - - 17 Figure 3-1: A JGraph package containing two classes and four interfaces - - - - - 22 Figure 3-2: A JGraph method - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -