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 varx
Statements S:
beginV;Send- S1
;S2 skipifbthenS1elseS2whilebdoSwriteawritebreadx
Boolean expressions b:
truefalse(b)notb- 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