Thapl—A Theatrical Programming Language
Total Page:16
File Type:pdf, Size:1020Kb
Thapl—A Theatrical Programming Language Matan I. Peled Technion - Computer Science Department - M.Sc. Thesis MSC-2020-12 - 2020 Technion - Computer Science Department - M.Sc. Thesis MSC-2020-12 - 2020 Thapl—A Theatrical Programming Language Research Thesis Submitted in partial fulfillment of the requirements for the degree of Master of Science in Computer Science Matan I. Peled Submitted to the Senate of the Technion — Israel Institute of Technology Heshvan 5780 Haifa November 2019 Technion - Computer Science Department - M.Sc. Thesis MSC-2020-12 - 2020 Technion - Computer Science Department - M.Sc. Thesis MSC-2020-12 - 2020 This work was carried out under the joint supervision of Prof. Yossi Gil and Prof. David H. Lorenz, in the Faculty of Computer Science. Some results in this thesis have been published as articles or talks by the author and research collaborators in conferences and journals during the course of the author’s magisteral research period, the most up-to-date versions of which being: Matan I. Peled, Joseph (Yossi) Gil, and David H. Lorentz. Thapl—a theaterical program- ming language. In 5th Workshop on Domain-Specific Language Design and Implementation (DSLDI), 2017. Acknowledgements To my parents Dafna and Michael, I am grateful for your endless love and support throughout the years, I literally wouldn’t have been here without you. I am indebted to my advisors, Prof. Yossi Gil and Prof. David H. Lorentz, for pa- tiently guiding me through tight deadlines, and for teaching me what research actually is. A most heartful thanks goes to my friends for keeping me sane, to Nitzan for making sure I go swimming at least once a week no matter what, and to all those who helped me during my research; especially Shiri and Hila who helped improve this document. Finally, I’d like to thank Ira for being patient and understanding, for putting up with me when my stress levels went through the roof, and just for being awesome. ⌨⌨⌨⌨⌨⌨⌨⌨⌨⌨⌨ The generous support of the Technion is acknowledged. This research was supported in part by the Israel Science Foundation (ISF) under Grant No. 1440/14. Technion - Computer Science Department - M.Sc. Thesis MSC-2020-12 - 2020 Technion - Computer Science Department - M.Sc. Thesis MSC-2020-12 - 2020 Contents List of Listings List of Figures List of Terms Abstract 1 1 Introduction 3 1.1 The Problem ................................. 3 1.2 Shortcomings of Current Solutions ..................... 4 1.3 Thesis ..................................... 4 1.4 A Simple Example in Thapl ........................ 5 2 Background 9 2.1 Presentation Software ............................ 9 2.2 Visualization Languages ........................... 13 3 Tutorial by Example 17 3.1 Introduction .................................. 18 3.1.1 Defining characters .......................... 18 3.1.2 Defining actors ............................ 19 3.2 Action ..................................... 19 3.2.1 Defining verbs ............................ 21 3.2.2 Controlling time ........................... 21 3.3 Conclusion .................................. 21 4 Syntax 25 4.1 Lexical Matters ................................ 26 4.1.1 Literals ................................ 27 4.1.2 Tokenization sequence ........................ 29 4.2 Program Structure .............................. 30 4.3 Declarative Definitions ............................ 32 4.3.1 Type System and Primitive Types ................. 34 Technion - Computer Science Department - M.Sc. Thesis MSC-2020-12 - 2020 4.4 Directives: Sentences, Subjects, Verbs, and Modifiers ........... 35 4.4.1 Compound Directives ........................ 35 4.4.2 Atomic directives ........................... 36 4.5 Practicalities and Ambiguities ........................ 38 4.5.1 Parsing ................................ 38 4.5.2 Ambiguities .............................. 39 5 Semantics: Language and Animation 41 5.1 Object Model ................................. 41 5.1.1 Object Creation ........................... 42 5.1.2 Inheritance .............................. 42 5.2 Name Resolution in Thapl ......................... 42 5.2.1 Implementation Using Context Data-structure .......... 43 5.2.2 Simulating Other Languages .................... 46 5.3 Animation Semantics ............................. 47 5.3.1 Primitives ............................... 47 5.3.2 Solving for Slides ........................... 48 6 Physical Constraint Model: Springs 51 6.1 The Physical Model ............................. 53 6.1.1 Linear springs ............................. 53 6.1.2 The spring group(s) ......................... 56 6.1.3 Discrete non-linear springs ..................... 58 7 Results 61 7.1 Fitness For Purpose ............................. 61 7.1.1 Complex Animations ......................... 61 7.1.2 Simulating Logic Circuits ...................... 62 7.1.3 Hannukah Menorah ......................... 63 7.2 Flexibility ................................... 65 7.3 Analysis .................................... 66 8 Conclusion and Future Work 69 8.1 Related Research ............................... 70 8.1.1 Musical Composition ......................... 70 8.1.2 Name-binding ............................. 71 8.1.3 Other DSLs .............................. 71 8.2 Future Directions ............................... 74 8.3 Closing Notes ................................. 75 Technion - Computer Science Department - M.Sc. Thesis MSC-2020-12 - 2020 A Code Listings 83 A.1 Thapl Compiler ............................... 83 A.1.1 Grammar ............................... 83 A.2 Little Smalltalk ............................. 86 B Code Listings for TEX and Thapl Examples 89 B.1 Towers of Hanoi ................................ 89 B.1.1 LATEX ................................. 89 B.1.2 Thapl ................................. 92 B.2 Simulating a Logic Circuit .......................... 93 B.2.1 LATEX ................................. 93 B.2.2 Thapl ................................. 95 B.3 Hannukah Menorah ............................. 97 B.3.1 Thapl ................................. 97 B.4 Convolution .................................. 98 B.4.1 Thapl ................................. 98 B.5 Intersection .................................. 99 B.5.1 Thapl ................................. 99 C Syntax Derivation Rules 101 D Installation Guide & Quick Start 105 D.1 Installing and running the main program ................. 105 D.2 Installing the Jupyter extension ...................... 106 Hebrew Abstract i Technion - Computer Science Department - M.Sc. Thesis MSC-2020-12 - 2020 Technion - Computer Science Department - M.Sc. Thesis MSC-2020-12 - 2020 List of Listings 1.1 First example of a Thapl program ..................... 4 1.2 A simple Thapl program animating intersecting circles ......... 6 2.1 A simple animation in LATEX ........................ 10 2.2 Animation using TikZ’s animation facility. ................. 12 2.3 A simple animation in CSS ......................... 13 2.4 Towers of Hanoi in AnimalScript [Rössling and Freisleben, 2001] ... 14 2.5 Bubble sort in AnimalScript2 [Rößling et al., 2004] ........... 14 3.1 Empty Thapl Program ........................... 18 3.2 Empty Thapl Program, with load statement ............... 18 3.3 Definition of pole and disc ......................... 18 3.4 Adding has properties to pole and disc .................. 19 3.5 Defining actors for poles and discs ..................... 19 3.6 Adding a simple action to the animation .................. 20 3.7 Defining a can property ........................... 21 3.8 Solving the Towers of Hanoi ......................... 22 3.9 Solving the Towers of Hanoi quickly using meanwhile ........... 23 4.1 Organization and structure of a Thapl program. ............. 30 4.2 An example of a simple entity definition. .................. 34 5.1 Thapl program demonstrating the object model. ............. 42 5.2 Illustration of the Context concept using Python syntax ........ 44 5.3 Context construction for “play grouping” using Python syntax ..... 45 5.4 Context construction for “play grouping” with link to enclosing scope . 45 5.5 Context construction for “play grouping” with inheritance and scopes . 46 7.1 Stack Exchange answer for complex animation .............. 62 7.2 Thapl version of “complex animation” ................... 62 7.3 Stack Exchange answer for circuit simulation (excerpt) .......... 63 7.4 Thapl implementation of a circuit simulation presentation (excerpt) .. 63 7.5 Hannukah Menorah TikZ animation, from Stack Exchange ........ 64 7.6 Hannukah Menorah: Thapl Entity definitions (excerpt) ......... 64 7.7 Hannukah Menorah: Thapl action directives (excerpt) ......... 65 A.1 thapl.lark: Grammar definition for Thapl ............... 83 Technion - Computer Science Department - M.Sc. Thesis MSC-2020-12 - 2020 A.2 test_smalltalk.py: Demonstration of context implementation of the Smalltalk type hierarchy ........................... 86 B.1 LATEX Implementation of Towers of Hanoi ................. 89 B.2 Complete Thapl implementation of Towers of Hanoi ........... 92 B.3 LATEXimplementation of a flip-flop digital circuit ............. 93 B.4 Thapl implementation of a flip-flop digital circuit ............ 95 B.5 Complete Hannukah Menorah Thapl implementation .......... 97 B.6 Convolution presentation: Thapl implementation ............ 98 B.7 Intersection presentation: Thapl implementation ............. 99 D.1 Example code to run within Jupyter ................... 107 D.2 Installation script for Thapl ........................ 107 Technion - Computer Science