| Date | Description |
| 18-Feb-2007 | Removed div as a legal MultiplicativeOp |
| 19-Jan-2007 | Initial release |
This document specifies the syntax for the Onyx language, and relates productions to the AST constructs in the AST Specification. The following notational conventions are used: nonterminals are set in strong font; tag names in the AST representation are shown below the generated nonterminal for each production and are set in underlined teletype font; and terminals within the Grammar Rule column are also shown underlined and in teletype font. The grammar includes the conventional "regular expression" extensions to BNF with these meanings:
| BNF Symbol | Meaning |
| ::= | Introduces a rule |
| | | Separates alternatives |
| ( and ) | Group a subexpression |
| ? | Optional (zero or one) |
| + | Transitive list (one or more) |
| * | Intransitive list (zero or more) |
AST node generation
The mapping between AST nodes and each nonterminal is indicated in the line below each nonterminal name. This AST Node generation line indicates an association between the syntactic elements in the Grammar Rule and the Onyx AST Specification, that is, the AST node's tag name. There are five cases needed to express this mapping as follows. Nonterminal represents some non-terminal symbol. The notation below, and after the arrow, enumerates one of the five possible mappings.
| AST Generation | Example | Meaning |
| Nonterminal => syntax |
AdditiveOp => syntax |
The production's syntactic elements do
not correspond directly to any AST node. In these case, the relevant
information is eventually collected into other elements. |
| Nonterminal => ast-node |
FunctionDecl => FunctionDeclaration |
The production's syntactic elements are
associated with the named node. |
| Nonterminal => sequence of ast-node |
ParamList => sequence of ArgumentDeclaration |
The production defines a sequence of AST
nodes. |
| Nonterminal => Expression |
ExprSingle => ExpressionNode |
The production's syntactic elements
propagate an existing ExpressionNode-type AST node. |
| Nonterminal => Expression or ast-node |
OrExpr => ExpressionNode or Operator |
The production's syntactic elements propagate an existing ExpressionNode-type AST node, or synthesize a new AST node of the named type. Many of these entries are associated with implicit function calls for the built-in operators. |
The following table presents the productions for the Onyx grammar. The start symbol for this language is Query. Note that notation below each terminal symbol in the Grammar Symbol column follows one of the previously mentioned 5 patterns. Hypertext links refer back to the AST specification.
| Grammar Symbol | Grammar Rule |
| Query => Query |
::= QueryProlog
QueryBody |
| QueryProlog => sequence of (FunctionDeclaration or VariableDeclaration) |
::= (FunctionDecl | VariableDecl)* |
| QueryBody => ExpressionNode |
::= ExprList? |
| FunctionDecl => FunctionDeclaration |
::= declare function
tokenQName ( ParamList?
) (as tokenQName)? {ExprList} ; |
| VariableDecl => VariableDeclaration |
::= declare variable tokenVariable (as tokenQName)? {ExprList} ; |
| ParamList => sequence of ArgumentDeclaration |
::= tokenVariable (as tokenQName)? (,
tokenVariable (as tokenQName)?)* |
| ExprList => ExprList |
::= ExprSingle (, ExprSingle)* |
| ExprSingle => ExpressionNode |
::= OrExpr | FLWRExpr | IfExpr | RangeExpr |
| OrExpr => ExpressionNode or Operator |
::= AndExpr (or AndExpr)* the 'or' operator associates left-to-right |
| AndExpr => ExpressionNode or Operator |
::= CompareExpr (and
CompareExpr)* the 'and' operator associates left-to-right |
| CompareExpr => ExpressionNode or Operator |
::= AdditiveExpr
(CompareOp AdditiveExpr)? |
| RangeExpr => Operator |
::= AdditiveExpr to
AdditiveExpr |
| AdditiveExpr => ExpressionNode or Operator |
::= MultiplicativeExpr
(AdditiveOp MultiplicativeExpr)* |
| MultiplicativeExpr => ExpressionNode or Operator |
::= UnaryExpr
(MultiplicativeOp UnaryExpr)* |
| UnaryExpr => ExpressionNode or Operator |
::= UnaryOp?
PrimaryExpr |
| CompareOp => syntax |
::= = | != |
<= | >= | < |
> |
| AdditiveOp => syntax |
::= + | - the additive operators associate left-to-right |
| MultiplicativeOp => syntax |
::= * |
idiv | mod
the multiplicative operators associate left-to-right |
| UnaryOp => syntax |
::= + | - the unary operators associate right-to-left |
| PrimaryExpr => ExpressionNode or Variable |
::= Literal |
tokenVariable | ( ExprList?
) | FunctionCall |
| Literal => Constant |
::= tokenInteger | tokenDecimal | tokenBoolean | tokenString |
| FunctionCall => FunctionCall |
::= tokenQName (
ArgList? ) |
| ArgList => sequence of ExpressionNode |
::= ExprSingle (, ExprSingle)* |
| FLWRExpr => ForExpression or LetExpression |
::= (ForClause |
LetClause)+ (WhereClause)? ReturnStmt |
| WhereClause => IfThenElseExpr |
::= where ExprSingle |
| ReturnStmt => syntax |
::= return ExprSingle |
| ForClause => ForExpression |
::= for tokenVariable
in ExprSingle (,
tokenVariable in ExprSingle)* |
| LetClause => LetExpression |
::= let tokenVariable
:= ExprSingle (,
tokenVariable := ExprSingle)* |
| IfExpr => IfThenElseExpr |
::= if (
ExprSingle ) then
ExprSingle else ExprSingle |