a java compiler front end major project

Upload: singaravelan-senthilkarasu

Post on 02-Jun-2018

215 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/11/2019 A Java Compiler Front End major project

    1/4

    A Java Compiler Front End

    A compiler reads a source program and translates it into an executable set of

    instructions (e.g., Java byte codes, native machine instructions). The Bear

    Products nternational compiler is itself internally structured as a set oftranslations. The BP Java front end uses a parser generated from an !"

    grammar by the A#T!"parser generator. The parser reads the Java source and

    outputs an Abstract $yntax Tree (A$T). The tree structure is carefully chosen to

    ma%e later passes over the tree simpler.

    The !" grammar, embedded &'' actions and comments consist of about ,

    lines. This grammar is based heavily on the Java grammar developed by

    Terence Parr, John !illey, John *itchell and $cott $tanchfield. This grammar is

    part of the A#T!" release. Although the grammar is relatively large, it does

    not report all syntactically incorrect Java programs. +olloing the parser pass,

    there is a pass that does additional syntactic chec%ing. +or a partial list of thesechec%s, clic% here

    &ompiling a language into native code can be thought of as the process of

    throing out information during translation until the correct instruction

    se-uence is created. This process of information distillation happens in all

    compiler phase, including the front end. To ma%e A$T processing easier, the

    A$T does not provide an exact mirror of the Java source. $yntactic elements

    li%e parentheses, hich are needed in the language to demarcate a production

    li%e an argument list, can be discarded in the A$T.

    Although it is rarely discussed, a great deal of or% goes into clearly

    representing a language in A$T form. The A$T trees generated for eachlanguage production must be built so that they still contain enough information

    so that elements of the production can be recognied by later passes hich

    al% the trees. n the case of the BP Java front end, this A$T is created by the

    &'' code associated ith the grammar productions.

    The output of the Java parser produces an intermediate that represents

    declarations (e.g., interfaces, classes, methods, and class members). These

    declarations are entered into the symbol table. Processing local declarations

    re-uires first processing imported class pac%ages and classes (/ava.lang is

    alays imported by default, for example). A Java file source ill contain either

    implicit or explicit import statements (/ava.lang.0 is implicitly imported into allJava source files). These define types, including the base type Object, that are

    referenced by local ob/ects defined in the source.

    The Java front end resolves any ob/ects that are not defined locally from the

    import paths. The front end searches for .classfiles for the undefined ob/ects. f

    a .class file for the ob/ect is not found, the front end searches for the

    associated .javafile and compiles it into a .class file. f a class file is found, the

    http://www.bearcave.com/software/antlr/index.htmlhttp://www.bearcave.com/software/java/todo.htmlhttp://www.bearcave.com/software/antlr/index.htmlhttp://www.bearcave.com/software/java/todo.html
  • 8/11/2019 A Java Compiler Front End major project

    2/4

    Java front end chec% to see if the time stamp on the class file is later than the

    time stamp on any associated source. f the source time stamp is neer, the

    class file must be recompiled. The re-uirement that the front end rebuild Java

    class files as necessary removes the need for a program li%e 1#23s makeor

    4indos nmake. But it moves this burden into the front end.

    4hen the class file for a ob/ect is obtained, the Java front end reads the symbolinformation stored in the Java class file (seeJavad5 a class file disassembler).

    The abstract syntax tree is composed of non6terminal nodes, li%e operators and

    terminal nodes li%e identifiers and constants. 4hen all external symbols are

    read, the local symbol can be resolved. This allos all A$T nodes to be

    annotated ith the associated symbol or type information.

    After resolving all symbols and types the declarations are 7pruned7 from the

    A$T. Then the Java front end ma%es a semantic chec%ing pass over the A$T.

    +or example, the Java front end verifies that an assignment statement ith

    a newexpression on the right hand side has a reference variable on the left. f

    no semantic errors are found, the A$T is no considered a representation of a

    correct Java program. The declarations are pruned from the decorated A$T.

    This pruned A$T is the output of the Java front end. This serves as the input to

    the tree to tree transformation pass.

    The Java programming-language compiler (javac) group

    This groupis comprised of developers involved in the design, implementation, andmaintenance of the Java programming language compiler (javac) and associatedcomponents.

    Note:As of build 24, We have restructured the source code so that javac, javadoc,javah, javap, and apt no all live in a ne repositor! called langtools.

    Introduction

    The Java programming"language compiler (javac) reads source files ritten in theJava programming language, and compiles them into b!tecode class files. #ptionall!,the compiler can also process annotations found in source and class files using the$luggable Annotation $rocessing A$%. The compiler is a command line tool but canalso be invo&ed using the Java 'ompiler A$%.

    The compiler accepts source code defined b! the Java anguage pecification (J)and produces class files defined b! the Java *irtual +achine pecification (J*+).

    Source Code

    The compiler source code is available in the #penJ- +ercurial repositories,athttp//hg.openjd&.java.net/.

    The master sources are

    in http//hg.openjd&.java.net/jd&0/jd&0/langtools. We integrate to the master repositories through the 1tl1 forest, so the

    ver! latest sources for the compiler are

    http://www.bearcave.com/software/java/javad/index.htmlhttp://openjdk.java.net/groups/index.htmlhttp://java.sun.com/docs/books/jls/third_edition/html/j3TOC.htmlhttp://java.sun.com/docs/books/vmspec/2nd-edition/html/VMSpecTOC.doc.htmlhttp://hg.openjdk.java.net/http://hg.openjdk.java.net/jdk7/jdk7/langtoolshttp://www.bearcave.com/software/java/javad/index.htmlhttp://openjdk.java.net/groups/index.htmlhttp://java.sun.com/docs/books/jls/third_edition/html/j3TOC.htmlhttp://java.sun.com/docs/books/vmspec/2nd-edition/html/VMSpecTOC.doc.htmlhttp://hg.openjdk.java.net/http://hg.openjdk.java.net/jdk7/jdk7/langtools
  • 8/11/2019 A Java Compiler Front End major project

    3/4

    inhttp//hg.openjd&.java.net/jd&0/tl/langtools. The integrations normall!happen bi"ee&l! !ou can see the integration schedule for J- 0 here.

    3or general information about the #penJ- repositories, and ho to clone them,see The #penJ- evelopers 5uide. 3or the compiler, !ou can donload and build itas part of a complete J- forest, or !ou can just donload and buildthelangtoolsrepositor! to build a standalone version of the compiler.

    6ote that the code for the native launcher for javacis shared ith all the other J-

    tools, and lives in the J- repositor!. %f !ou just donload and buildthelangtoolsrepositor!, !ou ill get an e7ecutable jar file hich !ou can invo&e

    directl! ith the javacommand, or ith a simple shell script that is provided.

    Windos users ill need '!gin or similar pac&ages to run the shell script.

    8ou can brose the compiler sources ith #pen5ro&. 'urrentl!, this is based on theinitial #penJ- release of the compiler, and so is not completel! up to date.

    Documentation

    %f !ouve cloned the langtoolsrepositor!, heres ho to ...

    9uild the compiler ith Ant, +a&e, or the 6et9eans %:

    *ersion ;.; or later.

  • 8/11/2019 A Java Compiler Front End major project

    4/4

    Ale7 9uc&le!

    +auri@io 'imadamore

    Joe arc!

    6eal 5after

    Jonathan 5ibbons

    'lumni

    $eter von der Ah

    http://blogs.sun.com/abuckleyhttp://blogs.sun.com/mcimadamorehttp://blogs.sun.com/darcyhttp://http//gafter.blogspot.com/http://blogs.sun.com/jjghttp://blogs.sun.com/ahe/http://blogs.sun.com/abuckleyhttp://blogs.sun.com/mcimadamorehttp://blogs.sun.com/darcyhttp://http//gafter.blogspot.com/http://blogs.sun.com/jjghttp://blogs.sun.com/ahe/