MiniJava Compiler A multi-back-end JIT compiler of Java.

Slides:



Advertisements
Similar presentations
CPSC 388 – Compiler Design and Construction
Advertisements

Abstract Syntax Mooly Sagiv html:// 1.
1 JavaCUP JavaCUP (Construct Useful Parser) is a parser generator Produce a parser written in java, itself is also written in Java; There are many parser.
1 Pass Compiler 1. 1.Introduction 1.1 Types of compilers 2.Stages of 1 Pass Compiler 2.1 Lexical analysis 2.2. syntactical analyzer 2.3. Code generation.
CPSC Compiler Tutorial 9 Review of Compiler.
Parsing Discrete Mathematics and Its Applications Baojian Hua
Copyright © 2006 The McGraw-Hill Companies, Inc. Programming Languages 2nd edition Tucker and Noonan Chapter 2 Syntax A language that is simple to parse.
Abstract Syntax Trees Compiler Baojian Hua
Context-Free Grammars Lecture 7
BİL744 Derleyici Gerçekleştirimi (Compiler Design)1.
CPSC Compiler Tutorial 3 Parser. Parsing The syntax of most programming languages can be specified by a Context-free Grammar (CGF) Parsing: Given.
Copyright © 2006 The McGraw-Hill Companies, Inc. Programming Languages 2nd edition Tucker and Noonan Chapter 3 Lexical and Syntactic Analysis Syntactic.
1.3 Executing Programs. How is Computer Code Transformed into an Executable? Interpreters Compilers Hybrid systems.
Abstract Syntax Trees Lecture 14 Wed, Mar 3, 2004.
2.2 A Simple Syntax-Directed Translator Syntax-Directed Translation 2.4 Parsing 2.5 A Translator for Simple Expressions 2.6 Lexical Analysis.
Course Revision Contents  Compilers  Compilers Vs Interpreters  Structure of Compiler  Compilation Phases  Compiler Construction Tools  A Simple.
ICS611 Introduction to Compilers Set 1. What is a Compiler? A compiler is software (a program) that translates a high-level programming language to machine.
CPSC 388 – Compiler Design and Construction Parsers – Context Free Grammars.
COP4020 Programming Languages
Semantic Analysis (Generating An AST) CS 471 September 26, 2007.
1 Week 4 Questions / Concerns Comments about Lab1 What’s due: Lab1 check off this week (see schedule) Homework #3 due Wednesday (Define grammar for your.
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 Week 3 Questions / Concerns What’s due: Lab1b due Friday at midnight Lab1b check-off next week (schedule will be announced on Monday) Homework #2 due.
Lesson 3 CDT301 – Compiler Theory, Spring 2011 Teacher: Linus Källberg.
D. M. Akbar Hussain: Department of Software & Media Technology 1 Compiler is tool: which translate notations from one system to another, usually from source.
Interpretation Environments and Evaluation. CS 354 Spring Translation Stages Lexical analysis (scanning) Parsing –Recognizing –Building parse tree.
BUILD ON THE POLYGLOT COMPILER FRAMEWORK MIHAL BRUMBULLI 7th Workshop “SEERE” Montenegro-Risan 9-14 September 2007 SimJ Programming Language.
Bernd Fischer RW713: Compiler and Software Language Engineering.
Prof. Fateman CS 164 Lecture 111 Syntax  Simple Semantics Lecture 11.
Towards the better software metrics tool motivation and the first experiences Gordana Rakić Zoran Budimac.
CPS 506 Comparative Programming Languages Syntax Specification.
Introduction Lecture 1 Wed, Jan 12, The Stages of Compilation Lexical analysis. Syntactic analysis. Semantic analysis. Intermediate code generation.
D Goforth COSC Translating High Level Languages Note error in assignment 1: #4 - refer to Example grammar 3.4, p. 126.
. n COMPILERS n n AND n n INTERPRETERS. -Compilers nA compiler is a program thatt reads a program written in one language - the source language- and translates.
Introduction to Compiling
Muhammad Idrees, Lecturer University of Lahore 1 Top-Down Parsing Top down parsing can be viewed as an attempt to find a leftmost derivation for an input.
Compiler Design Introduction 1. 2 Course Outline Introduction to Compiling Lexical Analysis Syntax Analysis –Context Free Grammars –Top-Down Parsing –Bottom-Up.
1 LEX & YACC Tutorial February 28, 2008 Tom St. John.
Compiler Construction By: Muhammad Nadeem Edited By: M. Bilal Qureshi.
1 Compiler & its Phases Krishan Kumar Asstt. Prof. (CSE) BPRCE, Gohana.
What am I? while b != 0 if a > b a := a − b else b := b − a return a AST == Abstract Syntax Tree.
1 A Simple Syntax-Directed Translator CS308 Compiler Theory.
C H A P T E R T W O Linking Syntax And Semantics Programming Languages – Principles and Paradigms by Allen Tucker, Robert Noonan.
What is a compiler? –A program that reads a program written in one language (source language) and translates it into an equivalent program in another language.
Compiler Construction CPCS302 Dr. Manal Abdulaziz.
Costas Busch - LSU1 Parsing. Costas Busch - LSU2 Compiler Program File v = 5; if (v>5) x = 12 + v; while (x !=3) { x = x - 3; v = 10; } Add v,v,5.
CSC 4181 Compiler Construction
LECTURE 3 Compiler Phases. COMPILER PHASES Compilation of a program proceeds through a fixed series of phases.  Each phase uses an (intermediate) form.
ICS312 Introduction to Compilers Set 23. What is a Compiler? A compiler is software (a program) that translates a high-level programming language to machine.
Overview of Compilation Prepared by Manuel E. Bermúdez, Ph.D. Associate Professor University of Florida Programming Language Principles Lecture 2.
CS416 Compiler Design1. 2 Course Information Instructor : Dr. Ilyas Cicekli –Office: EA504, –Phone: , – Course Web.
CS 404Ahmed Ezzat 1 CS 404 Introduction to Compiler Design Lecture Ahmed Ezzat.
Lecture 9 Symbol Table and Attributed Grammars
Chapter 3 – Describing Syntax
Introduction to Compiler Construction
Programming Languages 2nd edition Tucker and Noonan
A Simple Syntax-Directed Translator
Parsing & Context-Free Grammars
Programming Languages Translator
Introduction to Parsing (adapted from CS 164 at Berkeley)
PROGRAMMING LANGUAGES
CS416 Compiler Design lec00-outline September 19, 2018
CPSC 388 – Compiler Design and Construction
Introduction CI612 Compiler Design CI612 Compiler Design.
CSE401 Introduction to Compiler Construction
Syntax-Directed Translation
Programming Languages 2nd edition Tucker and Noonan
CS416 Compiler Design lec00-outline February 23, 2019
High-Level Programming Language
Lec00-outline May 18, 2019 Compiler Design CS416 Compiler Design.
Presentation transcript:

