このセクションでは、完全な Q 言語の文法をリストします。トークンの構造については、『字句エレメント』を参照してください。
以下のテーブルでは、文法の表示に使用される表記上の規則を要約しています。
- スタイル
- 意味
- [
]
- オプションの要素
- ( )+
- 1 つ以上のオカレンス
- ( )*
- ゼロ以上のオカレンス
- ID、STRING_LITERAL
- トークン
- let、for_all、=>、~<>
- 予約語または句読点
expr
: expr′
| expr′ |= expr′
expr′
: implies-expr
| let-expr
| if-expr
| universal-expr
| existential-expr
let-expr
: let ID = expr in expr′
if-expr
: if expr then expr else expr′
universal-expr
: for_all ID in expr = expr′
existential-expr
: there_exists ID in expr = expr′
implies-expr
: or-expr
| or-expr implies implies-expr
or-expr
: and-expr
| or-expr or and-expr
and-expr
: relational-expr
| and-expr and relational-expr
relational-expr
: additive-expr
| additive-expr = additive-expr
| additive-expr <> additive-expr
| additive-expr ~= additive-expr
| additive-expr ~<> additive-expr
| additive-expr < additive-expr
| additive-expr <= additive-expr
| additive-expr > additive-expr
| additive-expr = additive-expr
additive-expr
: multiplicative-expr
| additive-expr + multiplicative-expr
| additive-expr - multiplicative-expr
multiplicative-expr
: unary-expr
| multiplicative-expr * unary-expr
| multiplicative-expr / unary-expr
unary-expr
: primary-expr
| - unary-expr
| not unary-expr
primary-expr
: constant
| $ ID
| $ ID of primary-expr
| map { expr } over primary-expr
| filter { expr } over primary-expr
| traverse { expr } over primary-expr
| sort-expr
| ID primary-expr
| conversion-expr
| parenthesized-expr
| path
定数
: REGEXP_LITERAL
| STRING_LITERAL
| INTEGER_LITERAL
| REAL_LITERAL
| BOOLEAN_LITERAL
sort-expr
: sort-component ( & sort-component )* over primary-expr
sort-component
: sort-direction { expr }
sort-direction
: sort
| sortd
conversion-expr
: conversion-operator primary-expr
conversion-operator
: string
| integer
| real
| boolean
parenthesized-expr
: ( )
| ( expr )
| ( expr (, expr )+ )
パス
: anchor
| anchor -association-chain
| association-chain
アンカー
: this
| current
| model
| ID
association-chain
: simple-association ( -simple-association )* [ association-chain-tail ]
simple-association
: [ ID : ] [^] ASSOC_LITERAL [ { expr } ]
association-chain-tail
: -reference-association
| -composite-association
reference-association
: @ ID
composite-association
: ( component-association ( ; component-association )+ )
component-association
: reference-association
| association-chain