7. gyakorlat
Szívesen lennék többen
Byeson -d while.y
Szintaktikus elemzés
makeFile: make
Mi a futtató parancs?
./while [Path]
A DON kulcsszó
Feladat
Kód:
Parancssor:
declarations -> epsilon
declaration -> NAT ID
declarations -> declarations declaration
commands -> epsilon
command -> REA OP ID CL
commands -> commands command
start -> PRG ID declarations BEG commands END
Alulról felfelé értelmezzük. DON
Feladat (gy / 2.)
Egyészítsük ki a while nyelvet a következő kifejezéssel:
<kifejezés>?<kifejezés>:<kifejezés>
while.y: tokenek felsorolásához
while.l
while.y
expression:
// ...
OP expression QUE expression COL expression CL
{
std::cout << "expression -> OP expression QUE expression COL expression CL" << std::endl;
}
Feladat (gy / 3.)
Adjunk a WHILE nyelvhez repeat ciklust, melyben a repeat és until kulcsszó között tetszőleges számú utasítás állhat, az until után pedig egy kifejezés:
repeat x := x + 1 until x = 10
while.l
while.y: tokenek felsorolásához
while.y
commands:
// ...
REP commands UN expression
{
std::cout << "command -> REP commands UN expression" << std::endl;
}
Feladat (gy / 3.)
Adjunk a WHILE nyelvhez for ciklust az alábbi formában:
for i from 1 upto 10 do write(i) done
for i from 10+2 downto 2-1 do write(i) done
for from upto downto
for i from 1 upto 10 do write(i) done
for i from 10+2 downto 2-1 do write(i) done
while.l
for return parser::token::FOR;
from return parser::token::FROM;
upto return parser::token::UPTO;
downto return parser::token::DOWNTO;
while.y: tokenek felsorolásához
while.y
commands:
// ...
FOR ID FROM expression DOWNTO expression DO commands DON
{
std::cout << "commands -> FOR ID FROM expression DOWNTO expression DO commands DON" << std::endl;
}
FOR ID FROM expression UPTO expression DO commands DON
{
std::cout << "commands -> FOR ID FROM expression UPTO expression DO commands DON" << std::endl;
}
vagy
direction:
DOWNTO
{
std::cout << "direction -> DOWNTO" << std::endl;
}
|
UPTO
{
std::cout << "direction -> UPTO" << std::endl;
}
;
commands:
// ...
FOR ID FROM expression direction expression DO commands DON
{
std::cout << "commands -> FOR ID FROM expression direction expression DO commands DON" << std::endl;
}