3 This paper presents {\MathQL} version 4 which is the latest version of the
4 language, fully developed by Ferruccio Guidi.
5 For a description of the previous versions of {\MathQL} see: \cite{Gui03}
6 (version 3), \cite{GS03} (version 2), \cite{Lor02} (version 1).
7 The main novelties of this version are the elimination of some cast operators
8 (producing a substantial simplification in the query structure and semantics,
9 see \secref{Operational}), a clear distinction between the core language and
10 the auxiliary functions of the basic library, a support for query generating
11 functions, the possibility of extending the language adding new libraries of
12 functions and a more uniform textual syntax.
13 {\MathQL}.4 incorporates the features of {\MathQL}.3 not documented on paper%
15 {See the ``what's new'' section of {\MathQL} Web Site:
16 \URI{helm.cs.unibo.it/mathql}.}
17 and adds some new features improving {\MathQL} capabilities to post-process
20 \subsection{Textual syntax}
22 The syntax of grammatical productions resembles BNF and POSIX notation:
27 \TT{::=} defines a grammatical production by means of a regular expression.
29 Regular expressions are made of the following elements
30 (here \TT{...} is a placeholder):
33 % \TT{.} represents any character between U 0020 and U 007F inclusive;
36 \TT{`...`} represents any character in a character set;
39 \verb+`^ ...`+ represents any character (U+0020 to U+007E) not in a character
43 \TT{"..."} represents a string to be matched verbatim;
46 \GP{...} represents a regular expression defined by a grammatical production;
49 \TT{... ...} represents a conjunctive regular expression;
52 \TT{... | ...} represents a disjunctive regular expression;
55 \TT{[ ... ]?} represents an optional regular expression;
58 \TT{[ ... ]+} represents a regular expression to be repeated one or more times;
61 \TT{[ ... ]*} represents a regular expression to be repeated zero or more times;
64 \TT{[ ... ]} represents a grouped regular expression.
69 {\MathQL} Expressions can contain quoted constant strings with the syntax of
71 \footnote{Note that the first slash of the \GP{path} is not optional as
75 \begin{footnotesize} \begin{verbatim}
77 <num> ::= <dec> [ <dec> ]*
78 <hex> ::= <dec> | 'A - F' | 'a - f'
79 <escaped> ::= "u" <hex> <hex> <hex> <hex> | '"' | "\" | "^"
80 <string> ::= '"' [ "\" <escaped> "^" | '^ "\^' ]* '"'
81 <path> ::= "/" | [ "/" <string> ]+
82 \end{verbatim} \end{footnotesize}
84 \caption{Textual syntax of numbers, strings and paths} \label{StrTS}
88 The meaning of the escaped sequences is shown in \figref{EscTS}
89 (where $ .... $ is a 4-digit placeholder).
93 \begin{center} \begin{tabular}{|l|l|c|}
94 \hline {\bf Escape sequence} & {\bf Unicode character} & {\bf Text} \\
95 \hline \verb+\u....^+ & U+.... & \\
96 \hline \verb+\"^+ & U+0022 & \verb+"+ \\
97 \hline \verb+\\^+ & U+005C & \verb+\+ \\
98 \hline \verb+\^^+ & U+005E & \verb+^+ \\
100 \end{tabular} \end{center}
103 \caption{Textual syntax of escaped characters} \label{EscTS}
106 {\MathQL} character escaping syntax aims at complying with W3C character model
107 for the World Wide Web \cite{W3Ca} which recommends a support for standard
108 Unicode characters (U+0000 to U+FFFF) and escape sequences with
109 start/end delimiters.
110 In particular {\MathQL} escape delimiters (backslash and caret) are chosen
111 among the {\em unwise} characters for URI references (see \cite{URI}) because
112 URI references are the natural content of constant strings and these
113 characters should not be so frequent in them.
115 Query expressions can contain variables for {\av}'s (production \GP{avar})
116 and variables for {\av} sets, {\ie} for query results (production \GP{svar})
117 according to the syntax of \figref{VarTS}.
120 \begin{footnotesize} \begin{verbatim}
121 <alpha> ::= [ 'A - Z' | 'a - z' | `_` ]+
122 <id> ::= <alpha> [ <alpha> | <dec> ]*
125 \end{verbatim}\end{footnotesize} %$
127 \caption{Textual syntax of variables} \label{VarTS}
131 The syntax of query expressions (production \GP{query}) is described in
135 \begin{footnotesize} \begin{verbatim}
136 <qualifier> ::= [ "inverse" ]? [ "sub" | "super" ]? <path>
137 <main> ::= [ "main" <path> ]?
138 <cons> ::= <path> [ "in" | "match" ] <query>
139 <istrue> ::= [ "istrue" <cons> [ "," <cons> ]* ]?
140 <isfalses> ::= [ "isfalse" <cons> [ "," <cons> ]* ]*
141 <exp> ::= <path> [ "as" <path> ]?
142 <sec> ::= [ "attr" <exp> [ "," <exp> ]* ]?
143 <opt_args> ::= <main> <istrue> <isfalses> <sec>
144 <source> ::= [ "pattern" ]? <query>
145 <paths> ::= [ <path> [ "," <path> ]* ]?
146 <query> ::= "(" <query> ")" | <string> | "[" <xavs> "]"
147 | "property" <qualifier> <opt_args> "of" <source>
148 | "let" <svar> "=" <query> "in" <query>
149 | <query> ";;" <query> | <svar> | <avar>
150 | "ex" <query> | <avar> "." <path>
151 | "add" [ "distr" ]? [ <xgroups> | <avar> ] "in" <query>
152 | "for" <avar> "in" <query> [ "sup" | "inf" ] <query>
153 | "while" <query> [ "sup" | "inf" ] <query>
154 | <path> "{" <paths> "}" "{" <queries> "}"
155 | "gen" <path> [ "{" <queries> "}" | "in" <query> ]
156 <queries> ::= [ <query> [ "," <query> ]* ]?
157 <xattr> ::= <path> "=" <query>
158 <xgroup> ::= "{" <xattr> [ ";" <xattr> ]* "}"
159 <xgroups> ::= <xgroup> [ "," <xgroup> ]*
160 <xav> ::= <string> [ "attr" <xgroups> ]?
161 <xavs> ::= [ <xav> [ ";" <xav> ]* ]?
162 \end{verbatim} \end{footnotesize}
164 \caption{Textual syntax of queries} \label{QueryTS}
168 The syntax of result expressions (production \GP{avs}) is described in
172 \begin{footnotesize} \begin{verbatim}
173 <attr> ::= <path> "=" "{" [ <string> [ "," <string> ]* ]? "}"
174 <group> ::= "{" <attr> [ ";" <attr> ]* "}"
175 <av> ::= <string> [ "attr" <group> [ "," <group> ]* ]?
176 <avs> ::= [ <av> [ ";" <av> ]* ]?
177 \end{verbatim} \end{footnotesize}
179 \caption{Textual syntax of results} \label{ResultTS}
185 \begin{footnotesize} \begin{verbatim}
186 | "select" <avar> "from" <query> "where" <query>
187 \end{verbatim} \end{footnotesize}
189 \caption{Textual syntax of basic query extensions} \label{BasicTS}