Interim Report: Build Your Efficient Programming Language Quickly

Size: px
Start display at page:

Download "Interim Report: Build Your Efficient Programming Language Quickly"

Transcription

1 Interim Report: Build Your Efficient Programming Language Quickly Final Year Project Department of Computer Science University of Hong Kong Xiang Ji Supervisor: Prof. Bruno c.d.s. Oliveira January 24,

2 Contents 1 Introduction 4 2 Methodology Pretty Printer Correctness Aesthetic Qualities Work Accomplished Bug Fixes for the Pretty Printing Processor Bug Fix: Type Parameter Mismatch Bug Fix: Spaces Bug Fix: Annotation Processing Error Pretty Formatting Precise Representation of Language Primitives Testing for the Pretty Printer Generator Problems Encountered Finding a Pretty Printing Library Modularity Work Remaining & Plans Pretty Printer Case Study on Ruby Emacs/Vim Plugins Conclusion 17 List of Figures 1 Unformatted Code Formatted Code AnnotatedGrammar PPProcessor PPExpAlg Original Language Parameters JppLib Documentation

3 8 Prettifying Effect Manual override Wadler s Printer Emacs Plugin Vim Plugin

4 Abstract The programming language group at HKU (HKUPLG) aims to develop a language prototyping framework on top of Oracle s new research Graal Java Virtual Machine and its Truffle interpreter. In this project, which is a part of the aforementioned ongoing effort at HKU- PLG, various tools for the framework are developed, including a pretty printer generator and syntax highlighting plugins based on Emacs/Vim text editors for the new languages being prototyped. Currently, the pretty printer generator is nearly complete, having been tested on several sample languages; the syntax highlighting plugins are expected to be developed in the next iteration. Together with case studies using Python and Ruby language, the project aims to demonstrate that it is possible to build efficient programming languages quickly on a large scale, using Graal VM and an advanced design pattern called Object Algebra. Potential future works include other tools such as logger/debugger, and a IDE-like development environment for the framework. 1 Introduction Each year, there are hundreds of new programming languages created for various purposes. However, the creation process is usually complicated and involved, with each component of the language rewritten from scratch, instead of leveraging resources for existing languages. Also, if an interpreter is used for the language instead of a compiler, efficiency can become a serious issue. With the above concerns of extensibility and efficiency in sight, the programming language group at HKU (HKUPLG) aims to develop a framework on top of Oracles new research Graal Java Virtual Machine and its Truffle interpreter project, in order to allow developers build efficient programming language implementations quickly. Extensibility: The framework will provide various ready-to-use language components. In order to build a new programming language, a programmer just needs to pick the desired features for the language, assemble them together just like assembling Lego blocks, add some additional custom features if he/she wishes, and then quickly get a prototype implementation, thus eliminating the need of writing everything from scratch. Such modularity will be provided by Object Algebra 4

5 [1], a design pattern researched and proposed by the supervisor of this project, Bruno c.d.s. Oliveira. Efficiency: With the support of high-efficiency Graal virtual machine and Truffle framework, the interpreted languages will perform with high efficiency close to that of a compiled language.[2] In this project, which is a part of the larger project going on at HKUPLG, various tools for the framework are developed, including: A pretty printer which helps users in the process of prototyping and debugging. Emacs & Vim plugins which provide supports such as syntax highlighting for the new languages designed by users Also, a case study on Ruby language will be carried out in the next phase of the project. The remainder of this report first presents a detailed discussion on the methodology employed during the development of this project. Then, work accomplished and work remaining are described, which detail various functionalities of the pretty printer that we ve implemented so far and the tests we ve performed. In addition, problems encountered and future planning are provided. Finally, the report closes with a summary and information on potential future research directions. 2 Methodology The development of framework tools encompasses a variety of software. The pretty printer and related tools are being developed in Java in cohesion with the framework s existing code; it will also leverage existing Java libraries. The Emacs/Vim plugins will be written in Emacs Lisp / Vimscript respectively and will be relatively more independent. 2.1 Pretty Printer A pretty printer is a tool that formats and prints out application source code from the Abstract Syntax Tree (AST). It will help in producing a clear 5

6 representation of the code a programmer is writing. After pretty printing, the originally unintelligible code in Figure 1 is transformed into well-formatted code in Figure 2. Also, it will help the debugging process. Figure 1: Unformatted Code Figure 2: Formatted Code Since we are providing a language prototyping framework, the developer might create a wide variety of languages to his/her liking. Therefore, a single pretty printer would not suffice for all the languages. The framework shall instead automatically generate an appropriate printer for each new language that the developer creates. The way we achieve it is through Java annotations. Figure 3 demonstrates the developer-written Java interface which specifies the language syntax. After the developer has finished writing, he/she will prepend the to the interface. 6

7 Figure 3: AnnotatedGrammar Then, our pretty printer generator will collect all available interfaces annotated as shown in Figure 4. An analysis will be performed on each of the interfaces, and an appropriate printer will be generated based on the syntax definitions collected during the analysis. Figure 4: PPProcessor An example can be seen in Figure 5, where the appropriate printing method for the add operation in the language Expression Algebra is generated. All the code shown in this figure is automatically produced by our pretty printer generator, without extra modification. 7

8 Figure 5: PPExpAlg Before the project started, there was already a prototype of the annotation processor present in the framework, developed by other members of HKUPLG. However, it had two drawbacks upon which improvements are being made: 1. It was still largely primitive and only works for the simplest type of language. When the target language got more complicated, it produced some error and was unable to generate the printer. 2. The printing format was still crude, which means it was not really a "pretty" printer: The outputted strings were mostly an amalgamation of text and were not really pleasant on the eyes Correctness As the prototype printer was more a concept model than a real, complete piece of software, it contains multiple bugs, which will be discussed in details below. They have been fixed during the development process. 8

