BUILD ON THE POLYGLOT COMPILER FRAMEWORK MIHAL BRUMBULLI 7th Workshop “SEERE” Montenegro-Risan 9-14 September 2007 SimJ Programming Language.

Slides:



Advertisements
Similar presentations
AP Computer Science Anthony Keen. Computer 101 What happens when you turn a computer on? –BIOS tries to start a system loader –A system loader tries to.
Advertisements

IT 325 OPERATING SYSTEM C programming language. Why use C instead of Java Intermediate-level language:  Low-level features like bit operations  High-level.
Formal Language, chapter 4, slide 1Copyright © 2007 by Adam Webber Chapter Four: DFA Applications.
Intermediate Code Generation
Control Flow Analysis (Chapter 7) Mooly Sagiv (with Contributions by Hanne Riis Nielson)
Object Oriented Programming in Java George Mason University Fall 2011
Lab#1 (14/3/1431h) Introduction To java programming cs425
Slides prepared by Rose Williams, Binghamton University Chapter 1 Getting Started 1.1 Introduction to Java.
WPSM Programming Language A simple language that transform simple data structure into complex xML format Wai Y. Wong Peter Chen Seema Gupta Miqdad Mohammed.
Outline Java program structure Basic program elements
Polyglot: An Extensible Compiler Framework for Java Nathaniel Nystrom, Michael R. Clarkson, and Andrew C. Myers Presentation by Aaron Kimball & Ben Lerner.
CS-341 Dick Steflik Introduction. C++ General purpose programming language A superset of C (except for minor details) provides new flexible ways for defining.
CS-341 Dick Steflik Introduction. C++ General purpose programming language A superset of C (except for minor details) provides new flexible ways for defining.
Programming in Java; Instructor:Alok Mehta Objects, Classes, Program Constructs1 Programming in Java Objects, Classes, Program Constructs.
Transformation of Java Card into Diet Java Semester Project Presentation Erich Laube.
7/2/2015CS2621 OO Design and Programming II I/O: Reading and Writing.
CS 153: Concepts of Compiler Design August 25 Class Meeting Department of Computer Science San Jose State University Fall 2014 Instructor: Ron Mak
Compiler design Computer Science Rensselaer Polytechnic Lecture 1.
Lecture 1: Overview of Java. What is java? Developed by Sun Microsystems (James Gosling) A general-purpose object-oriented language Based on C/C++ Designed.
Copyright 2013 by Pearson Education Building Java Programs Chapter 1 Lecture 1-1: Introduction; Basic Java Programs reading:
CSC3170 Introduction to Database Systems
Polyglot An Extensible Compiler Framework for Java Nathaniel Nystrom Michael R. Clarkson Andrew C. Myers Cornell University.
Presented By: Shriraksha Mohan Nathaniel Nystrom, Michael R. Clarkson, and Andrew C. Myers.
Georgia Institute of Technology Speed part 3 Barb Ericson Georgia Institute of Technology May 2006.
C++ Code Analysis: an Open Architecture for the Verification of Coding Rules Paolo Tonella ITC-irst, Centro per la Ricerca Scientifica e Tecnologica
Compiler1 Chapter V: Compiler Overview: r To study the design and operation of compiler for high-level programming languages. r Contents m Basic compiler.
Chapter 1 Introduction Dr. Frank Lee. 1.1 Why Study Compiler? To write more efficient code in a high-level language To provide solid foundation in parsing.
1 October 1, October 1, 2015October 1, 2015October 1, 2015 Azusa, CA Sheldon X. Liang Ph. D. Computer Science at Azusa Pacific University Azusa.
Chapter 10: Compilers and Language Translation Invitation to Computer Science, Java Version, Third Edition.
Java Programming Introduction & Concepts. Introduction to Java Developed at Sun Microsystems by James Gosling in 1991 Object Oriented Free Compiled and.
CSC 338: Compiler design and implementation
By Nicholas Policelli An Introduction to Java. Basic Program Structure public class ClassName { public static void main(String[] args) { program statements.
1 Java Console I/O Introduction. 2 Java I/O You may have noticed that all the I/O that we have done has been output The reasons –Java I/O is based on.
Lexical Analysis - An Introduction. The Front End The purpose of the front end is to deal with the input language Perform a membership test: code  source.
1 Computer Systems -- Introduction  Chapter 1 focuses on:  the structure of a Java application  basic program elements  preparing and executing a program.
CSC Java Programming, Fall, 2008 Week 2: Java Data Types, Control Constructs, and their C++ counterparts, September 4.
Basic Java Programming CSCI 392 Week Two. Stuff that is the same as C++ for loops and while loops for (int i=0; i
1 Top Down Parsing. CS 412/413 Spring 2008Introduction to Compilers2 Outline Top-down parsing SLL(1) grammars Transforming a grammar into SLL(1) form.
CS 11 java track: lecture 1 Administrivia need a CS cluster account cgi-bin/sysadmin/account_request.cgi need to know UNIX
Geoff Holmes and Bernhard Pfahringer COMP206-08S General Programming 2.
1 COMP 3438 – Part II-Lecture 1: Overview of Compiler Design Dr. Zili Shao Department of Computing The Hong Kong Polytechnic Univ.
Java means Coffee Java Coffee Beans The name “JAVA” was taken from a cup of coffee.
Input & Output In Java. Input & Output It is very complicated for a computer to show how information is processed. Although a computer is very good at.
Netprog: Java Intro1 Crash Course in Java. Netprog: Java Intro2 Why Java? Network Programming in Java is very different than in C/C++ –much more language.
What does a computer program look like: a general overview.
CIS 260: App Dev I. 2 Programs and Programming n Program  A sequence of steps designed to accomplish a task n Program design  A detailed _____ for implementing.
Advanced Compiler Design An Introduction to the Javali Compiler Framework Zoltán Majó 1.
CPS 506 Comparative Programming Languages Syntax Specification.
Introduction to Compilers. Related Area Programming languages Machine architecture Language theory Algorithms Data structures Operating systems Software.
1 Compiler Design (40-414)  Main Text Book: Compilers: Principles, Techniques & Tools, 2 nd ed., Aho, Lam, Sethi, and Ullman, 2007  Evaluation:  Midterm.
BEGINNING PROGRAMMING.  Literally – giving instructions to a computer so that it does what you want  Practically – using a programming language (such.
Core Java Introduction Byju Veedu Ness Technologies httpdownload.oracle.com/javase/tutorial/getStarted/intro/definition.html.
Fall 2002CS 150: Intro. to Computing1 Streams and File I/O (That is, Input/Output) OR How you read data from files and write data to files.
CS101: Introduction to Computer Science Slides adapted from Sedgewick and Wayne Copyright © Your First Java.
Using the while-statement to process data files. General procedure to access a data file General procedure in computer programming to read data from a.
MiniJava Compiler A multi-back-end JIT compiler of Java.
Copyright 2010 by Pearson Education APCS Building Java Programs Chapter 1 Lecture 1-1: Introduction; Basic Java Programs reading:
CPSC 233 Tutorial January 21 st /22 nd, Linux Commands.
Lecture 9 Symbol Table and Attributed Grammars
The need for Programming Languages
Compiler Design (40-414) Main Text Book:
OO Design and Programming II I/O: Reading and Writing
Introduction to Compiler Construction
CS 3304 Comparative Languages
Objects, Classes, Program Constructs
Chapter 1: Introduction to Compiling (Cont.)
CS 536 / Fall 2017 Introduction to programming languages and compilers
An Introduction to Java – Part I, language basics
CSE401 Introduction to Compiler Construction
Presentation transcript:

BUILD ON THE POLYGLOT COMPILER FRAMEWORK MIHAL BRUMBULLI 7th Workshop “SEERE” Montenegro-Risan 9-14 September 2007 SimJ Programming Language

Introduction Goal: “Build a new programming language”  For beginners  Redable & Easy code  No complexity  Basic functionality (found in beginners programming text books)  For compiler design  Basic functionality (not too complex)  Most important data types  Very similiar to Java (not an exact copy of it)  Implemented in a compiler framework 2 Polytechnic University of Tirana M. Brumbulli

Polyglot Compiler Framework An extensible Java compiler toolkit designed for experimentation with new language extensions. The base polyglot compiler is a mostly-complete Java front end.  It parses, performs semantic checking on Java source code and outputs Java source code.  Its power consists in doing so on other languages source codes. The AST is translated into a Java AST and the existing code is output into a Java source file which can then be compiled with javac. 3 Polytechnic University of Tirana M. Brumbulli

Framework Architecture M. Brumbulli Polytechnic University of Tirana 4

Language Extensions An extension is a source-to-source compiler that accepts a program written in a language extension and translates it to Java source code. The first step in compilation is parsing input source code to produce an AST.  Polyglot includes an extensible parser generator, PPG, which allows the implementer to define the syntax of the language extension as a set of changes to the base grammar for Java. M. Brumbulli Polytechnic University of Tirana 5

Language Extentions cont... The second step consist in a set of passes that transform the produced AST in a JavaAST.  The pass scheduler selects passes to run over the AST of a single source file in an order defined by the extension.  Each compilation pass, if successful, rewrites the AST, producing a new AST that is the input to the next pass. Finally, a Java compiler such as javac is invoked to compile the Java code to bytecode. M. Brumbulli Polytechnic University of Tirana 6

SimJ Language Is a simplified version of the Java programming language.  Not just a reduced copy of Java (MiniJava). Simple Java like program structure.  Not some simple, command like instructions (J 0 ). Two possible targets:  Beginners with no experience in programming.  Compiler construction. M. Brumbulli Polytechnic University of Tirana 7

SimJ Language cont... Classes, Methods,... Data types  boolean – true or false  int – integers  char – characters  string – sequence of characters  int[] – array of integers Control flow  if else  for  while  switch M. Brumbulli Polytechnic University of Tirana 8

Java SimJ public class A { public static void main(String[] args) { try { BufferedReader reader = new BufferedReader(new InputStreamReader (System.in)); System.out.print(“Your name:”); String name = reader.readLine(); System.out.print(“\nHello, ”+name+ “!”); } catch (IOException ioexeption) { System.out.println(ioexeption); } class A { main() { print(“Your name:”); string name = readLine(); print(“\nHello, ”+name+“!”); } SimJ vs Java M. Brumbulli Polytechnic University of Tirana 9

Implementation The design process of SimJ includes the following tasks:  Syntactic differences between SimJ and Java are defined based on the Java grammar:  polyglot/ext/jl/parse/java12.cup.  Any new AST nodes that SimJ requires are defined based on the existing Java nodes found in:  polyglot.ast and polyglot.ext.jl.ast.  Semantic differences between SimJ and Java are defined.  Translation from SimJ to Java is defined. The translation produces a legal Java program that can be compiled by javac. M. Brumbulli Polytechnic University of Tirana 10

Implementation cont... Resulting packages are:  ext.simj.ast  AST nodes specific to SimJ language.  ext.simj.extension  New extension and delegate objects specific to SimJ.  ext.simj.types  Type objects and typing judgments specific to SimJ.  ext.simj.visit  Visitors specific to SimJ.  ext.simj.parse  The parser and lexer for the SimJ language. M. Brumbulli Polytechnic University of Tirana 11

Conclusions SimJ is a simple programming language that improves the learning of programming basic structures.  the existing approaches did not fully address the problem of a simplified Java like structured language and that is not only a reduced copy of it. Simplicity of SimJ is principally gained by hiding some of the Java object-orientation syntax in the usage of basic statements.  This improves the understandability of the code, making it less confusing and definitely more easy to learn. M. Brumbulli Polytechnic University of Tirana 12

Conclusions cont... Polyglot Framework is an effective and easy way to produce compilers for Java-like languages like SimJ.  It offers the possibility to generate a base skeleton for new language extensions on witch we can add the desired specifications. SimJ is a simplified version of the Java programming language that is not only a reduced copy of it.  SimJ could be used by beginners that want to learn Java but don’t know anything about programming.  It is also a good choice for learning compiler design because of its well defined and easy to implement structure. M. Brumbulli Polytechnic University of Tirana 13

MIHAL BRUMBULLI THANK YOU!