Designing context-free grammars

Designing context-free grammars

by Giorgio Satta -
Number of replies: 8

Dear All, this week and the last week I have spent some time in class discussing several exercises that provide a context-free language and ask you to design a context-free grammar that generates that language.

I am seeking now volunteers who can post some of the exercises that we have solved, so that students who have not been able to be at the lectures can still access that material.

Thank you very much in advance for your help with this!

In reply to Giorgio Satta

Re: Designing context-free grammars

by Giorgio Satta -

Nobody has followed up with this thread ...

If you have some time this weekend please write down at least one of the exercises that have been done in class about CFGs. In this way we should be able to have a complete coverage of those activities.

In reply to Giorgio Satta

Re: Designing context-free grammars

by MATTEO PADRIN -
Dear professor and students, I will break the ice showing the first exercise (Lecture 14 #1) :
image.png
 
 
I will happily accept any corrections, alternative solutions, or questions about mine. If you need the solution to any other exercise (also not from Lecture 14), I have them all, no worries, and just ask 
In reply to MATTEO PADRIN

Re: Designing context-free grammars

by DENISA ALEXANDRA STOICA -

Can you upload all the exercise from the last friday and the 31/10?

In reply to DENISA ALEXANDRA STOICA

Re: Designing context-free grammars

by Giorgio Satta -
Denisa, which exercises are you missing? It seems to me that Gianmarco has posted all the exercises about CFGs ... Please let me know.
In reply to Giorgio Satta

Re: Designing context-free grammars

by GIANMARCO FOSSATO -
Here are all the exercises. At the top of the first page, there are some notes about how I use colours for text (just to make it a bit less confusing). I apologize in advance for bad English or if some steps seem a bit disorganized.
In reply to Giorgio Satta

Re: Designing context-free grammars

by Giorgio Satta -

The grammars by both Gianmarco and Matteo are correct, I do not see any mistake.

Only comment: I do not understand the tree in the post by Matteo, that does not look like a valid parse tree for the grammar.

In reply to Giorgio Satta

Re: Designing context-free grammars

by MATTEO PADRIN -

Dear professor, 

You are absolutely correct, I am sorry for the mistake. I don't know why the picture was cropped. 

image.png

In my notes I wanted to stress the fact that a language can be either expressed with a tree, so I came up with the parse tree that shows the derivation of the string aaabbb. The complete tree is a parse tree since I created the arcs from S to a and b and all the leaves are terminal symbols right? 

Thanks a lot for your correction. 

 

 

In reply to MATTEO PADRIN

Re: Designing context-free grammars

by Giorgio Satta -

Ok Matteo, but your tree does not look right ... The node labeled S at the 2nd level should have three children according to the rule. Also, the symbols a and b at the second level should not have any child node.