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 of translations. 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. +ollo,ing the parser pass, there is a pass that does additional syntactic chec%ing. +or a partial list of these chec%s, clic% here &ompiling a language into native code can be thought of as the process of thro,ing 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 each language production must be built so that they still contain enough information so that elements of the production can be recogni.ed 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 al,ays imported by default, for example). A Java file source ,ill contain either implicit or explicit import statements (/ava.lang.0 is implicitly imported into all Java 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 .class files for the undefined ob/ects. f a .class file for the ob/ect is not found, the front end searches for the associated .java file and compiles it into a .class file. f a class file is found, the 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 ne,er, 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 make or 4indo,s 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 symbol information 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 allo,s 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 new expression 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 group is comprised of developers involved in the design, implementation, and maintenance of the Java programming language compiler (javac) and associated components. 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 the Java 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 can also 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 inhttp.//hg.openjd&.java.net/jd&0/tl/langtools. The integrations normall! happen bi"ee&l!2 !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,- ,eveloper4s 5uide. 3or the compiler, !ou can donload and build it as part of a complete J,- forest, or !ou can just donload and build thelangtools repositor! to build a standalone version of the compiler. 6ote that the code for the native launcher for javac is shared ith all the other J,- tools, and lives in the J,- repositor!. %f !ou just donload and build thelangtools repositor!, !ou ill get an e7ecutable jar file hich !ou can invo&e directl! ith the java command, 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 the initial #penJ,- release of the compiler, and so is not completel! up to date. Documentation %f !ou4ve cloned the langtools repositor!, here4s ho to ... 9uild the compiler ith Ant, +a&e, or the 6et9eans %,: *ersion ;.; or later. <un the unit and regression tests <un the compiler that !ou built =o to ... +odif! this page =elp translate compiler diagnostic messages >ser 5uide $ac&age #vervie (6:W) 'ompilation #vervie (6:W) #vervie of the compiler4s operation (#(,) )o !ou ant to change the Java $rogramming (anguage... )o !ou ant to change 1javac1 ... Resources The folloing lin&s are for resources about the compiler, provided b! non")un contributors. Note: )ince the #penJ,- project is going through changes, these resources ma! not ala!s be completel! up to date. =ac&ing the #penJ,- compiler b! Ale7ander =ristov Related rojects J,- ? and J,- 0 +odules Communit! "ailing lists compiler"dev #itchen Sin$ %anguage (#S%) Compiler &loggers Ale7 9uc&le! +auri@io 'imadamore Joe ,arc! 6eal 5after Jonathan 5ibbons 'lumni $eter von der AhA