WHILE {
Program = Cmd | BExp | AExp
Cmd (commands / statements)
= Cmd ";" Cmd -- seq
| "if" BExp "then" Cmd "else" Cmd "end" -- if
| "while" BExp "do" Cmd "end" -- while
| var ":=" AExp -- assign
| "skip" -- skip
BExp
= BExp "&&" BExp -- and
| BExp "||" BExp -- or
| "!" PriBExp -- not
| PriBExp
PriBExp
= "(" BExp ")" -- paren
| "&&" PriBExp -- and
| "||" PriBExp -- or
| AExp "=" AExp -- eq
| AExp ">" AExp -- gt
| AExp "<" AExp -- lt
| AExp ">=" AExp -- geq
| AExp "<=" AExp -- leq
| bool
AExp (arithmetic expressions)
= AExp "+" AExp -- add
| AExp "-" AExp -- sub
| AExp "*" PriAExp -- mul
| PriAExp
PriAExp
= "(" AExp ")" -- paren
| "+" PriAExp -- pos
| var
| number
bool (a bool value)
= "true" ~var
| "false" ~var
var (a variable)
= letter+
number (positive and negative integers)
= "-" digit+ --negative
| digit+ --positive
}
x := 6;
y := 7;
z := 0;
while x > 0 do
x := x - 1;
v := y;
while v > 0 do
v := v - 1;
z := z + 1
end
end
while x > 0 do
x := x - 1;
v := y;
while v > 0 do
v := v - 1;
z := z + 1
end
end
x := 0;
y := 1;
z := 0;
while x < 100 do
z := x + y;
x := y;
y := z
end
z := (x+3) * (y-2)
(2 - -4) * (11 - y)
!1=1 || (true && 3 <= 4)