9 2.1.2 Aesthetic Qualities A "pretty" printer should not only print the abstract syntax tree correctly, but also do so with style. A good pretty printer should be able to handle line breaks and indentations appropriately. For this purpose, a layout algorithm is needed. There have been several algorithms around, and a Java pretty printing library, JppLib[3], which implements the algorithm of Oppen[4], has been selected as the library to provide such a layout algorithm. The library is integrated into our annotation processor in order to generate printers that are able to print prettily. 3 Work Accomplished 3.1 Bug Fixes for the Pretty Printing Processor Currently, the bugs within the prototype processor are mostly fixed. Those bugs include: Bug Fix: Type Parameter Mismatch Before, the generated printer would always only have one type parameter in its interface signature regardless of the number of type parameters in the algebra interface of the target language. For example, for parameters <E, P> (See figure 6), the generated printer would still produce just <interface _PPMumAlg extends MumAlg<IPrint> instead of <interface _PPMumAlg extends MumAlg<IPrint, IPrint>. This prevented the pretty printer from working on more complicated languages. Now this bug is fixed and the correct type parameters are produced. Figure 6: Original Language Parameters 9

10 3.1.2 Bug Fix: Spaces The generated printer would not produce appropriate spaces. For example, the abstract syntax tree alg.ifnode(alg.booleannode(true), alg.stringnode("it s true"), alg.stringnode("it s false")) should be printed as ( if true "It s true" "It s false"), however the actual output was (iftrue"it s true""it s false"), which means everything was jumbled together. Now the correct output is printed Bug Fix: Annotation Processing Error Whenever there is an annotation in the form = ( SYMBOL form@ * ) "), that is to say, a symbol followed by a list of arguments, the annotation processor reported an index out of range error and failed to generate any code for the printer. Now this error is fixed and the printers can be generated properly. 3.2 Pretty Formatting As mentioned previously, for the pretty part of the printers generated, we resorted to a library JppLib by Martin Geise, which provides a full set of documentation(see Figure 7) and sample usage. Designed with a focus on object-oriented programming style, JppLib uses one single object to record the information accumulated while traversing the document. In order to adapt to such a feature, we had to utilize an object algebra interface IPrint similar to that used in Factory design pattern in our code, so that the printer can properly print the parent node of an abstract syntax tree first, before proceeding to its children nodes. Without this pattern, the printer will always print children nodes first, which will result in erroneous outputs such as (true it is True it is False if) instead of (if true it is True it is False ). After successfully incorporating the library, the pretty printer is now able to correctly insert line breaks and whitespaces into the printed output. As seen in Figure 8a, the original output is all piled together in one line, while the prettified output, as seen in Figure 8b, has linebreaks and whitespaces which make the code much easier for the programmer to read. Notice that in this example, the parameter LINE_WIDTH is set as 20. Varying this parameter will lead to different line-breaking behaviors in accordance with the programmer s 10

11 Figure 7: JppLib Documentation preference. 3.3 Precise Representation of Language Primitives The form of language primitives, such as boolean, can vary greatly from one language to another. For example, in Mumbler language it s #t and #f while in Java language it s true and false. In our framework, a token file is supplied for each language for the parser to correctly identify and convert language primitives from source code into AST representation. Unfortunately, the reverse is not easy, i.e. converting the language primitive from AST back into their original source code form. This resulted in certain inaccuracies in our printer. For example, for Mumbler language, the output (if true resulta resultb) should really be (if #t "resulta" "resultb"). The current solution is to let users manually supply the correct way of printing out language primitives (See figure 9). Some language workbenches (tools for domain-specific language creation) seem to be capable of incorporating language tokens for reserved keywords defined by the developer. As a part of potential future work, we might be able to look into those language workbenches and come up with our an automatic solution which would spare the users of the manual labor. 11

12 (a) Unformatted Output Figure 8: Prettifying Effect (b) Formatted Output 3.4 Testing for the Pretty Printer Generator The pretty printer generator has been tested on two sample languages: ExpAlg which is a simple language involving only arithmetic operations, and Mumbler [5] which is a more sophisticated language resembling Lisp in its design. In the next step it will be combined with the other part of our project carried out by the other group members, namely a case study attempting to implement Python using our framework. It will be tested on our implementation of Python once the implementation is complete. 4 Problems Encountered There were several main difficulties which were dealt with in the process. Setting up the Graal/Truffle framework was actually quite complicated. Because it is still an experimental project under active development by Oracle, each new version brings breaking changes. Therefore, we had to fix our version of Graal to a specific version instead of the newest one. Also, we had to fix the version of Java Runtime Environment installed on our machine to version 1.8.0_31 instead of version 1.8.0_45 since the newest JRE is incompatible with Graal. After fixing the versions the program runs normally. 12

13 Figure 9: Manual override 4.1 Finding a Pretty Printing Library Finding a suitable pretty printing library took some time. Originally we intended to translate a library written in Haskell by Wadler[6] (see Figure 10a) to Java. However, doing so proved difficult since Java and Haskell are two distinctly different languages in various aspects, and such differences are also embodied in the design patterns of their programs. A prototypical implementation in Java was attempted, as shown in Figure 10b, however it could not satisfactorily provide all the functionalities needed. Therefore, we resorted to an open-source library JppLib written in Java according to Oppen s algorithm, which is actually effectively equivalent to Wadler s algorithm. 4.2 Modularity One important feature of object algebra is modularity. For this purpose, multiple algebraic interfaces should be able to be combined together: Listing 1: Combining Interfaces s t a t i c <E> E make1 ( ExpAlg<E> a l g ) { return a l g. add ( a l g. l i t ( 3 ), a l g. mul ( a l g. l i t ( 4 ), a l g. l i t ( 5 ) ) ) ; } 13

14 (a) Haskell Source Figure 10: Wadler s Printer (b) Java Translation Attempt s t a t i c <E> E make2 ( ExpAlg<E> a l g ) {... } PPExpAlg p1 = new PPExpAlg ( ) ; I P r i n t pp1 = make1 ( p1 ) ; PPExpAlg p2 = new PPExpAlg ( ) ; I P r i n t pp2 = make2 ( p2 ) ; PPExpAlg p3 = new PPExpAlg ( ) ; // Here we try to combine pp1 and pp2 t o g e t h e r. I P r i n t pp3 = p3. add ( pp1, pp2 ) ; However, in the previous implementation, each interface contained its own layouter instance, which cannot communicate with each other. The solution (provided by the supervisor) is to only instantiate a printer when the function print() of the interface is called, instead of when the interface is instantiated. In this way, this printer can traverse the structures of all children interfaces each time, instead of having to rely on other printers for information. p u b l i c i n t e r f a c e I P r i n t { d e f a u l t StringBackend p r i n t ( ) { StringBackend back = new StringBackend (DEFAULT_LINE_WIDTH) ; Layouter<NoExceptions> pp = new Layouter<NoExceptions >(back, DEFAULT_INDENTATION) ; p r i n t L o c a l ( pp ) ; 14

