|
|
Abstract Syntax Trees ExercisesThese exercises are all related to the expression examples we've been looking at in class and in the Examples listed below.
Reading
Materials ExamplesIn the compiler SVN repository, the compiler-examples project ...src-antlr contains the antlr.astexample directory which includes the ASTOperator.g and ASTRewrite.g files that make use ANTLR's builtin support for tree construction and transformation. It also has, in antlr.example4, the grammar Example4.g which defines semantic actions to evaluate a given input expression. src-jdt contains some fragments of code that illustrate how to use the JDT. The CollectXTest.java program is a unit test driver to exercise the CollectInt.java and ColelctName.java functionality. A third interesting example is not loaded into SVN yet; it is accessible here. You should unzip this archive into your workspace and it will create the directory antlr.explicitast. This contains an example that explicitly constructs a non-ANTLR representation of a simple expression AST. It is instructive to study as you are getting started.
Use these as starting points to explore ANTLR's support for syntax
directed translation and semantic actions. You should feel free
to modify and experiment with them.
|