Interpreter for ZOOM-I Andrew Deren Initial Presentation - SE690 5/30/03
What is ZOOM? ZOOM is a set of tools and notation specifications used for development of large scale Object-Oriented systems. ZOOM stands for Z-based Object Oriented Modeling The ZOOM Project is supervised by Dr. Jia
Part of Zoom There are 3 parts of ZOOM: ZOOM-D – design notation Formal notation to specify design models: object design models and user interface design. ZOOM-S – specification notation Formal notation to describe the use cases with formally specified preconditions and postconditions. ZOOM-I – implementation language Can be any object-oriented language: Java, C++, etc Currently work is done on extending Java. Language will be extended with zoom specific features, but parts of the software system can be developed in target language.
What is Interpreter? An interpreter is a program that accepts any program (the source program) expressed in a particular language (the source language), and runs that source program immediately. The interpreter does not translate the source program into object code prior to execution.
Why Write Interpreter? Easier to test programs, no need to recompile. Can test fragments of code. Changes to design of ZOOM language are easier to test in interpreter. Some features of ZOOM might be hard to translate to java code directly. Interpreters are much easier to implement than compilers.
Programming Language Lifecycle Model Can be implemented as Interpreter to test language features
Features different from Java Enumerations Const Type definitions Generics Language support for Sets/Lists/Relations Foreach statement
Enumerations enum States { AL, CA, IL, NY, MA}; Better type-safety than int or String. Can only use valid values and is enforced by compiler at compile time.
Const & Type definitions const int PI = Nicer syntax for: static final int PI = typedef SmallInt = typedef CourseSet = {Course}
Generics class Hashtable Provides type safety for collections and other types No longer casts needed to cast back to object
Sets/Lists Build in support for list and set construction list = [1.. 10] // list with 10 elements 1 to 10 list = [1, 2, 3, 4] list = [int x: x > 0 & x < x * 2] Similar syntax for set creation, but uses { instead of [ Build in operators for list and set operations: Union, intersection, cardinality, membership tests, etc. boolean inList = x in list;
Foreach New addition to the language foreach (Type x in Expression) Expression must result in typesafe iterator.
Interpreter Features Integrated into zoom IDE Syntax highlight and other nice editor features Run zoom code directly from IDE with statement step through, variable evaluation, etc.
Interpreter Architecture 1. Program text is fetched to ZOOM Parser which builds AST nodes. 2. AST nodes are transformed into language elements (Statements, Expressions, etc) 3. Type checker checks type validity of the program. 4. Interpreter walks AST evaluating statements and expressions.
Interpreter Architecture Operates on AST elements (expressions, statements, etc) Interpreter runtime system holds all data in objects derived from Val Each Val type knows how to interact with other Val types and supports all operators that can be performed by that type Val ValIntValSetValListValString... int x = 3;// creates ValInt int y = 4;// created ValInt int z = x + y;// calls x.operator_plus(y)
Status Currently interpreter can be used in command line mode, or as swing application. Most operators, expressions and statements are functional for primitive types, sets and lists, but no object- oriented features yet.
References David A. Watt & Deryck F. Brown. Programming Language Processors in Java. Prentice Hall, Alfred V. Aho, Ravi Sethi, Jeffrey D. Ullman. Compilers: Principles, Techniques and Tools. Addison-Wesley,1988. Ravi Sethi. Programming Languages, Concepts & Constructs. Addison-Wesley, 1996 Randy M. Kaplan. Constructing Language Processors for Little Languages. John Wiley & Sons, Inc., 1994
Questions?