]> matita.cs.unibo.it Git - helm.git/blob - helm/mathql/doc/mathql_introduction.tex
introduction updated
[helm.git] / helm / mathql / doc / mathql_introduction.tex
1 \section{Introduction}
2
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%
14 \footnote
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
18 the query results.  
19
20 \subsection{Textual syntax}
21
22 The syntax of grammatical productions resembles BNF and POSIX notation:
23
24 \begin{itemize}
25
26 \item
27 \TT{::=} defines a grammatical production by means of a regular expression.
28
29 Regular expressions are made of the following elements
30 (here \TT{...} is a placeholder):
31
32 % \item
33 % \TT{.} represents any character between U 0020 and U 007F inclusive;
34
35 \item 
36 \TT{`...`} represents any character in a character set;
37
38 \item 
39 \verb+`^ ...`+ represents any character (U+0020 to U+007E) not in a character
40 set;
41
42 \item 
43 \TT{"..."} represents a string to be matched verbatim;
44
45 \item
46 \GP{...} represents a regular expression defined by a grammatical production;
47
48 \item
49 \TT{... ...} represents a conjunctive regular expression;
50
51 \item
52 \TT{... | ...} represents a disjunctive regular expression;
53
54 \item
55 \TT{[ ... ]?} represents an optional regular expression;
56
57 \item
58 \TT{[ ... ]+} represents a regular expression to be repeated one or more times;
59
60 \item
61 \TT{[ ... ]*} represents a regular expression to be repeated zero or more times;
62
63 \item
64 \TT{[ ... ]} represents a grouped regular expression.
65
66 \end{itemize}
67
68 \noindent
69 {\MathQL} Expressions can contain quoted constant strings with the syntax of
70 \figref {StrTS}.%
71 \footnote{Note that the first slash of the \GP{path} is not optional as
72 in {\MathQL}.3.}
73
74 \begin{figure}[ht]
75 \begin{footnotesize} \begin{verbatim}
76 <dec>     ::= '0 - 9'
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}
83 \vskip-1pc
84 \caption{Textual syntax of numbers, strings and paths} \label{StrTS}
85 \end{figure}
86
87 \noindent
88 The meaning of the escaped sequences is shown in \figref{EscTS}
89 (where $ .... $ is a 4-digit placeholder).
90
91 \begin{figure}[ht]
92 \begin{footnotesize}
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+^+   \\
99 \hline
100 \end{tabular} \end{center}
101 \end{footnotesize}
102 \vskip-1pc
103 \caption{Textual syntax of escaped characters} \label{EscTS}
104 \end{figure}
105
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.
114
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}.
118
119 \begin{figure}[ht]
120 \begin{footnotesize} \begin{verbatim}
121 <alpha> ::= [ 'A - Z' | 'a - z' | `_` ]+
122 <id>    ::= <alpha> [ <alpha> | <dec> ]*
123 <avar>  ::= "@" <id>
124 <svar>  ::= "$" <id>
125 \end{verbatim}\end{footnotesize} %$
126 \vskip-1pc
127 \caption{Textual syntax of variables} \label{VarTS}
128 \end{figure}
129
130 \noindent
131 The syntax of query expressions (production \GP{query}) is described in
132 \figref{QueryTS}.
133
134 \begin{figure}[ht]
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}
163 \vskip-1pc
164 \caption{Textual syntax of queries} \label{QueryTS}
165 \end{figure}
166
167 \noindent
168 The syntax of result expressions (production \GP{avs}) is described in
169 \figref{ResultTS}.
170
171 \begin{figure}[ht]
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}
178 \vskip-1pc
179 \caption{Textual syntax of results} \label{ResultTS}
180 \end{figure}
181
182 \xcomment {
183
184 \begin{figure}[ht]
185 \begin{footnotesize} \begin{verbatim}
186             |   "select" <avar> "from" <query> "where" <query>
187 \end{verbatim} \end{footnotesize}
188 \vskip-1pc
189 \caption{Textual syntax of basic query extensions} \label{BasicTS}
190 \end{figure}
191
192 }