memento.xml 7.75 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
<?xml version="1.0" encoding="ISO-8859-1" standalone="yes"?>
<page>

<title>CDuce memento</title>
<banner> CDuce memento </banner>

<!-- ********* Left panel ********* -->
<navig>
<toc/>
<box>
<p>
This page briefly presents the syntax of the CDuce language. 
</p>

<ul>
<li><a href="/cgi-bin/cduce">Online demo</a></li>
<li><a href="/">Home page</a></li>
</ul>
</box>
</navig>

<!-- ********* Main panel ********* -->

<main>

<box title="Identifiers" link="id">
<ul>
<li> Type and Pattern identifiers: words formed by of unicode letters and  and 
the underscore "_" character,  starting by a capitalized letter. </li>
  
<li> value identifiers: words formed by of unicode letters and the underscore "
_" character,  starting by a capitalized letter or underscore.</li>
</ul>
</box>

<box title="Scalars" link="scalars">
<ul>
 <li>Large integers: 
   <ul> 
     <li>Values: <duce>0,1,2,3,...</duce> </li>
     <li>Types: intervals <duce>-*--10, 20--30, 50--*, ...</duce>,
                singletons <duce>0,1,2,3,...</duce> </li>
     <li>Operators: <duce>+,-,/,*,div,mod, int_of</duce> </li>
   </ul>
 </li>
 <li>Unicode characters:
   <ul>
     <li>Values: <duce>'a','b','c'...</duce> </li>
     <li>Types: intervals <duce>'a'--'z', '0'--'9'</duce>,
                singletons <duce>'a','b','c',...</duce> </li>
   </ul>
 </li>
 <li>Symbolic atoms:
   <ul>
     <li>Values: <duce>`A, `B, `a, `b, `true, `false, ...</duce> </li>
     <li>Types: singletons <duce>`A, `B, ...</duce> </li>
   </ul>
 </li>
</ul>
</box>

<box title="Operators" link="op">
<ul>
   <li>Infix:
     <br/> <duce>@</duce> : String,String -> String
     <br/> <duce>+,*,-,div,mod</duce> : Integer,Integer -> Integer
     <br/> <duce>=, &lt;&lt;, &lt;=, &gt;&gt;, &gt;= </duce> :
Integer,Integer -> Bool = <duce>`true | `false</duce>
   </li>
   <li>Prefix:
71
72
        <br/><duce>load_xml,load_html</duce> : String -> Any,
        <br/><duce>dump_to_file</duce> : String -> String -> Any,
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
        <br/><duce>print_xml</duce> : Any -> String
        <br/><duce>print</duce> : String -> []
        <br/><duce>int_of</duce> : [('0'--'9')+] -> Integer
        <br/><duce>string_of</duce> : Integer -> String
   </li>
   <li>Postfix:
        <br/><duce>?,*,+,??,*?,+?</duce> : for regexp
   </li>
 </ul>
</box>

<box title="Pairs" link="pair">
<ul>
 <li>Expressions: <duce>(e1,e2)</duce> </li>
 <li>Types and patterns: <duce>(t1,t2)</duce> </li>
 <li>Note: tuples are right-associative pairs; e.g.: 
           <duce>(1,2,3)=(1,(2,3))</duce> </li>
 <li>When a capture variable appears on both side of a pair pattern,
     the two captured values are paired
     together (e.g. <duce>match (1,2,3) with (x,(_,x)) -> x ==>
(1,3)</duce>). </li>
</ul>
</box>

