We are constructing a new programming language to program a painting robot. This language allows us to
construct simple loops, if-else blocks and give the robot some basic commands. Our robot is also capable of
sensing the color of the objects. We call this language “Robot Programming Language” (RPL). Syntax of
Robot Programming Language is represented as a Context Free Grammar RPG = (Σ, NT, R ,S ) where;
Σ = { git, boya, birim, bir, iki, uc, dort, bes, alti, yedi, sekiz,
dokuz, on, doguya, batiya, kuzeye, guneye, siyaha, beyaza, kirmiziya, yesile,
maviye, tekrarla , defa, dongu, degilse, son, zemin , i , esit, degil}
NT = { [Kod], [Blok], [Komut], [Dongu], [ise-degilse], [Kosul],
[Degilse], [Sayi], [Yon], [Renk], [Hedef], S }
R = {
S → [Kod],
[Kod] → [Kod] [Kod],
[Kod] → [Blok],
[Kod] → [Komut],
[Komut] → [Sayi] birim [Yon] git,
[Komut] → [Hedef] i [Renk] boya,
[Komut] → [Komut] [Komut],
[Blok] → [Dongu] son,
[Blok] → [ise-degilse] son,
[Blok] → [Blok] [Blok],
[Dongu] → [Sayi] defa tekrarla [Kod],
[Dongu] → dongu [Kosul] [Kod],
[ise-degilse] → [Kosul]ise [Kod] [Degilse],
[Degilse] → degilse [Kod],
[Degilse] → ℮,
[Kosul] → [Hedef] esit [Renk],
[Kosul] → [Hedef] esit degil [Renk],
[Sayi] → bir |iki |uc |dort |bes |alti |yedi |sekiz |dokuz |on,
[Yon] → doguya | batiya | kuzeye | guneye,
[Renk] → siyaha | beyaza | kirmiziya | yesile| maviye,
[Hedef] → zemin}
S: Starting symbol
Each terminal has a blank character at its end as a delimiter.
An example input that is accepted by this language is given below;
dort defa tekrarla
on birim guneye git
son
on defa tekrarla
bes defa tekrarla
bir birim doguya git
zemin esit yesile ise
zemin i beyaza boya
son
son
son
This code moves the robot 40 units to south, then for 50 times, moves the robot to east by 1 unit while
painting the ground to white if it is green. A parse tree generated for the code above is given in below;
PART A (90 Points):
Write a C / C++ / Java program to analyze a given source code which is written in RPL. Your program will
read an RPL source code from a text file called “rpl.txt” and decide whether the code is syntactically correct
or not. If the source code is correct, your program should give message “No syntax error found...”,
otherwise give message “Syntax Error at line: XX” where XX is the line number for the error encountered.