15 } return back ; } void p r i n t L o c a l ( Layouter<NoExceptions> pp ) ; 5 Work Remaining & Plans The remaining work will be focused on the case study of Ruby programming language and the development of Emacs/Vim plugins. 5.1 Pretty Printer The eventual goal for the pretty printer is to let it serve as a component of the entire framework. An important usage of it will be printing out debugging information in a legible and user-friendly way. Also it should be useful for code formatting as well as transforming abstract syntax tree of the target language into source code. 5.2 Case Study on Ruby Since the idea of our framework is to share common components when creating different language implementations, we would like to perform a case study on another language, which would reuse considerable work we have done during the case study of Python. We decided to use Ruby programming language as our case study target, because: Ruby and Python share a lot of similarities. They are both dynamic, interpreted languages widely used for scripting and rapid software developments. Similar to the zippy project with Python, there s also a Truffle-based Ruby implementation called RubyTruffle, which would serve as a reasonable comparison target against our implementation using Object Algebra for program benchmarks. Specifically, we ll first break down the algebraic interfaces for Python syntax definitions into modules, and reuse the appropriate components for Ruby 15

16 syntax definitions. For example, the syntaxes of arithmetic computations for Python and Ruby are largely similar. Therefore, we might be able to extend the algebraic interface for Python arithmetic computations, instead of having to rewrite a definition particular to Ruby. We ll also seek to modularize the interpreter implementation for Python, and see how we will be able to reuse it in Ruby interpreter. 5.3 Emacs/Vim Plugins In order to write codes efficiently in the newly created language, it is better for the developers to have something like an IDE(Integrated Development Environment). However, developing an IDE from scratch is a huge task which would be out of the scope of a final year project. An alternative would be to write plugins for Emacs/Vim (two widely used extensible text editors) which will generate appropriate syntax highlighting and corresponding editing facilities respectively for the target languages being developed by the users, according to their algebraic interface annotations. Depending on the remaining time available for the project, plugins for Emacs and Vim will be developed. The plugin development for Emacs will be done in Emacs Lisp (See Figure 11), while the plugin for Vim will be written in Vimscript (See Figure 12). Ideally they will be tested against various sample languages. Figure 11: Emacs Plugin 16

17 Figure 12: Vim Plugin 6 Conclusion Together with the case study using Python carried out by the other members of this group, we hope this project could demonstrate the viability of rapid prototyping of programming languages using Oracle Graal/Truffle combined with the Object Algebra design pattern. With the completion and improvement of the various components of our framework, we hope that the framework could be ready for use of real-world programming languages in the near future. Potential areas for future work include the development of loggers and debuggers for the framework, the creation of more language components for developers to use, and the development of full-blown IDE support for languages created. 17

18 References [1] B. C. d. S. Oliveira and W. R. Cook, Extensibility for the Masses: Practical Extensibility with Object Algebras, in Proceedings of the 26th European Conference on Object-Oriented Programming, ser. ECOOP 12, Berlin, Heidelberg: Springer-Verlag, 2012, pp. 2 27, isbn: doi: / {\_}2. [Online]. Available: [2] Oracle, Graal Project, [Online]. Available: net/projects/graal. [3] M. Giese, The Java Pretty Printer Library, [Online]. Available: [4] D. Oppen, Pretty printing, Stanford University, Tech. Rep., 1979, p. 26. [Online]. Available: au/%7b~%7dpmoulder/line-breaking/oppen-pretty-printing.pdf. [5] C. Esquivias, Mumbler, [Online]. Available: https : / / github. com/cesquivias/mumbler. [6] P. Wadler, A prettier printer, Tech. Rep. 1980, 1998, pp [Online]. Available: doi= %7b%5c&%7damp;rep=rep1%7b%5c&%7damp;type= pdf. 18

Copyright 2014 Oracle and/or its affiliates. All rights reserved.

Copyright 2014 Oracle and/or its affiliates. All rights reserved. Copyright 2014 Oracle and/or its affiliates. All rights reserved. On the Quest Towards Fastest (Java) Virtual Machine on the Planet! @JaroslavTulach Oracle Labs Copyright 2015 Oracle and/or its affiliates.

More information

Introduction to Programming Using Java (98-388)

Introduction to Programming Using Java (98-388) Introduction to Programming Using Java (98-388) Understand Java fundamentals Describe the use of main in a Java application Signature of main, why it is static; how to consume an instance of your own class;

More information

Semantic Analysis. Lecture 9. February 7, 2018

Semantic Analysis. Lecture 9. February 7, 2018 Semantic Analysis Lecture 9 February 7, 2018 Midterm 1 Compiler Stages 12 / 14 COOL Programming 10 / 12 Regular Languages 26 / 30 Context-free Languages 17 / 21 Parsing 20 / 23 Extra Credit 4 / 6 Average

More information

Semantic Analysis. Outline. The role of semantic analysis in a compiler. Scope. Types. Where we are. The Compiler Front-End

Semantic Analysis. Outline. The role of semantic analysis in a compiler. Scope. Types. Where we are. The Compiler Front-End Outline Semantic Analysis The role of semantic analysis in a compiler A laundry list of tasks Scope Static vs. Dynamic scoping Implementation: symbol tables Types Static analyses that detect type errors

More information

The role of semantic analysis in a compiler

The role of semantic analysis in a compiler Semantic Analysis Outline The role of semantic analysis in a compiler A laundry list of tasks Scope Static vs. Dynamic scoping Implementation: symbol tables Types Static analyses that detect type errors

More information

CS 211 Programming Practicum Fall 2018

CS 211 Programming Practicum Fall 2018 Due: Wednesday, 11/7/18 at 11:59 pm Infix Expression Evaluator Programming Project 5 For this lab, write a C++ program that will evaluate an infix expression. The algorithm REQUIRED for this program will

More information

Implementation of F# language support in JetBrains Rider IDE