<box title="Sequences" link="seq">
<ul>
<li>Expressions: <duce>[ 1 2 3 ]</duce>, 
     which is syntactic sugar for <duce>(1,(2,(3,`nil)))</duce> </li>
<li>A sub-sequence can be escaped by !: <duce>[ 1 2 ![ 3 4 ] 5
]</duce> is then equal to <duce>[ 1 2 3 4  5 ]</duce> . </li>
<li>Types and patterns : <duce>[ R ]</duce> where <duce>R</duce> is
    a regular expression built on types and patterns:
   <ul>
     <li>A type or a pattern is a regexp by itself, matching a single
         element of the sequence </li>
     <li>Postfix repetition operators: <duce>*,+,?</duce>
         and the ungreedy variants (for patterns) <duce>*?, +?
         ,??</duce></li>
     <li>Concatenation of regexps</li>
     <li>For patterns, sequence capture variable <duce>x::R</duce> </li>
   </ul>
 </li>
<li>It is possible to specify a tail, for expressions, types, and patterns;
    e.g.: <duce>[ x::Int*; q ]</duce>   </li>
<li>Map: <duce>map e with p1 -> e1 | ... | pn -> en</duce>. 
    Each element of e must be matched. </li>
<li>Transform: <duce>transform e with p1 -> e1 | ... | pn -> en</duce>. 
    Unmatched elements are discarded; each branch returns a sequence
    and all the resulting sequences are concatenated together. </li>
<li>Operators: concatenation <duce>e1 @ e2 = [ !e1 !e2 ]</duce>,
              flattening <duce>flatten e = transform e with x -> x</duce>.
</li>
</ul>
</box>

<box title="Record" link="record">
<ul>
<li>Records litteral <duce>{ l1 = e1; ...; ln = en }</duce></li>
<li>Types: <duce>{| l1 = t1; ...; ln = tn |}</duce> (closed, no more
fields allowed), <duce>>{ l1 = t1; ...; ln = tn }</duce> (open,
any other field allowed). Optional fields: <duce>li =? ti</duce>
instead of <duce>li = ti</duce>.</li>
<li>Record concatenation:  <duce>e1 + e2</duce>
 (priority to the fields from the right argument) </li>
<li>Field removal: <duce>e1 \ l</duce> (does nothing if the
field <duce>l</duce> is not present)</li>
<li>Field access: <duce>e1 . l</duce></li>
<li>Record: <duce>{ l1 = p1; ...; ln = pn }</duce></li>
</ul>
</box>

<box title="Strings" link="string">
<ul>
<li>Strings are actually sequences of characters.</li>
<li>Expressions: <duce>"abc", [ 'abc' ], [ 'a' 'b' 'c' ]</duce>. </li>
<li>Operators: <duce>string_of, print, dump_to_file</duce></li>
<li><duce>PCDATA</duce> means <duce>Char*</duce> inside regular expressions</li>
</ul>
</box>

<box title="XML elements" link="xml">
<ul>
 <li>Expressions: <duce> &lt;(tag) (attr)>content</duce> </li>
 <li>If the tag is an atom <duce>`X</duce>, it can be written
      <duce>X</duce> (without the <duce>(..)</duce>).
      Similarly, parenthesis and curly braces may be omitted
      when attr is a record <duce>l1=e1;...;ln=en</duce>.
      E.g: <duce>&lt;a href="abc">[ 'abc' ]</duce>.</li>
 <li>Types and patterns: same notations.</li>
 <li>Operators: <duce>load_xml : String -> Any; print_xml : Any -> String</duce>
</li>
</ul>
</box>

<box title="Functions" link="fun">
<ul>
<li>Expressions: 
   <ul>
     <li>General form: <duce>fun f (t1->s1;...;tn->sn)
     p1 -> e1 | ... | pn -> en</duce> (<duce>f</duce> is optional) </li>
     <li>Simple function: <duce>fun f (p : t) : s = e</duce>,
     equivalent to <duce>fun f (t -> s) p -> e</duce> </li>
     <li>Multiple arguments: <duce>fun f (p1 : t1, p2 : t2,...) : s =
e</duce>, equivalent to <duce>fun f ((p1,p2,...):(t1,t2,...)) : s
= e</duce> </li>
  </ul>
</li>
<li>Types: <duce>t -> s</duce> </li>
</ul>
</box>

<box title="Pattern matching, exceptions, ..." link="match">
<ul>
 <li>Type restriction: <duce>(e : t)</duce> (forgets any more precise
     type for <duce>e</duce>) </li>
 <li>Pattern matching: <duce>match e with p1 -> e1 | ... | pn ->
en</duce></li>
 <li>Local binding: <duce>let p = e1 in e2</duce>, equivalent to
 <duce>match e1 with p -> e2</duce>; 
   <duce>let p : t = e1 in e2</duce> equivalent to
  <duce>let p = (e1 : t) in e2</duce> </li>
 <li>If-then-else: <duce>if e1 then e2 else e3</duce>, equivalent to
 <duce>match e1 with `true -> e2 | `false -> e3</duce></li>
 <li>Exceptions: <ul>
   <li>Raise exception: <duce>raise e</duce></li>
   <li>Handle exception: <duce>try e with p1 -> e1 | ... | pn ->
    en</duce></li>
  </ul> </li>
</ul>
</box>

<box title="More about types and patterns" link="type">
<ul>
<li>Boolean connectives: <duce>&amp;,|,\</duce> (<duce>|</duce> is
first-match). </li>
<li>Empty and universal types: <duce>Empty,Any</duce> or
<duce>_</duce>.</li>
<li>Recursive types and patterns: <duce>t where T1 = t2 and ... and
Tn = tn</duce>.</li>
<li>Capture variable: <duce>x</duce>. </li>
<li>Default values: <duce>(x := c)</duce>. </li>
</ul>
</box>
216
217
218
219
220
221

<box title="Toplevel statements" link="type">
<ul>
<li>Type declarations: <duce>type T = t</duce>.</li>
<li>Source inclusion: <duce>include </duce> <i> filename_string</i></li>
<li>Debug directives: <duce>debug </duce> <i> directive argument</i> <br/>
222
223
    where <i> directive</i> is one of the following: <duce>accept</duce>, 
<duce>subtype</duce>, <duce>compile</duce>.
224
225
226
227
228
    </li>
</ul>
</box>


229
230
231
232
233
234
235
236
237
238
<meta>
<p>
This page has been generated by a CDuce program.
</p>
<p><a href="/">Home page</a> - <a href="mailto:Alain.Frisch@ens.fr">Webmaster</a>
</p>
</meta>

</main>
</page>