You are on page 1of 3

LIS3042-1 Theory of Computation UDLAP - Autumn 2021

Grammar Design
Víctor A. Canales Lima 162328

Rules
<LOOP> ::= <LOOP>: <EXPR>
<LOOP> ::= for identifier in range(value, value)
<EXPR> ::= <EXPR> <LOOP>
<EXPR> ::= <LOOP>
<EXPR> ::= print( string )
<EXPR> ::= print( identifier )

Vocabulary
𝑣𝑎𝑙𝑢𝑒 ∈ ({1, … ,9}+ ∘ {0, … ,9}⋆ | 0)
𝑖𝑑𝑒𝑛𝑡𝑖𝑓𝑖𝑒𝑟 ∈ ({𝑎, … , 𝑧}+ ∘ ({𝑎, … , 𝑧}|{0, … ,9})⋆ )
𝑠𝑡𝑟𝑖𝑛𝑔 ∈ (" ∘ ({𝑎, … , 𝑧}|{0, … ,9})⋆ ∘ ")

Definition
LIS3042-1 Theory of Computation UDLAP - Autumn 2021

Examples

Source Code Objective Code


for i in range(0,3): for i in 0..<3 {
print(i) print(i)
}
for i in range(0,3): for i in 0..<3 {
print(i) print(i)
for j in range(0,4): for j in 0..<4 {
print("Hello World") print("Hello World")
}
}
for i in range(0,3): for i in 0..<3 {
for j in range(0,4): for j in 0..<4 {
for k in range(0,5): for k in 0..<5 {
print("Hello World") print("Hello World")
}
}
}
Table 1 Examples for the designed grammar
LIS3042-1 Theory of Computation UDLAP - Autumn 2021

Figure 1 Parser Tree for the first example

Figure 2 Parser tree for the second example

Figure 3 Parser tree for the third example

You might also like