All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class epp.Parser

java.lang.Object
   |
   +----epp.Parser

public class Parser
extends Object
The Parser.java file defines methods of the EPP preprocessor that are used for the parser portion of the Java language.

Note: This class is provided for the sake of creating javadocs. It does not exist in the actual EPP source code.

By extending the behaviour of each method using the SystemMixin syntax from with a plug-in, you can extend the grammar of the Java language that EPP processes.

The parser of EPP is written in recursive descent style. A recursive descent parser is a parser written in a style where each non-terminal is described as a single function. The funtion will parse one non-terminal and return a tree. For example, in EPP, the method expression() starts parsing assuming that an "expression" begins from the current token and returns the parsed result as an abstract syntax tree.

Most non-terminals are defined using the defineNonterminal macro. This macro automatically defines methods including xxxTop, xxxLeft, and xxxRight. Plug-ins may also add new alternatives to the non-terminal by extending these methods. For a list of non-terminals, see "Java grammar accepted by EPP".

EPP provides a mechanism for back tracking while parsing. While a pure single token peek ahead recursive descent syntax parser can only handle LL(1) grammer, it can handle a broarder ranges by back traking.

See Also:
backtrack

Constructor Index

 o Parser()

Method Index

 o convertExpressionToType(Tree)
Converts an abstract syntax tree that was parsed as an expression into a canonical form that describes a type.
 o type()
Parses the non-terminal Type and returns the result.
 o xxx()
Parses the non-terminal xxx and returns the resulting abstract syntax tree.
 o xxx1()
Called when all alternatives of the non-terminal xxx do not match.
 o xxxLeft(Tree)
Parses and returns alternatives of a non-terminal xxx that are left recursive rules.
 o xxxRight(Tree)
Parses and returns alternatives of a non-terminal xxx that are right associative binary operators.
 o xxxTop()
Parses and returns alternatives of a non-terminal xxx that can be determined by just looking at the first token.

Constructors

 o Parser
 public Parser()

Methods

 o xxx
 public Tree xxx()
Parses the non-terminal xxx and returns the resulting abstract syntax tree. xxx should be the same as the name of the non-terminal with the first character in lower case. (For example, statement, expression, classBodyDeclaration, etc.) Normally, plug-ins should not extend/redefine this method. (Doing so, may confuse line number processing.) If you wish to extend the syntax, extend the methods named xxxTop, xxxRight, and xxxLeft.

 o xxxTop
 public Tree xxxTop()
Parses and returns alternatives of a non-terminal xxx that can be determined by just looking at the first token.

This method is automatically defined by the defineNonterminal macro.

 o xxxRight
 public Tree xxxRight(Tree tree)
Parses and returns alternatives of a non-terminal xxx that are right associative binary operators. Argument tree is the parsed result of the left hand side of the binary operator.

This method is automatically defined by the defineNonterminal macro.

 o xxxLeft
 public Tree xxxLeft(Tree tree)
Parses and returns alternatives of a non-terminal xxx that are left recursive rules. Argument tree is the parsed result of the non-terminal xxx.

This method is automatically defined by the defineNonterminal macro.

 o xxx1
 public Tree xxx1()
Called when all alternatives of the non-terminal xxx do not match. If it is an expression, the method is usually defined to call the method of a non-terminal next in precendence. Normally, this method should not be redefined by a plug-in.

 o type
 public Tree type()
Parses the non-terminal Type and returns the result.

For the sake of implementation, the type method first calls the primary method, then converts the result value into a canonical form that describes a type and returns it. In order to convert the result value into a canonical form, this method calls the convertExpressionToType method.

For the plug-in to introduce a new "type description", you will need to extend the primaryTop method and the convertExpressionToType method.

See Also:
convertExpressionToType
 o convertExpressionToType
 public Tree convertExpressionToType(Tree exp)
Converts an abstract syntax tree that was parsed as an expression into a canonical form that describes a type. For the sake of implementating with recursive descent, the EPP parser initially parses a type name as an expression. Then, with this method, converts it into a form that is easier to handle as a type name. For example, the result of parsing the identifier "int" as an expression would be (id int). Converting this into a canonical form will result in (name (id int)).

The canonical form of a type is defined as follows.

 CanonicalType:
	(name Identifier Identifier*)
	(arrayOf CanonicalType)
       <extended alternatives>

If the passed argument is not an appropriate abstract syntax tree describing a type, an EppUserError will be thrown.

See Also:
type, TypeNameChecker

All Packages  Class Hierarchy  This Package  Previous  Next  Index