Download ppt

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the work of artificial intelligence, which forms the content of this project

Document related concepts
no text concepts found
Transcript
SimJ Programming Language
BUILD ON THE POLYGLOT COMPILER
FRAMEWORK
MIHAL BRUMBULLI
7th Workshop “SEERE”
Montenegro-Risan 9-14 September 2007
Introduction
2
 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

Polytechnic University of Tirana
M. Brumbulli
Polyglot Compiler Framework
3
 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.
Polytechnic University of Tirana
M. Brumbulli
Framework Architecture
4
Polytechnic University of Tirana
M. Brumbulli
Language Extensions
5
 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.
Polytechnic University of Tirana
M. Brumbulli
Language Extentions cont...
6
 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.
Polytechnic University of Tirana
M. Brumbulli
SimJ Language
7
 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 (J0) .
 Two possible targets:
 Beginners with no experience in programming.
 Compiler construction.
Polytechnic University of Tirana
M. Brumbulli
SimJ Language cont...
8
 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
Polytechnic University of Tirana
M. Brumbulli
SimJ vs Java
9
Java
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);
}
}
}
Polytechnic University of Tirana
SimJ
class A {
main() {
print(“Your name:”);
string name = readLine();
print(“\nHello, ”+name+“!”);
}
}
M. Brumbulli
Implementation
10
 The design process of SimJ includes the following
tasks:

Syntactic differences between SimJ and Java are defined based
on the Java grammar:


Any new AST nodes that SimJ requires are defined based on
the existing Java nodes found in:



polyglot/ext/jl/parse/java12.cup.
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.
Polytechnic University of Tirana
M. Brumbulli
Implementation cont...
11
 Resulting packages are:
 ext.simj.ast


ext.simj.extension


Type objects and typing judgments specific to SimJ.
ext.simj.visit


New extension and delegate objects specific to SimJ.
ext.simj.types


AST nodes specific to SimJ language.
Visitors specific to SimJ.
ext.simj.parse

The parser and lexer for the SimJ language.
Polytechnic University of Tirana
M. Brumbulli
Conclusions
12
 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.
Polytechnic University of Tirana
M. Brumbulli
Conclusions cont...
13
 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.
Polytechnic University of Tirana
M. Brumbulli
THANK YOU!
MIHAL BRUMBULLI