|
JastAdd Tutorial Examples
For each of these examples, you can look at the specifications directly from the web pages, or you can download the complete example
and run it.
This example shows how to implement semantic analysis for an object-oriented language with inheritance
and nesting.
Features illustrated include abstract syntax trees, reference attributes, broadcasting,
parameterized attributes, context-dependent rewrites,
circular attributes,
imperative aspects,
and connection to parser.
While the PicoJava language is small, the example shows off the main features in JastAdd and their typical
use. It illustrates how quite complex problems can be solved in a simple way.
E.g., how to implement name resolution in the presence of both inheritance and nesting; how to deal with
qualified names and their types; how to check assignments in
the presence of hierarchical types; and how to use the Null pattern to deal with erroneous programs.
The solutions used in PicoJava are typical for how JastAdd is used, so we recommend studying this example
before looking at real projects like the Extensible Java Compiler.
The DevirtualizationAnalyzer
component is an extension of the Java1.4Frontend that implements a whole-program
analysis of which method calls can be devirtualized. The example illustrates how advanced analyses can
be implemented in a simple way on top of an existing compiler component. The implementation is currently
in an experimental stage, not yet taking all of Java's langauge constructs into account.
The Metrics component is an extension of the Java1.4Frontend that computes a set of object-oriented
metrics proposed by Chidamber and Kemerer. These metrics include structural properties such as
the height of inheritance tree and number of subclasses, but also more global
properties such as the analysis of coupling between classes. Internal
properties such as the lack of cohesion of methods within a class and the
number of weighted methods per class are also computed.
Non-null types is a type-based approach to detect possible null pointer
violations in code statically at compile time. We have extended a Java compiler, in a modular way, to include non-null
types. This is an example of how a large JastAdd project can be extended in an
easy and declarative way. We have also implemented an inference algorithm to
retrofit legacy code to include non-null types.
We show how Java name analysis including ambiguities related to names of variables, fields, and packages, can be implemented in a declarative and modular manner using the JastAdd compiler construction system. The example defines a tiny subset of Java that demonstrates all challenges in Java name analysis. The same technique has been used in the JastAdd Extensible Java Compiler
This example shows how circular attributes can be used for doing a static analysis of
context-free grammars, computing
the Nullable property and the First and Follow symbols for nonterminals in the grammar.
The example provides a nice illustration of the use of several circular attributes.
This example shows how to use JastAdd to implement Knuth's seminal example from 1968
where the values of binary numbers are defined using attribute grammars.
The example illustrates simple use of synthesized and inherited attributes. No parser is included.
The test ASTs are built explicitly in Java code.
This example is very small and simple. It is particularly intended for people already familiar with conventional attribute
grammars,
and who would like to see what this well-known example looks like in JastAdd. Note that this example does
not at all show the full potential of JastAdd since it only
illustrates the simple features of synthesized and inherited attributes.
This is a very small "hello world"-like example showing how you can build a JastAdd project on top of the
parser generator JavaCC and JJTree
(rather than on jflex and beaver). The example also illustrates a simple imperative aspect.
|