CSE 131A - Onyx AST Specification - Winter 2007

Summary | Notation
Non-Expression Elements | Expression Elements

Changelog

Date Description
07-Feb-2007 Corrected attribute name for argument name in ArgumentDeclaration, and bound variable name in ForExpression and LetExpression. It should be name.
05-Feb-2007 Added discussion about normalization rules, referencing the normalization document.
04-Jan-2007 Initial release of document.

Summary

The following tables specify a document object model for the Onyx AST. The object model defined here is similar to, but not the same as, that given in the W3C XQueryX 1.0 working draft. That document provides examples as well as DTD and XMLSchema characterizations of XQueryX. However, this Onyx AST Specification document should be considered authoritative for purposes of the assignment.

These AST nodes define an alternate representation of Onyx programs that is suitable for constructing abstract syntax trees (ASTs). Since OXML is the "native" data format for Onyx, this representation permits easy manipulation of Onyx programs by Onyx programs.

The root element for an Onyx AST is a Query element. The order of elements within the Onyx AST document will reflect the order of corresponding constructs within the program. As in any OXML document, attributes may be specified in any order within a tag.

The Onyx AST nodes are broadly grouped into two categories: non-expression elements and expression elements. Non-expression elements are used only when specifically permitted by a containing element. In contrast, any of the expression elements can be used any time any expression element is allowed.

Be sure and read over the discussion on normalization for dealing with FLWR expressions, as there is no AST node for FLWR. Instead, there are separate node types for for and let. The return and where clauses are normalized out of the AST. [02/05/07].

Notation

In this specification, element and attribute names are shown underlined and in teletype font. This specification includes the following symbols to indicate repeated or optional includes the conventional "regular expression" extensions to BNF with these meanings:

Symbol Meaning
| Separates alternatives
( and ) Group a subexpression
? Optional element(zero or one)
+ Iterated element(one or more)
* Repeated element(zero or more)
any-expression-element Any one of the Expression Elements

When the specification lists alternatives, only one of the alternative elements is allowed for the indicated element position.

Non-expression Elements

This section specifies elements that define "non-expression" elements in the schema. These are elements that can contain, or be contained in, expression elements. Expression elements are specified in a separate table.

The Query tag marks the root element for any AST's OXML document. Thus the Query start tag should be similar to:

<onyx.ast.Query>

The namespace scope for Onyx AST tag names is onyx.ast. All tag names in the following tables should be qualified with the the prefix onyx.ast. For example, the Query AST node should have a tag name onyx.ast.Query and a FunctionDeclaration AST node must have a tag name of onyx.ast.FunctionDeclaration.


Element Descendant type Attribute and
child element names
Description
Query Elements (FunctionDeclaration | VariableDeclaration)*
ExprList
The function definitions constitute the query prolog; ExprList is the query body, which may be an empty list.
FunctionDeclaration Attributes funcName
datatype
The funcName attribute's value is the name of the declared function; the datatype attribute is the function return type and should be a valid fully qualified Onyx datatype.
Elements ArgumentDeclaration*
any-expression-element
Argument declarations must occur in their order of declaration. The one expression-element is the function definition body.
VariableDeclaration Attributes

varName
datatype

The varName attribute's value is the name of the declared variable; the datatype attribute is the variable's type and should be a fully qualified Onyx datatype.
Elements any-expression-element An expression whose evaluated value is the initial value of the declared variable.
ArgumentDeclaration Attributes name
datatype
The argument name is an attribute; its value must be a variable name. The value of the datatype should be a fully qualified Onyx datatype.

Expression Elements

The following elements define the different forms of expressions used in Onyx. These elements are allowed in any locations where ExpressionNode any-expression-element is specified as a legal element.


Element Descendant type Attribute and
child element names
Description
Variable Text Content variable name The variable's name is the content of the element. The leading "$" must be included.
Constant Attributes datatype The value of the datatype attribute should be a valid Onyx type. For constants, the datatype is limited to onyx.types.Integer, onyx.types.Decimal, onyx.types.String, and onyx.types.Boolean.
Text Content constant value The constant's value is the content of the element.
FunctionCall Attributes name Name of the function to call. The function can be a user-defined function or a built-in function.
Elements any-expression-element* These expressions are the actual parameters to the function. The arguments of the function appear as children of the FunctionCall AST node. If there are no arguments, the FunctionCall AST node is an element with no children.
Operator Attributes name Name of the operator to call. The correponding built-in in function name always begins with "op:" and the mapping of operator to internal name is defined in the Semantic Spec Table of built-in functions and operators
Elements any-expression-element+ These expressions are the actual parameters to the function.
ForExpression Attributes name Name of variable bound to the sequence of values from the expression.
Elements any-expression-element
any-expression-element
The first expression generates a sequence of values that get bound to the variable. The second expression is the body of the for.
LetExpression Attributes name Name of values bound to the expression's value.
Elements any-expression-element
any-expression-element
The first expression generates the value bound to the variable. The second expression is the body of the let.
IfThenElseExpr Attributes normalized Exists only if a where statement is normalized to an if. The value in this situation is 'where'.
Elements any-expression-element
any-expression-element
any-expression-element
The first expression is the conditional clause. This should be a boolean value. The second expression is the then clause and the last expression is the else clause.
ExprList Elements any-expression-element* A list of expressions. The children can be any expression node except other ExprList nodes. When added, ExprLists should be flattened.