1 / 14

SimJ Programming Language

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

komala
Download Presentation

SimJ Programming Language

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


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

  2. 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 Polytechnic University of Tirana

  3. 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. Polytechnic University of Tirana

  4. Framework Architecture Polytechnic University of Tirana

  5. 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. Polytechnic University of Tirana

  6. 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. Polytechnic University of Tirana

  7. 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. Polytechnic University of Tirana

  8. 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 Polytechnic University of Tirana

  9. SimJ vs Java 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+“!”); } } Polytechnic University of Tirana

  10. 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. Polytechnic University of Tirana

  11. 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. Polytechnic University of Tirana

  12. 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. Polytechnic University of Tirana

  13. 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. Polytechnic University of Tirana

  14. THANK YOU! Mihal brumbulli

More Related