Implementation of F# language support in JetBrains Rider IDE SAINT-PETERSBURG STATE UNIVERSITY Software Engineering Evgeniy Auduchinok Implementation of F# language support in JetBrains Rider IDE Graduation Thesis Scientific supervisor: Senior lecturer Iakov Kirilenko

More information

WACC Report. Zeshan Amjad, Rohan Padmanabhan, Rohan Pritchard, & Edward Stow

WACC Report. Zeshan Amjad, Rohan Padmanabhan, Rohan Pritchard, & Edward Stow WACC Report Zeshan Amjad, Rohan Padmanabhan, Rohan Pritchard, & Edward Stow 1 The Product Our compiler passes all of the supplied test cases, and over 60 additional test cases we wrote to cover areas (mostly

More information

STATS 507 Data Analysis in Python. Lecture 2: Functions, Conditionals, Recursion and Iteration

STATS 507 Data Analysis in Python. Lecture 2: Functions, Conditionals, Recursion and Iteration STATS 507 Data Analysis in Python Lecture 2: Functions, Conditionals, Recursion and Iteration Functions in Python We ve already seen examples of functions: e.g., type()and print() Function calls take the

More information

Automatic Generation of Graph Models for Model Checking

Automatic Generation of Graph Models for Model Checking Automatic Generation of Graph Models for Model Checking E.J. Smulders University of Twente edwin.smulders@gmail.com ABSTRACT There exist many methods to prove the correctness of applications and verify

More information

JASMINT: Language to User-Friendly AST with Emphasis on Transpilation. By: John Bradbury. Advisor: John Clements. Computer Science Department

JASMINT: Language to User-Friendly AST with Emphasis on Transpilation. By: John Bradbury. Advisor: John Clements. Computer Science Department JASMINT: Language to User-Friendly AST with Emphasis on Transpilation By: John Bradbury Advisor: John Clements Computer Science Department College of Engineering California Polytechnic State University,

More information

Overview. Rationale Division of labour between script and C++ Choice of language(s) Interfacing to C++ Performance, memory

Overview. Rationale Division of labour between script and C++ Choice of language(s) Interfacing to C++ Performance, memory SCRIPTING Overview Rationale Division of labour between script and C++ Choice of language(s) Interfacing to C++ Reflection Bindings Serialization Performance, memory Rationale C++ isn't the best choice

More information

Intro to Programming. Unit 7. What is Programming? What is Programming? Intro to Programming

Intro to Programming. Unit 7. What is Programming? What is Programming? Intro to Programming Intro to Programming Unit 7 Intro to Programming 1 What is Programming? 1. Programming Languages 2. Markup vs. Programming 1. Introduction 2. Print Statement 3. Strings 4. Types and Values 5. Math Externals

More information

Intro. Scheme Basics. scm> 5 5. scm>

Intro. Scheme Basics. scm> 5 5. scm> Intro Let s take some time to talk about LISP. It stands for LISt Processing a way of coding using only lists! It sounds pretty radical, and it is. There are lots of cool things to know about LISP; if

More information

Experiences in Building a Compiler for an Object-Oriented Language

Experiences in Building a Compiler for an Object-Oriented Language Experiences in Building a Compiler for an Object-Oriented Language José de Oliveira Guimarães Departamento de Computação UFSCar, São Carlos - SP, Brazil jose@dc.ufscar.br Abstract Traditionally books on

More information

Introduction to Python Part 2

Introduction to Python Part 2 Introduction to Python Part 2 v0.2 Brian Gregor Research Computing Services Information Services & Technology Tutorial Outline Part 2 Functions Tuples and dictionaries Modules numpy and matplotlib modules

More information

Working with JavaScript

Working with JavaScript Working with JavaScript Creating a Programmable Web Page for North Pole Novelties 1 Objectives Introducing JavaScript Inserting JavaScript into a Web Page File Writing Output to the Web Page 2 Objectives

More information

LECTURE 2. Compilers and Interpreters

LECTURE 2. Compilers and Interpreters LECTURE 2 Compilers and Interpreters COMPILATION AND INTERPRETATION Programs written in high-level languages can be run in two ways. Compiled into an executable program written in machine language for

More information

Think of drawing/diagramming editors. ECE450 Software Engineering II. The problem. The Composite pattern

Think of drawing/diagramming editors. ECE450 Software Engineering II. The problem. The Composite pattern Think of drawing/diagramming editors ECE450 Software Engineering II Drawing/diagramming editors let users build complex diagrams out of simple components The user can group components to form larger components......which

More information

Course introduction. Advanced Compiler Construction Michel Schinz

Course introduction. Advanced Compiler Construction Michel Schinz Course introduction Advanced Compiler Construction Michel Schinz 2016 02 25 General information Course goals The goal of this course is to teach you: how to compile high-level functional and objectoriented

More information

COP4020 Programming Languages. Compilers and Interpreters Robert van Engelen & Chris Lacher

COP4020 Programming Languages. Compilers and Interpreters Robert van Engelen & Chris Lacher COP4020 ming Languages Compilers and Interpreters Robert van Engelen & Chris Lacher Overview Common compiler and interpreter configurations Virtual machines Integrated development environments Compiler

More information

Code::Blocks Student Manual

Code::Blocks Student Manual Code::Blocks Student Manual Lawrence Goetz, Network Administrator Yedidyah Langsam, Professor and Theodore Raphan, Distinguished Professor Dept. of Computer and Information Science Brooklyn College of

More information

Scripted Components: Problem. Scripted Components. Problems with Components. Single-Language Assumption. Dr. James A. Bednar

Scripted Components: Problem. Scripted Components. Problems with Components. Single-Language Assumption. Dr. James A. Bednar Scripted Components: Problem Scripted Components Dr. James A. Bednar jbednar@inf.ed.ac.uk http://homepages.inf.ed.ac.uk/jbednar (Cf. Reuse-Oriented Development; Sommerville 2004 Chapter 4, 18) A longstanding

More information

Scripted Components Dr. James A. Bednar

Scripted Components Dr. James A. Bednar Scripted Components Dr. James A. Bednar jbednar@inf.ed.ac.uk http://homepages.inf.ed.ac.uk/jbednar SAPM Spring 2012: Scripted Components 1 Scripted Components: Problem (Cf. Reuse-Oriented Development;

More information

PyPy - How to not write Virtual Machines for Dynamic Languages

PyPy - How to not write Virtual Machines for Dynamic Languages PyPy - How to not write Virtual Machines for Dynamic Languages Institut für Informatik Heinrich-Heine-Universität Düsseldorf ESUG 2007 Scope This talk is about: implementing dynamic languages (with a focus

More information

which a value is evaluated. When parallelising a program, instances of this class need to be produced for all the program's types. The paper commented

which a value is evaluated. When parallelising a program, instances of this class need to be produced for all the program's types. The paper commented A Type-Sensitive Preprocessor For Haskell Noel Winstanley Department of Computer Science University of Glasgow September 4, 1997 Abstract This paper presents a preprocessor which generates code from type

More information

Why are there so many programming languages? Why do we have programming languages? What is a language for? What makes a language successful?

Why are there so many programming languages? Why do we have programming languages? What is a language for? What makes a language successful? Chapter 1 :: Introduction Introduction Programming Language Pragmatics Michael L. Scott Why are there so many programming languages? evolution -- we've learned better ways of doing things over time socio-economic

More information

Java Bytecode (binary file)

Java Bytecode (binary file) Java is Compiled Unlike Python, which is an interpreted langauge, Java code is compiled. In Java, a compiler reads in a Java source file (the code that we write), and it translates that code into bytecode.

More information

Control Flow. COMS W1007 Introduction to Computer Science. Christopher Conway 3 June 2003

Control Flow. COMS W1007 Introduction to Computer Science. Christopher Conway 3 June 2003 Control Flow COMS W1007 Introduction to Computer Science Christopher Conway 3 June 2003 Overflow from Last Time: Why Types? Assembly code is typeless. You can take any 32 bits in memory, say this is an

More information

Semantic Modularization Techniques in Practice: A TAPL case study

Semantic Modularization Techniques in Practice: A TAPL case study 1 Semantic Modularization Techniques in Practice: A TAPL case study Bruno C. d. S. Oliveira Joint work with Weixin Zhang, Haoyuan Zhang and Huang Li July 17, 2017 Text 2 EVF: An Extensible and Expressive

More information

Chapter 9: Dealing with Errors

Chapter 9: Dealing with Errors Chapter 9: Dealing with Errors What we will learn: How to identify errors Categorising different types of error How to fix different errors Example of errors What you need to know before: Writing simple

More information

Notes from a Short Introductory Lecture on Scala (Based on Programming in Scala, 2nd Ed.)

Notes from a Short Introductory Lecture on Scala (Based on Programming in Scala, 2nd Ed.) Notes from a Short Introductory Lecture on Scala (Based on Programming in Scala, 2nd Ed.) David Haraburda January 30, 2013 1 Introduction Scala is a multi-paradigm language that runs on the JVM (is totally

More information

Summer 2017 Discussion 10: July 25, Introduction. 2 Primitives and Define

Summer 2017 Discussion 10: July 25, Introduction. 2 Primitives and Define CS 6A Scheme Summer 207 Discussion 0: July 25, 207 Introduction In the next part of the course, we will be working with the Scheme programming language. In addition to learning how to write Scheme programs,

More information

CS2383 Programming Assignment 3

CS2383 Programming Assignment 3 CS2383 Programming Assignment 3 October 18, 2014 due: November 4 Due at the end of our class period. Due to the midterm and the holiday, the assignment will be accepted with a 10% penalty until the end

More information

CSE 413 Languages & Implementation. Hal Perkins Winter 2019 Structs, Implementing Languages (credits: Dan Grossman, CSE 341)

CSE 413 Languages & Implementation. Hal Perkins Winter 2019 Structs, Implementing Languages (credits: Dan Grossman, CSE 341) CSE 413 Languages & Implementation Hal Perkins Winter 2019 Structs, Implementing Languages (credits: Dan Grossman, CSE 341) 1 Goals Representing programs as data Racket structs as a better way to represent

More information

Compiling and Interpreting Programming. Overview of Compilers and Interpreters

Compiling and Interpreting Programming. Overview of Compilers and Interpreters Copyright R.A. van Engelen, FSU Department of Computer Science, 2000 Overview of Compilers and Interpreters Common compiler and interpreter configurations Virtual machines Integrated programming environments

More information

Program development plan

Program development plan Appendix A Program development plan If you are spending a lot of time debugging, it is probably because you do not have an effective program development plan. A typical, bad program development plan goes

More information

Java Code Cleanup using ExtendJ

Java Code Cleanup using ExtendJ Java Code Cleanup using ExtendJ Hannes Jönsson LTH stv10hjo@student.lu.se Felix Olsson LTH dat12fol@student.lu.se Abstract In order to reduce code size, ensure proper functionality of overridden methods

More information

Getting Started. Excerpted from Hello World! Computer Programming for Kids and Other Beginners

Getting Started. Excerpted from Hello World! Computer Programming for Kids and Other Beginners Getting Started Excerpted from Hello World! Computer Programming for Kids and Other Beginners EARLY ACCESS EDITION Warren D. Sande and Carter Sande MEAP Release: May 2008 Softbound print: November 2008

More information

CS1622. Semantic Analysis. The Compiler So Far. Lecture 15 Semantic Analysis. How to build symbol tables How to use them to find

CS1622. Semantic Analysis. The Compiler So Far. Lecture 15 Semantic Analysis. How to build symbol tables How to use them to find CS1622 Lecture 15 Semantic Analysis CS 1622 Lecture 15 1 Semantic Analysis How to build symbol tables How to use them to find multiply-declared and undeclared variables. How to perform type checking CS

More information

Scala : an LLVM-targeted Scala compiler

Scala : an LLVM-targeted Scala compiler Scala : an LLVM-targeted Scala compiler Da Liu, UNI: dl2997 Contents 1 Background 1 2 Introduction 1 3 Project Design 1 4 Language Prototype Features 2 4.1 Language Features........................................

More information

Table of Contents EVALUATION COPY

Table of Contents EVALUATION COPY Table of Contents Introduction... 1-2 A Brief History of Python... 1-3 Python Versions... 1-4 Installing Python... 1-5 Environment Variables... 1-6 Executing Python from the Command Line... 1-7 IDLE...

More information

Reverse Engineering with a CASE Tool. Bret Johnson. Research advisors: Spencer Rugaber and Rich LeBlanc. October 6, Abstract

Reverse Engineering with a CASE Tool. Bret Johnson. Research advisors: Spencer Rugaber and Rich LeBlanc. October 6, Abstract Reverse Engineering with a CASE Tool Bret Johnson Research advisors: Spencer Rugaber and Rich LeBlanc October 6, 994 Abstract We examine using a CASE tool, Interactive Development Environment's Software

More information

UPTR - a simple parse tree representation format

UPTR - a simple parse tree representation format UPTR - a simple parse tree representation format Jurgen Vinju Software Transformation Systems October 22, 2006 Quality of Software Transformation Systems Some Questions on Parsing Two pragmatical steps

More information

GDB Tutorial. A Walkthrough with Examples. CMSC Spring Last modified March 22, GDB Tutorial

GDB Tutorial. A Walkthrough with Examples. CMSC Spring Last modified March 22, GDB Tutorial A Walkthrough with Examples CMSC 212 - Spring 2009 Last modified March 22, 2009 What is gdb? GNU Debugger A debugger for several languages, including C and C++ It allows you to inspect what the program

More information

Unit E Step-by-Step: Programming with Python

Unit E Step-by-Step: Programming with Python Unit E Step-by-Step: Programming with Python Computer Concepts 2016 ENHANCED EDITION 1 Unit Contents Section A: Hello World! Python Style Section B: The Wacky Word Game Section C: Build Your Own Calculator

More information

Syntax and Grammars 1 / 21

Syntax and Grammars 1 / 21 Syntax and Grammars 1 / 21 Outline What is a language? Abstract syntax and grammars Abstract syntax vs. concrete syntax Encoding grammars as Haskell data types What is a language? 2 / 21 What is a language?

More information

CSCI 1100L: Topics in Computing Lab Lab 11: Programming with Scratch

CSCI 1100L: Topics in Computing Lab Lab 11: Programming with Scratch CSCI 1100L: Topics in Computing Lab Lab 11: Programming with Scratch Purpose: We will take a look at programming this week using a language called Scratch. Scratch is a programming language that was developed

More information

9/5/17. The Design and Implementation of Programming Languages. Compilation. Interpretation. Compilation vs. Interpretation. Hybrid Implementation

9/5/17. The Design and Implementation of Programming Languages. Compilation. Interpretation. Compilation vs. Interpretation. Hybrid Implementation Language Implementation Methods The Design and Implementation of Programming Languages Compilation Interpretation Hybrid In Text: Chapter 1 2 Compilation Interpretation Translate high-level programs to

More information

CS164: Programming Assignment 2 Dlex Lexer Generator and Decaf Lexer

CS164: Programming Assignment 2 Dlex Lexer Generator and Decaf Lexer CS164: Programming Assignment 2 Dlex Lexer Generator and Decaf Lexer Assigned: Thursday, September 16, 2004 Due: Tuesday, September 28, 2004, at 11:59pm September 16, 2004 1 Introduction Overview In this

More information

Language Translation. Compilation vs. interpretation. Compilation diagram. Step 1: compile. Step 2: run. compiler. Compiled program. program.

Language Translation. Compilation vs. interpretation. Compilation diagram. Step 1: compile. Step 2: run. compiler. Compiled program. program. Language Translation Compilation vs. interpretation Compilation diagram Step 1: compile program compiler Compiled program Step 2: run input Compiled program output Language Translation compilation is translation

More information

Chapter 9. Introduction to High-Level Language Programming. INVITATION TO Computer Science

Chapter 9. Introduction to High-Level Language Programming. INVITATION TO Computer Science Chapter 9 Introduction to High-Level Language Programming INVITATION TO Computer Science 1 Objectives After studying this chapter, students will be able to: Explain the advantages of high-level programming

More information

Total Test Questions: 43 Levels: Grades Units of Credit:.50

Total Test Questions: 43 Levels: Grades Units of Credit:.50 DESCRIPTION Computer Programming IA introduces students to the fundamentals of computer programming. Students will learn to design, code, and test their own programs while applying mathematical concepts.

More information

Using loops and debugging code

Using loops and debugging code Using loops and debugging code Chapter 7 Looping your code pp. 103-118 Exercises 7A & 7B Chapter 8 Fixing Bugs pp. 119-132 Exercise 8 Chapter 7 Looping your code Coding a For loop Coding a Do loop Chapter

More information

Stating the obvious, people and computers do not speak the same language.

Stating the obvious, people and computers do not speak the same language. 3.4 SYSTEM SOFTWARE 3.4.3 TRANSLATION SOFTWARE INTRODUCTION Stating the obvious, people and computers do not speak the same language. People have to write programs in order to instruct a computer what

More information

EPS Import Functionality for ReportLab

EPS Import Functionality for ReportLab A Proposal for the Synopsis By Mark Peters mark.peters@ivanhouse.com ReportLab is a Python Library designed to easily implement PDF output functionality into Python programs. Currently, ReportLab can import

More information

Type Inference. Prof. Clarkson Fall Today s music: Cool, Calm, and Collected by The Rolling Stones

Type Inference. Prof. Clarkson Fall Today s music: Cool, Calm, and Collected by The Rolling Stones Type Inference Prof. Clarkson Fall 2016 Today s music: Cool, Calm, and Collected by The Rolling Stones Review Previously in 3110: Interpreters: ASTs, evaluation, parsing Formal syntax Formal semantics

More information

Flow Control: Branches and loops

Flow Control: Branches and loops Flow Control: Branches and loops In this context flow control refers to controlling the flow of the execution of your program that is, which instructions will get carried out and in what order. In the

More information

Computer and Programming: Lab 1

Computer and Programming: Lab 1 01204111 Computer and Programming: Lab 1 Name ID Section Goals To get familiar with Wing IDE and learn common mistakes with programming in Python To practice using Python interactively through Python Shell

More information

Reversing. Time to get with the program

Reversing. Time to get with the program Reversing Time to get with the program This guide is a brief introduction to C, Assembly Language, and Python that will be helpful for solving Reversing challenges. Writing a C Program C is one of the

More information

UNIVERSITY OF CALIFORNIA Department of Electrical Engineering and Computer Sciences Computer Science Division

UNIVERSITY OF CALIFORNIA Department of Electrical Engineering and Computer Sciences Computer Science Division UNIVERSITY OF CALIFORNIA Department of Electrical Engineering and Computer Sciences Computer Science Division Fall, 2005 Prof. R. Fateman CS 164 Assignment 3 and 4: Parsing for MiniJava Due: Tuesday, Oct.

More information

The Lorax Programming Language

The Lorax Programming Language The Lorax Programming Language Doug Bienstock, Chris D Angelo, Zhaarn Maheswaran, Tim Paine, and Kira Whitehouse dmb2168, cd2665, zsm2103, tkp2108, kbw2116 Programming Translators and Languages, Department

More information

CS2900 Introductory Programming with Python and C++ Kevin Squire LtCol Joel Young Fall 2007

CS2900 Introductory Programming with Python and C++ Kevin Squire LtCol Joel Young Fall 2007 CS2900 Introductory Programming with Python and C++ Kevin Squire LtCol Joel Young Fall 2007 Course Web Site http://www.nps.navy.mil/cs/facultypages/squire/cs2900 All course related materials will be posted

More information

Utilizing a Common Language as a Generative Software Reuse Tool

Utilizing a Common Language as a Generative Software Reuse Tool Utilizing a Common Language as a Generative Software Reuse Tool Chris Henry and Stanislaw Jarzabek Department of Computer Science School of Computing, National University of Singapore 3 Science Drive,

More information

Safe Instantiation in Generic Java

Safe Instantiation in Generic Java Safe Instantiation in Generic Java January 31, 2003 Abstract This paper presents the safe-instantiation principle a new design principle for evaluating extensions of Java with support for generic types.

More information

PROFESSOR: Last time, we took a look at an explicit control evaluator for Lisp, and that bridged the gap between

PROFESSOR: Last time, we took a look at an explicit control evaluator for Lisp, and that bridged the gap between MITOCW Lecture 10A [MUSIC PLAYING] PROFESSOR: Last time, we took a look at an explicit control evaluator for Lisp, and that bridged the gap between all these high-level languages like Lisp and the query

More information

Case Study: Debugging a Discovered Specification for java.util.arraylist by Using Algebraic Interpretation

Case Study: Debugging a Discovered Specification for java.util.arraylist by Using Algebraic Interpretation Case Study: Debugging a Discovered Specification for java.util.arraylist by Using Algebraic Interpretation Technical Report CU-CS-970-04 Johannes Henkel and Amer Diwan {henkel,diwan}@cs.colorado.edu February

More information

Cross-platform software development in practice. Object-Oriented approach.

Cross-platform software development in practice. Object-Oriented approach. Cross-platform software development in practice. Object-Oriented approach. Vitaly Repin Maemo Devices, Nokia Maemo March 25, 2010 (Maemo) Cross-platform software development. March 25, 2010 1 / 37 Outline

More information

Arbori Starter Manual Eugene Perkov

Arbori Starter Manual Eugene Perkov Arbori Starter Manual Eugene Perkov What is Arbori? Arbori is a query language that takes a parse tree as an input and builds a result set 1 per specifications defined in a query. What is Parse Tree? A

More information

SCHEME 7. 1 Introduction. 2 Primitives COMPUTER SCIENCE 61A. October 29, 2015

SCHEME 7. 1 Introduction. 2 Primitives COMPUTER SCIENCE 61A. October 29, 2015 SCHEME 7 COMPUTER SCIENCE 61A October 29, 2015 1 Introduction In the next part of the course, we will be working with the Scheme programming language. In addition to learning how to write Scheme programs,

More information

Compilation I. Hwansoo Han

Compilation I. Hwansoo Han Compilation I Hwansoo Han Language Groups Imperative von Neumann (Fortran, Pascal, Basic, C) Object-oriented (Smalltalk, Eiffel, C++) Scripting languages (Perl, Python, JavaScript, PHP) Declarative Functional

More information

CMSC 201 Fall 2016 Lab 09 Advanced Debugging

CMSC 201 Fall 2016 Lab 09 Advanced Debugging CMSC 201 Fall 2016 Lab 09 Advanced Debugging Assignment: Lab 09 Advanced Debugging Due Date: During discussion Value: 10 points Part 1: Introduction to Errors Throughout this semester, we have been working

More information

UNIT TESTING OF C++ TEMPLATE METAPROGRAMS

UNIT TESTING OF C++ TEMPLATE METAPROGRAMS STUDIA UNIV. BABEŞ BOLYAI, INFORMATICA, Volume LV, Number 1, 2010 UNIT TESTING OF C++ TEMPLATE METAPROGRAMS ÁBEL SINKOVICS Abstract. Unit testing, a method for verifying a piece of software, is a widely

More information

Turtle Blocks Python Export

Turtle Blocks Python Export Turtle Blocks Python Export A Report on my GSoC Project Marion Zepf October 7, 2013 1 Motivation Turtle Blocks teaches children an important skill in today s world: programming. Its block-based graphical

More information

CS 360 Programming Languages Interpreters

CS 360 Programming Languages Interpreters CS 360 Programming Languages Interpreters Implementing PLs Most of the course is learning fundamental concepts for using and understanding PLs. Syntax vs. semantics vs. idioms. Powerful constructs like

More information

CS 330 Homework Comma-Separated Expression

CS 330 Homework Comma-Separated Expression CS 330 Homework Comma-Separated Expression 1 Overview Your responsibility in this homework is to build an interpreter for text-based spreadsheets, which are essentially CSV files with formulas or expressions

More information

Overview of the Ruby Language. By Ron Haley

Overview of the Ruby Language. By Ron Haley Overview of the Ruby Language By Ron Haley Outline Ruby About Ruby Installation Basics Ruby Conventions Arrays and Hashes Symbols Control Structures Regular Expressions Class vs. Module Blocks, Procs,

More information

AXIOMS OF AN IMPERATIVE LANGUAGE PARTIAL CORRECTNESS WEAK AND STRONG CONDITIONS. THE AXIOM FOR nop

AXIOMS OF AN IMPERATIVE LANGUAGE PARTIAL CORRECTNESS WEAK AND STRONG CONDITIONS. THE AXIOM FOR nop AXIOMS OF AN IMPERATIVE LANGUAGE We will use the same language, with the same abstract syntax that we used for operational semantics. However, we will only be concerned with the commands, since the language

More information

Macros in sbt: Problem solved!

Macros in sbt: Problem solved! Macros in sbt: Problem solved! Martin Duhem, Eugene Burmako Technical Report January 2015 Contents 1 Introduction 2 1.1 What problems do macros bring?................ 2 1.1.1 The problems we addressed

More information

The Environment Model. Nate Foster Spring 2018

The Environment Model. Nate Foster Spring 2018 The Environment Model Nate Foster Spring 2018 Review Previously in 3110: Interpreters: ASTs, evaluation, parsing Formal syntax: BNF Formal semantics: dynamic: small-step substitution model static semantics

More information

Integrated Software Environment. Part 2

Integrated Software Environment. Part 2 Integrated Software Environment Part 2 Operating Systems An operating system is the most important software that runs on a computer. It manages the computer's memory, processes, and all of its software

More information

Instance generation from meta-models (for model transformation testing)

Instance generation from meta-models (for model transformation testing) Instance generation from meta-models (for model transformation testing) Robbe De Jongh University of Antwerp Abstract Testing model transformations is a tedious job. One needs to make a representative

More information

CPU DB Data Visualization Senior Project Report

CPU DB Data Visualization Senior Project Report CPU DB Data Visualization Senior Project Report Marek Moreno ( mmoren14@calpoly.edu ) Ruchita Patel ( rpatel31@calpoly.edu ) 16 June 2017 Introduction Project Overview/Executive Summary Given the CPU database

More information

Introduction to C/C++ Programming

Introduction to C/C++ Programming Chapter 1 Introduction to C/C++ Programming This book is about learning numerical programming skill and the software development process. Therefore, it requires a lot of hands-on programming exercises.

More information

CS103 Handout 29 Winter 2018 February 9, 2018 Inductive Proofwriting Checklist

CS103 Handout 29 Winter 2018 February 9, 2018 Inductive Proofwriting Checklist CS103 Handout 29 Winter 2018 February 9, 2018 Inductive Proofwriting Checklist In Handout 28, the Guide to Inductive Proofs, we outlined a number of specifc issues and concepts to be mindful about when

More information

Code::Blocks Student Manual

Code::Blocks Student Manual Code::Blocks Student Manual Lawrence Goetz, Network Administrator Yedidyah Langsam, Professor and Theodore Raphan, Distinguished Professor Dept. of Computer and Information Science Brooklyn College of

More information

If Statements, For Loops, Functions

If Statements, For Loops, Functions Fundamentals of Programming If Statements, For Loops, Functions Table of Contents Hello World Types of Variables Integers and Floats String Boolean Relational Operators Lists Conditionals If and Else Statements

More information

C++ for Java Programmers

C++ for Java Programmers Basics all Finished! Everything we have covered so far: Lecture 5 Operators Variables Arrays Null Terminated Strings Structs Functions 1 2 45 mins of pure fun Introduction Today: Pointers Pointers Even

More information

Compositional Model Based Software Development

Compositional Model Based Software Development Compositional Model Based Software Development Prof. Dr. Bernhard Rumpe http://www.se-rwth.de/ Seite 2 Our Working Groups and Topics Automotive / Robotics Autonomous driving Functional architecture Variability

More information

Harvard School of Engineering and Applied Sciences CS 152: Programming Languages

Harvard School of Engineering and Applied Sciences CS 152: Programming Languages Harvard School of Engineering and Applied Sciences CS 152: Programming Languages Lecture 24 Thursday, April 19, 2018 1 Error-propagating semantics For the last few weeks, we have been studying type systems.

More information

Kent Academic Repository

Kent Academic Repository Kent Academic Repository Full text document (pdf) Citation for published version Chitil, Olaf (2006) Promoting Non-Strict Programming. In: Draft Proceedings of the 18th International Symposium on Implementation

More information

Project Compiler. CS031 TA Help Session November 28, 2011

Project Compiler. CS031 TA Help Session November 28, 2011 Project Compiler CS031 TA Help Session November 28, 2011 Motivation Generally, it s easier to program in higher-level languages than in assembly. Our goal is to automate the conversion from a higher-level

More information

Static verification of program running time

Static verification of program running time Static verification of program running time CIS 673 course project report Caleb Stanford December 2016 Contents 1 Introduction 2 1.1 Total Correctness is Not Enough.................................. 2

More information

! Broaden your language horizons! Different programming languages! Different language features and tradeoffs. ! Study how languages are implemented

! Broaden your language horizons! Different programming languages! Different language features and tradeoffs. ! Study how languages are implemented Course Goal CMSC 330: Organization of Programming Languages Introduction Learn how programming languages work Broaden your language horizons! Different programming languages! Different language features

More information

Project 2: Scheme Interpreter

Project 2: Scheme Interpreter Project 2: Scheme Interpreter CSC 4101, Fall 2017 Due: 12 November 2017 For this project, you will implement a simple Scheme interpreter in C++ or Java. Your interpreter should be able to handle the same

More information

CS 6353 Compiler Construction Project Assignments

CS 6353 Compiler Construction Project Assignments CS 6353 Compiler Construction Project Assignments In this project, you need to implement a compiler for a language defined in this handout. The programming language you need to use is C or C++ (and the

More information

Semantic Analysis. Outline. The role of semantic analysis in a compiler. Scope. Types. Where we are. The Compiler so far

Semantic Analysis. Outline. The role of semantic analysis in a compiler. Scope. Types. Where we are. The Compiler so far Outline Semantic Analysis The role of semantic analysis in a compiler A laundry list of tasks Scope Static vs. Dynamic scoping Implementation: symbol tables Types Statically vs. Dynamically typed languages

More information

What is the Best Way for Children to Learn Computer Programming?

What is the Best Way for Children to Learn Computer Programming? What is the Best Way for Children to Learn Computer Programming? Dr Alex Davidovic One of the defining characteristics of today s society is that the computers and mobile devices are the integral and natural

More information

CS 211 Programming Practicum Spring 2018

CS 211 Programming Practicum Spring 2018 Due: Thursday, 4/5/18 at 11:59 pm Infix Expression Evaluator Programming Project 5 For this lab, write a C++ program that will evaluate an infix expression. The algorithm REQUIRED for this program will

More information