Jump to: navigation, search

Difference between revisions of "FAQ What is an AST?"

 
m
Line 1: Line 1:
In traditional compiler design, a lexical scanner first converts an input stream
+
In traditional compiler design, a lexical scanner first converts an input stream into a list of tokens. The tokens are then parsed according to syntax rules for the language, resulting in an abstract syntax tree or AST. Aho, Sethi, and Ullman (1986) distinguish between an <i>abstract syntax tree</i> and a <i>parse tree</i>.  The AST is used for semantic analysis such as type resolution, and is traditionally converted to an  intermediate representation (IR) for optimization and code generation.  The Eclipse Java compiler uses a single AST structure from the initial parse all the way through to code generationn.  This approach allows for heavy optimization of the compiler, avoiding the garbage collection required when using different structures for different phases of the compilation process.   
into a list of tokens. The tokens are then parsed according to syntax rules for
+
the language, resulting in an abstract syntax tree or AST.  
+
Aho, Sethi, and Ullman (1986) distinguish between an <i>abstract syntax tree</i>
+
and a <i>parse tree</i>.  The AST is used for semantic analysis such as  
+
type resolution, and is traditionally converted to an  intermediate representation  
+
(IR) for optimization and code generation.  The Eclipse Java compiler uses a  
+
single AST structure from the initial parse all the way through to code  
+
generation.  This approach allows for heavy optimization of the compiler,
+
avoiding the garbage collection required when using different structures for
+
different phases of the compilation process.   
+
 
+
 
+
Because it powerfully captures the semantic structure of a Java
+
program, an AST is a very useful data structure for any tools that want to
+
perform complex queries or manipulation of a program.  The AST
+
was initially not exposed as API, but many tools were making use of it
+
anyway to perform such manipulation as code refactoring. However,
+
because the compiler&#146;s AST is used for parsing, type resolution, flow analysis,
+
and code generation, the code is very complex and difficult to expose as API.
+
The Java core team decided not to expose its internal AST but instead to
+
expose a clean, new AST. This AST is available in the
+
<tt>org.eclipse.jdt.core.dom</tt> package. Although this isn&#146;t the same
+
AST used by the compiler, it nonetheless provides a rich semantic representation
+
of a Java program, right down to every expression and statement in
+
methods and initializers. This AST optionally supports resolution of all
+
type references but does not provide advanced capabilities such as
+
flow analysis and code generation. Clients can build and manipulate ASTs for any
+
Java source code, whether or not it&#146;s in the workspace.
+
  
 +
Because it powerfully captures the semantic structure of a Java program, an AST is a very useful data structure for any tools that want to perform complex queries or manipulation of a program.  The AST was initially not exposed as API, but many tools were making use of it anyway to perform such manipulation as code refactoring. However, because the compiler&#146;s AST is used for parsing, type resolution, flow analysis, and code generation, the code is very complex and difficult to expose as API. The Java core team decided not to expose its internal AST but instead to expose a clean, new AST. This AST is available in the  <tt>org.eclipse.jdt.core.dom</tt> package. Although this isn&#146;t the same AST used by the compiler, it nonetheless provides a rich semantic representation of a Java program, right down to every expression and statement in methods and initializers. This AST optionally supports resolution of all type references but does not provide advanced capabilities such as flow analysis and code generation. Clients can build and manipulate ASTs for any Java source code, whether or not it&#146;s in the workspace.
  
 
== See Also: ==
 
== See Also: ==
+
*[[FAQ What is the Java model?]]
[[FAQ_What_is_the_Java_model%3F]]
+
*Alfred Aho, Ravi Sathi, and Jeffrey Ullman, [http://www-db.stanford.edu/~ullman/dragon.html <i>Compilers, Principles, Techniques, and Tools</i>] (Addison-Wesley, 1986).
 
+
Alfred Aho, Ravi Sathi, and Jeffrey Ullman, <i>Compilers, Principles,  
+
Techniques, and Tools</i> (Addison-Wesley, 1986).
+
  
<hr><font size=-2>This FAQ was originally published in [http://www.eclipsefaq.org Official Eclipse 3.0 FAQs]. Copyright 2004, Pearson Education, Inc. All rights reserved. This text is made available here under the terms of the [http://www.eclipse.org/legal/epl-v10.html Eclipse Public License v1.0].</font>
+
{{Template:FAQ_Tagline}}

Revision as of 20:23, 19 June 2006

In traditional compiler design, a lexical scanner first converts an input stream into a list of tokens. The tokens are then parsed according to syntax rules for the language, resulting in an abstract syntax tree or AST. Aho, Sethi, and Ullman (1986) distinguish between an abstract syntax tree and a parse tree. The AST is used for semantic analysis such as type resolution, and is traditionally converted to an intermediate representation (IR) for optimization and code generation. The Eclipse Java compiler uses a single AST structure from the initial parse all the way through to code generationn. This approach allows for heavy optimization of the compiler, avoiding the garbage collection required when using different structures for different phases of the compilation process.

Because it powerfully captures the semantic structure of a Java program, an AST is a very useful data structure for any tools that want to perform complex queries or manipulation of a program. The AST was initially not exposed as API, but many tools were making use of it anyway to perform such manipulation as code refactoring. However, because the compiler’s AST is used for parsing, type resolution, flow analysis, and code generation, the code is very complex and difficult to expose as API. The Java core team decided not to expose its internal AST but instead to expose a clean, new AST. This AST is available in the org.eclipse.jdt.core.dom package. Although this isn’t the same AST used by the compiler, it nonetheless provides a rich semantic representation of a Java program, right down to every expression and statement in methods and initializers. This AST optionally supports resolution of all type references but does not provide advanced capabilities such as flow analysis and code generation. Clients can build and manipulate ASTs for any Java source code, whether or not it’s in the workspace.

See Also:


This FAQ was originally published in Official Eclipse 3.0 FAQs. Copyright 2004, Pearson Education, Inc. All rights reserved. This text is made available here under the terms of the Eclipse Public License v1.0.