2018-2019
2018-2019 copied to clipboard
Lecture "Introduction to Computational Thinking", exercise 1
What are all the possible sentences that can be produced by using the regular grammar introduced in Section "Historic hero: Noam Chomsky"?
regular grammar
<sentence> ::= "I"
Regular grammar possible generic sentence:
<non terminal>
::= "terminal"
<non terminal>
::= "terminal" <non terminal>
i.e.
<sentence>
::= "I" <sentence>
::= "you" <verb>
::= "write"
<verb>
::= "read"
possible example sentences
I write ("terminal" = "I" and <non terminal>
= <verb>
('write'))
I read ("terminal" = "I" and <non terminal>
= <verb>
('read'))
you write ("terminal" = "you" and <non terminal>
= <verb>
('write'))
you read ("terminal" = "you" and <non terminal>
= <verb>
('read'))
Regular grammar rules can be summarized in:
<non-terminal>
::= "terminal"
<non-terminal>
::= "terminal"
For example, in order to create a sentence, this could be the combination:
<sentence>
::= "I" <verb>
<verb>
::= "eat"
<verb>
::= "sleep"
Possible combinations:
I eat (composed by the terminal "I" and the <non-terminal>
/<verb>
"eat")
I sleep (composed by the terminal "I" and the <non-terminal>
/<verb>
"sleep")
From regular grammar with production rules:
<sentence>
::= "I" <verb>
<sentence>
::= "you" <verb>
<verb>
::= "write"
<verb>
::= "read"
Possible sentences:
I write ( <terminal>
= "I"; <non-terminal>=<verb>("write"))
I read( <terminal>
= "I"; <non-terminal>=<verb>("read"))
you write ( <terminal>
= "you"; <non-terminal>=<verb>("write"))
you read ( <terminal>
= "you"; <non-terminal>=<verb>("read"))
Forms of production:
<non terminal>
::= "terminal"
<non terminal>
::= "terminal" <non terminal>
For instance:
<sentence>
::= "He" <verb>
<sentence>
::= "She" <verb>
<verb>
::= "runs"
<verb>
::= "works"
Possible combinations:
He runs ("terminal" = "He" and <verb>
"runs")
He works ("terminal" = "He" and <verb>
"works")
She runs ("terminal" = "She" and <verb>
"runs")
She works ("terminal" = "She" and <verb>
"works")
Form of production rules for regular grammar:
<non-terminal>
::="terminal" and <non-terminal>
::="terminal" <non-terminal>
<sentence>
::="I" <verb>
<sentence>
::="We" <verb>
<verb>
::="cry"
<verb>
::="die"
I cry ("terminal" = I and <verb>
, specifically <verb>
= cry)
I die ("terminal" = I and <verb>
, specifically <verb>
= die)
We cry ("terminal" = We and <verb>
, specifically <verb>
= cry)
We die ("terminal" = We and <verb>
, specifically <verb>
= die)
That allows me to create all the two-word sentences having as a terminal either the first person singular or the first person plural pronoun accompanied by either the (non-terminal part) <verb>
"cry" or the <verb>
"die", for a total of four combinations.
<sentence>::
= "I" <verb>
<sentence>::
= "They" <verb>
<verb>::
= "walk"
<verb>::
="fly"
I walk (terminal: "I", terminal: "walk", non-terminal: <verb>
)
I fly (terminal: "I", terminal: "fly", non-terminal: <verb>
)
They walk (terminal:"They", terminal: "walk", non-terminal: <verb>
)
They fly (terminal:"they", terminal:"fly", non-terminal: <verb>
)
Possible sentences that can be produced by using the regular grammar:
<non terminal> ::= "terminal"
<non terminal> ::= "terminal"
Examples:
<sentence> ::= “I”
Possible example sentences:
I write ("terminal" = "I" and
Form of production rules of regular grammars:
non-terminal ::= "terminal"
and <non-terminal> ::= "terminal" <non-terminal>
.
i.e.
<sentence> ::= "I" <verb>
<sentence> ::= "we" <verb>
<verb> ::= "run"
<verb> ::= "walk"
Considering these non-terminal elements we can produce four possible sentences:
-
I run -
<pronoun> ::= "I"
and<verb> ::= "run"
-
I walk -
<pronoun> ::= "I"
and<verb> ::= "walk"
-
we run -
<pronoun> ::= "we"
and<verb> ::= "run"
-
we walk -
<pronoun> ::= "we"
and<verb> ::= "walk"
A sentence can either contain "I" plus a verb or "You" plus a verb. There are two defined verbs: "write" and "read". Hence, four constellations are possible.
- I write
- I read
- You write
- You read
@MattiaSpadoni and @ilsamoano and @lisasiurina
<sentence>
::= "I"<sentence>
::= "you"
There is something strange here... maybe you wanted to refer to <pronoun>
instead of <sentence>
?