MiniJava Compiler A multi-back-end JIT compiler of Java

Team Instructor 华保健 Participants 徐波 孙浩 裴达凯 范琳 张腾宇

What we have achieved What is unfinished yet What we will go on with

Our original plan Lexical analysis Parsing Type check Translation

Our accomplishment Lexical analysis Parsing AST disposal Translation

Lexer Tool: Jflex  Announced to be “The Fast Scanner Generator for Java” From source language into target language, a compiler must first pull it apart and understand its structure and meaning, then put it together in a different way Here we break the input into individual words or "tokens"

Part of “miniJava.flex” //Macro Declarations INTEGER=0|[1-9][0-9]* ALPHA=[A-Za-z] … //keywords "void“{ return symbol(sym.VOID); } "main“{ return symbol(sym.MAIN); } … //operator "&&“{ return symbol(sym.AND); } "<“{ return symbol(sym.LESS); } "!“{ return symbol(sym.DENY); } …

Parser Tool: CUP  Parser Generator in Java grammars is used to describe the structure of lexical tokens parsing using a simple algorithm known as context-free grammar production turns into one clause of recursive functions

Part of “parser.cup” //terminal terminal CLASS, MAIN, …, ADD, MINUS… terminal Integer INTEGER; terminal String ID; //non terminal non terminal syntaxTree.exp.exp exp; non terminal syntaxTree.program.program Program; //precedence && associativity precedence left AND; precedence left LESS; precedence left ADD,MINUS; //recursive function Program::= MainClass:m ClassDecl:c {: RESULT = new programMain(m,c); :} | MainClass:m {: RESULT = new programMain(m); :}

Abstract syntax tree A compiler must do more than recognize whether a sentence belongs to the language of a grammar - it must do something useful with that sentence To produce a parse tree - a data structure that later phases of the compiler can traverse Technically, a parse tree has exactly one leaf for each token of the input and one internal node for each grammar rule reduced during the parse Many of the punctuation tokens are redundant and convey no information

Structure of AST Program → MainClass ClassDecl* MainClass → class id { public static void main ( String [] id ) { Statement }} ClassDecl → class id { VarDecl* MethodDecl* } → class id extends id { VarDecl* MethodDecl* } … Exp → Exp op Exp → Exp [ Exp ] → Exp. length → Exp. id ( ExpList ) → INTEGER LITERAL → true → false → id → this → new int [ Exp ] → new id () → ! Exp → ( Exp )

AST of MiniJava Program

Deal with AST Here comes troubles for us Semantic analysis is exhausted Bytecode grammar is a rough task Time is limited No knowledge of intermediate language

Transformation Java 2 C Two choices  Re-construct a AST for C  Use method in AST to convert the representation of Java AST We choose the second one Every class of AST contains the method to output follow the C grammer

Transformation //the root point of AST of MiniJava public class programMain extends program{ … public String toC(){ return (clas.toC()+mainn.toC()); } … //every class contains the method “toC()” public class formalListApp extends formalList{ … public String toC() { return (clas.toC()+" *this, "+t.toC()+' '+id.toC()+' '+fr.toC()); }

Final product Lexical analyze of the whole java file Scan the source code to verify that it belongs to the language of miniJava grammar Store the structure of the file into the abstract syntax tree Convert it into a syntax tree of C The target code can be compiled and run on multi-back-end

Utility E-business Web Site Industrial control software Data-base arrangement Java developing on embedded system

Not the end It’s really a funny thing to construct a Java compiler with Java language Semantic analysis & Intermediate language unfinished We will go on with this topic

Thank you!