Columbia University Programming Languages and Translators Spring 2007 Professor Edwards SLAWscript Final Report Steve Henderson Levi Lister Abe Skolnik Wei Teng SLAWscript Final Report Page 2 of 169 Table of Contents Section Starting Page Number Section 1 Introduction 5 1 1 Executive Summary 6 1 2 Introduction 6 1 3 Key Features 6 1 4 Representative program 7 1 5 Examples of Syntax 7 1 6 Relevant Terminology 7 Section 2 Language Tutorial 8 2 1 Getting Started 9 2 2 Using Variables 9 2 4 Control Flow 10 3 1 Introduction 12 3 1 1 Hello World 12 3 2 Lexical Conventions 12 3 2 1 Comments 12 3 2 2 Constants 12 3 2 3 Identifiers 12 3 2 4 Keywords 13 3 2 5 Numeric Literals 13 3 2 6 String Literals 13 3 2 7 White Space 13 3 3 Subroutines 14 3 3 1 Subroutine Scope summarily static 14 3 3 2 Procedures 14 3 3 3 Functions 14 3 4 Variables 15 3 4 1 Data Types 15 3 4 2 Assignment 15 3 4 3 Variable Scope summarily dynamic 15 3 4 4 Randomization 16 3 5 Operators 16 3 5 1 Unary Operators 16 3 5 2 Binary and Tertiary Operators 17 3 5 3 Operator Precedence 17 3 5 4 Operator Chaining 18 3 6 Auto conversion 18 3 6 1 Unary Operator Auto conversion 18 3 6 2 Binary Operator Auto conversion 19 3 6 3 Boolean Context 20 3 6 4 Integer Context 20 SLAWscript Final Report Page 3 of 169 3 7 Conditionals 20 3 8 Loops 21 3 8 1 repeat times Loops 21 3 8 2 repeat with Loops 21 3 8 2 1 Note on repeat with Precision 22 3 8 3 while Loops 22 3 9 Input and Output 23 3 9 1 Input 23 3 9 2 Output 23 3 10 Program Termination 23 3 10 1 stop 23 3 10 2 Assertions 23 3 11 User defined Constants 24 3 12 Formal Grammar 25 3 13 Summary 28 Section 4 Project Plan 29 4 1 Project Overview 30 4 1 1 Purpose Scope and Objectives 30 4 1 2 Assumptions Constraints and Risks 30 4 1 3 Project Deliverables 31 4 1 4 Schedule Summary 31 4 2 Project Processes 31 4 2 1 4 2 2 4 2 3 4 2 3 Planning 31 Specification 32 Development 32 Testing 32 4 3 Programming Style Guide 33 4 4 Project Time line 35 4 5 Roles and Responsibilities 38 4 5 1 Internal Structure 38 4 5 2 Roles and Responsibilities 38 4 5 3 External Interfaces 39 4 6 Software Development Environment 39 4 6 1 Overview 39 4 6 2 Front end Software Development Environment 39 4 6 3 Back end Software Development Environment 40 4 7 Project Log 40 Section 5 Architectural Design 42 5 1 Architecture Overview 43 5 2 Front End Architecture 43 5 2 1 Front End Architecture Overview 43 5 2 2 Front end Components 43 5 2 3 Intermediate Representation 44 SLAWscript Final Report Page 4 of 169 5 3 Back end Architecture 44 5 3 1 Back end Architecture Overview 44 5 3 2 Iteration of Main Body SLAWscript Java Objects SJOs 45 5 3 3 Design of SLAWscript Java Objects SJOs 45 5 3 3 1 Top level Abstract Classes 45 5 4 The Constant Class 46 5 5 The UsableInExpressions Interface and its Implementations 46 5 5 1 Logic Expressions 46 5 5 2 Mathematical and String Expressions 46 5 5 3 Utility expressions 48 5 6 Sentences and Paragraphs 48 5 6 1 Non Subroutine Sentences and Paragraphs 49 5 6 1 1 Program Execution Sentences and Paragraphs 49 5 6 1 2 Loop Constructs 49 5 6 1 3 Input and Output Sentences 50 5 6 1 4 Utility Sentences 50 5 6 2 Subroutine Sentences and Paragraphs 50 5 7 Helper Classes 52 Section 6 Test Plan 54 6 1 Representative Programs 55 6 1 1 Hello World 55 6 1 2 Test of Logical OR 55 6 1 3 GCD 56 6 2 Test Methods 56 6 2 1 Unit Testing 56 6 2 2 Integrated Testing 57 6 3 Roles and Responsibilities 58 Section 7 Lessons Learned 59 7 1 Steve s Conclusions 60 7 2 Levi s Conclusions 60 7 3 Abe s Conclusions 60 7 4 Wei s Conclusions 61 Section 8 Appendix 62 8 1 ANTLR v3 Code 63 8 2 Java Code 71 8 3 SLAWscript Test Code 141 8 4 SLAWscript sample code 163 8 5 Shell Scripts 168 8 6 Miscellaneous Files 169 SLAWscript Final Report Page 5 of 169 Section 3 Section Language 1 Introduction Reference Manual SLAWscript Final Report Page 6 of 169 1 1 Executive Summary Simplified Python Runs in Java Requires Java 1 5 or higher 1 2 Introduction The name of our language is SLAWscript Steve Levi Abe and Wei s scripting language SLAWscript is a general purpose yet simple scripting language designed to enable the easy production of text i e command line environment applications Amongst other possible uses it will allow for quickly programming and deploying interactive training tutorial and survey applications SLAWscript is modeled on Python but on a smaller scale SLAWscript has no arrays classes or objects At this time only the three standard UNIX like channels stderr stdin and stdout are accessible that is to say files cannot be opened and used Also SLAWscript is not strict about the use of leading spacing 1 3 Key Features Conventional SLAWscript attempts to use conventional notation where possible as limited by the expressive abilities of ASCII For example the bar symbol is used to both begin and end an operator which returns either the absolute value for numeric operands or the string length for string operands Dynamic In SLAWscript variables don t need to be declared and they are allowed to contain different data types at different points in time Flexible In SLAWscript the addition operator can take either a number or string as either of its parameters and intelligently decides whether to perform arithmetic addition or string concatenation The multiplication operator is similarly flexible and intelligently decides whether to perform arithmetic multiplication or string multiplication i e multiplying 3 by Hi produces HiHiHi In general wherever a number is required a variable containing a string containing an appropriate number may be used instead The primary exception is assert statements This allows for easier use of user entered numbers in SLAWscript programs For example if the user entered 3 in response to a prompt and that string is stored in a variable called input then the expression 10 input yields the number seven Interpreted Our implementation of SLAWscript is an interpreter which facilitates rapid development Intuitive SLAWscript is designed to use the English language as a basis whenever it is helpful to do so for example to copy the data from a variable named a to a variable named b simply use the command copy a to b Portable and architecture neutral Our implementation of SLAWscript is based on Java which gets …
View Full Document
Unlocking...