While Language Specification
Syntactic Categories
P | Programs |
V | Variable declarations |
S | Statements |
x, y | Variables |
n | Numerals |
a | Arithmetic expressions |
b | Boolean expressions |
opa | Arithmetic operators: + , - , / , * , % |
opb | Boolean operators: and , or , xor |
opr | Relational operators: == , != , < , > , <= , >= |
opbt | Bitwise operators: << , >> , & , | , ^ |
Abstract Syntax
Programs P:
- S
Variable declarations V:
- V1
;
V2 var
x
Statements S:
begin
V;
Send
- S1
;
S2 skip
if
bthen
S1else
S2while
bdo
Swrite
awrite
bread
x
Boolean expressions b:
true
false
(
b)
not
b- b1 opb b2
- a1 opr a2
Arithmetic expressions a:
(
a)
-
a- x
- n
- a1 opa a2
- a1 opbt a2
Example
While program calculating factorial is here:
begin
var x;
var y;
var z;
read x;
y := x;
z := 1;
while y > 1 do
z = z * y;
y = y - 1
write y
end