simj programming language
DESCRIPTION
SimJ Programming Language. BUILD ON THE POLYGLOT COMPILER FRAMEWORK MIHAL BRUMBULLI 7th Workshop “SEERE” Montenegro-Risan 9-14 September 2007. Introduction. Goal: “Build a new programming language” For beginners Redable & Easy code No complexity - PowerPoint PPT PresentationTRANSCRIPT
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. BrumbulliPolytechnic 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. BrumbulliPolytechnic 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. BrumbulliPolytechnic 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 (J0) .
Two possible targets: Beginners with no experience in programming. Compiler construction.
M. BrumbulliPolytechnic 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. BrumbulliPolytechnic University of Tirana
8
JavaJava SimJSimJ
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. BrumbulliPolytechnic 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. BrumbulliPolytechnic 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. BrumbulliPolytechnic 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. BrumbulliPolytechnic 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. BrumbulliPolytechnic University of Tirana
13
MIHAL BRUMBULLI
THANK YOU!