You are on page 1of 2

i) Design a Non-deterministic Finite Automata (NFA) for the syntax of the chosen

construct. Note that the NFA must cover the generic syntax of the construct, and not
be limited to just a specific sample code. The syntax covers all valid code for the
construct, hence the NFA must accept all valid code, whilst rejecting all invalid code.

Solution:

Constructing the Non-deterministic Finite Automata (NFA).

The while loop construct of the Python programming language is chosen to design the Non-
deterministic Finite Automata (NFA).

syntax of the while loop construct:

while (condition):

statement

… (code block)

Figure 1: Flowchart of while loop


Figure 2: NFA for while loop syntax Python

σ = {w, h, i, l, e, (, ), :, α, β}

α = Condition

β = Body of statements

∅ =! σ (invalid input)

You might also like