Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
cduce
cduce
Commits
49960418
Commit
49960418
authored
Oct 05, 2007
by
Pietro Abate
Browse files
[r2003-10-10 22:00:14 by cvscast] Logical operators + regexp example
Original author: cvscast Date: 2003-10-10 22:00:15+00:00
parent
79a7451f
Changes
9
Show whitespace changes
Inline
Side-by-side
CHANGES
View file @
49960418
...
...
@@ -3,6 +3,7 @@
* -o option for compilation
* .cd suffixes are now optional in command line
* Bugfixes
* Add logical operators &&, ||, and not
0.2.0
* Code upgraded to Ocaml 3.07+beta2
...
...
parser/ast.ml
View file @
49960418
...
...
@@ -43,6 +43,7 @@ and pexpr =
|
Abstraction
of
abstr
(* Data constructors *)
|
Const
of
Types
.
Const
.
t
|
Integer
of
Intervals
.
V
.
t
|
Char
of
Chars
.
V
.
t
|
Pair
of
pexpr
*
pexpr
...
...
parser/parser.ml
View file @
49960418
...
...
@@ -51,7 +51,7 @@ let tuple_queue =
let
char
=
mknoloc
(
Internal
(
Types
.
char
Chars
.
any
))
let
string_regexp
=
Star
(
Elem
char
)
let
cst_nil
=
Atom
(
U
.
mk
"nil"
)
let
cst_nil
=
Const
(
Types
.
Atom
(
Atoms
.
V
.
mk_ascii
"nil"
)
)
let
pat_nil
=
mknoloc
(
Internal
(
Sequence
.
nil_type
))
let
seq_of_string
s
=
...
...
@@ -171,6 +171,7 @@ EXTEND
|
"transform"
|
"fun"
|
"in"
|
"let"
|
"type"
|
"debug"
|
"include"
|
"and"
|
"validate"
|
"schema"
|
"namespace"
|
"ref"
|
"using"
|
"not"
]
->
a
]
...
...
@@ -207,6 +208,11 @@ EXTEND
exp
loc
(
Match
(
e1
,
[
pat_nil
,
e2
]))
|
"ref"
;
p
=
pat
;
e
=
expr
->
exp
loc
(
Ref
(
e
,
p
))
|
"not"
;
e
=
expr
->
let
p1
=
mknoloc
(
Internal
true
_type
)
and
p2
=
mknoloc
(
Internal
false
_type
)
in
exp
loc
(
Match
(
e
,
[
p1
,
Const
(
Types
.
Atom
(
false
_atom
));
p2
,
Const
(
Types
.
Atom
(
true
_atom
))]))
]
|
[
e1
=
expr
;
":="
;
e2
=
expr
->
...
...
@@ -224,11 +230,19 @@ EXTEND
|
[
e1
=
expr
;
op
=
[
"+"
|
"-"
|
"@"
];
e2
=
expr
->
exp
loc
(
Op
(
op
,
[
e1
;
e2
]))
|
e1
=
expr
;
"||"
;
e2
=
expr
->
let
p1
=
mknoloc
(
Internal
true
_type
)
and
p2
=
mknoloc
(
Internal
false
_type
)
in
exp
loc
(
Match
(
e1
,
[
p1
,
Const
(
Types
.
Atom
(
true
_atom
));
p2
,
e2
]))
|
e
=
expr
;
"
\\
"
;
l
=
[
IDENT
|
keyword
]
->
exp
loc
(
RemoveField
(
e
,
label
l
))
]
|
[
e1
=
expr
;
op
=
[
"*"
];
e2
=
expr
->
exp
loc
(
Op
(
op
,
[
e1
;
e2
]))
|
e1
=
expr
;
"&&"
;
e2
=
expr
->
let
p1
=
mknoloc
(
Internal
true
_type
)
and
p2
=
mknoloc
(
Internal
false
_type
)
in
exp
loc
(
Match
(
e1
,
[
p1
,
e2
;
p2
,
Const
(
Types
.
Atom
(
false
_atom
))]))
|
e
=
expr
;
op
=
"/"
;
p
=
pat
->
let
tag
=
mk
loc
(
Internal
(
Types
.
atom
(
Atoms
.
any
)))
in
...
...
parser/ulexer.ml
View file @
49960418
...
...
@@ -74,7 +74,7 @@ let rec token = lexer
return
lexbuf
(
"INT"
,
L
.
utf8_lexeme
lexbuf
)
|
[
"<>=.,:;+-*/@&{}[]()|?`!"
]
|
"->"
|
"::"
|
";;"
|
"--"
|
":="
|
"
\\
"
|
"++"
|
"{|"
|
"|}"
|
"<="
|
">="
|
"<<"
|
">>"
|
"{|"
|
"|}"
|
"<="
|
">="
|
"<<"
|
">>"
|
"||"
|
"&&"
|
[
"?+*"
]
"?"
|
"#"
->
return
lexbuf
(
""
,
L
.
utf8_lexeme
lexbuf
)
|
"#"
ncname
->
...
...
types/types.ml
View file @
49960418
typing/typer.ml
View file @
49960418
...
...
@@ -146,6 +146,7 @@ let rec const env loc = function
|
Atom
t
->
Types
.
Atom
(
parse_atom
env
loc
t
)
|
Integer
i
->
Types
.
Integer
i
|
Char
c
->
Types
.
Char
c
|
Const
c
->
c
|
_
->
raise_loc_generic
loc
"This should be a scalar or structured constant"
(* I. Transform the abstract syntax of types and patterns into
...
...
@@ -821,7 +822,7 @@ let rec expr env loc = function
Typed
.
fun_fv
=
fv
}
in
exp
loc
fv
e
|
(
Integer
_
|
Char
_
|
Atom
_
)
as
c
->
|
(
Integer
_
|
Char
_
|
Atom
_
|
Const
_
)
as
c
->
exp
loc
Fv
.
empty
(
Typed
.
Cst
(
const
env
loc
c
))
|
Pair
(
e1
,
e2
)
->
let
(
fv1
,
e1
)
=
expr
env
loc
e1
and
(
fv2
,
e2
)
=
expr
env
loc
e2
in
...
...
web/examples.xml
View file @
49960418
...
...
@@ -37,6 +37,24 @@ A detailed explanation of the code can be found <a href="tutorial_overloading.ht
</sample>
</box>
<box
title=
"Datatypes + first-class functions"
link=
"data"
>
<p>
The program below shows how to simulate ML data types in CDuce.
It implements a (naive backtracking) regular expression recognizer.
The examples also demonstrate the use of first-class functions
(used as continuations).
</p>
<p>
Exercise for the reader: show that the algorithm may not terminate for
some special regular expressions.
</p>
<sample
highlight=
"false"
>
<include-verbatim
file=
"regexp.cd"
/>
</sample>
</box>
<box
title=
"The script that generates this site"
link=
"site"
>
<p>
The script below is one of the longest CDuce application ever written
...
...
web/manual/expressions.xml
View file @
49960418
...
...
@@ -368,6 +368,14 @@ match %%e1%% with `true -> %%e2%% | `false -> %%e3%%
<p>
Note that the else-clause is mandatory.
</p>
<p>
The infix operators
<code>
||
</code>
and
<code>
&&
</code>
denote respectively the logical or and the logical and. The prefix
operator
<code>
not
</code>
denotes the logical negation.
</p>
</box>
<box
title=
"Upward coercions"
link=
"upward"
>
...
...
web/memento.xml
View file @
49960418
...
...
@@ -55,6 +55,8 @@ _" character, starting by a capitalized letter or underscore.</li>
<br/>
<code>
+,*,-,div,mod
</code>
: Integer,Integer -> Integer
<br/>
<code>
=,
<<
,
<
=,
>>
,
>
=
</code>
:
<i>
t
</i>
,
<i>
t
</i>
-> Bool =
<code>
`true | `false
</code>
(any non functional type
<i>
t
</i>
)
<br/>
<code>
||,
&&
</code>
: Bool,Bool -> Bool
<br/>
<code>
not
</code>
: Bool -> Bool
</li>
<li>
Prefix:
<br/><code>
load_xml,load_html
</code>
: String -> Any,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment