Mentions légales du service

Skip to content
Snippets Groups Projects
Commit 0309e55f authored by MONTAGU Benoit's avatar MONTAGU Benoit
Browse files

got rid of do/done keywords

parent 88243144
No related branches found
No related tags found
No related merge requests found
......@@ -152,8 +152,9 @@ let assoc_stmt = function
let prec_stmt = function
| Assign _ | Skip | Call _ -> -1
| Seq _ | While _ | IfThenElse (_, _, None) -> 0
| IfThenElse _ -> 1
| Seq _ | IfThenElse (_, _, None) -> 0
| While _ -> 1
| IfThenElse _ -> 2
let is_seq s = match s.data with Seq _ -> true | _ -> false
......@@ -184,8 +185,8 @@ let rec pp_stmt0_ lvl fmt =
if n < lvl then fprintf fmt "@[@[<v 2>{ %a@];@ }@]" (pp_stmt0_ n) s
else
let lvl1 = n in
fprintf fmt "@[<v>@[<v 2>@[while @[%a@] do@]@ @[%a@];@]@ done@]"
pp_bexpr b (pp_stmt_ lvl1) s1
fprintf fmt "@[<v 2>@[while @[%a@]@]@ @[%a@];@]" pp_bexpr b
(pp_stmt_ lvl1) s1
| IfThenElse (b, s1, None) as s ->
let n = prec_stmt s in
if n < lvl then fprintf fmt "@[@[<v 2>{ %a@];@ }@]" (pp_stmt0_ n) s
......
......@@ -42,8 +42,6 @@ rule lexer = parse
| '}' { RBRACE }
| "skip" { SKIP }
| "while" { WHILE }
| "done" { DONE }
| "do" { DO }
| "if" { IF }
| "then" { THEN }
| "else" { ELSE }
......
......@@ -29,7 +29,7 @@ let rec stmts = function
%token AMP2 VBAR2
%token NOT
%token SKIP WHILE DO DONE IF THEN ELSE
%token SKIP WHILE IF THEN ELSE
%token SEMI COLONEQ
%token LBRACE RBRACE
......@@ -129,7 +129,7 @@ stmt0:
{ Call (xs, f, es) }
| LBRACE s = stmts RBRACE
{ s.data }
| WHILE b = bexpr DO s = stmts DONE
| WHILE b = bexpr s = stmt
{ While (b, s) }
| IF b = bexpr THEN s1 = stmt ELSE s2 = stmt
{ IfThenElse (b, s1, Some s2) }
......
......@@ -9,13 +9,39 @@ def h() = { skip; skip; return 0 }
def i() = { {skip; skip; } ; skip; return 0 }
def d(x,y) {
while a + c - d <= 0 || c <> a do
while a + c - d <= 0 || c <> a
y := y - 1;
done;
if continue = 0 then x := x * x else skip;
return z
}
def test() {
if true
then {
if false
then skip
else skip;
};
return
}
def test'() {
if true
then
if false
then skip
else skip;
return
}
def test''() {
if true
then
{ if false then skip; }
else skip;
return
}
def f(a) {
y := i();
z := d(a, b);
......@@ -23,14 +49,14 @@ def f(a) {
}
def loop2() {
while true do
while true {
y := 0;
while true do
while true {
x := x + 1;
y := y - 1;
done;
};
x := y + x;
done;
};
z := x + y;
return z
}
......
......@@ -28,13 +28,27 @@ def i() =
def d(x,
y) =
{ while a + c - d <= 0 || c <> a do
y := y - 1;
done;
{ while a + c - d <= 0 || c <> a
y := y - 1;;
if continue = 0 then x := x * x else skip;
return z;
}
def test() =
{ if true then if false then skip else skip;
return ;
}
def test'() =
{ if true then if false then skip else skip;
return ;
}
def test''() =
{ if true then { if false then skip; } else skip;
return ;
}
def f(a) =
{ y := i();
z := d(a, b);
......@@ -42,14 +56,12 @@ def f(a) =
}
def loop2() =
{ while true do
y := 0;
while true do
x := x + 1;
y := y - 1;
done;
x := y + x;
done;
{ while true
{ y := 0;
while true
{ x := x + 1;
y := y - 1; };;
x := y + x; };;
z := x + y;
return z;
}
......
def loop() = {
while true do skip; done;
while true skip;
return 0
}
def loop() =
{ while true do
skip;
done;
{ while true
skip;;
return 0;
}
while true do skip; done
while true skip
while true do
while true
skip;
done
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment