Dsy Network www | forum | my | didattica | howto | wiki | el goog | stats | blog | dona | rappresentanti
Homepage
 Register   Calendar   Members  Faq   Search  Logout 
.dsy:it. : Powered by vBulletin version 2.3.1 .dsy:it. > Didattica > Corsi G - M > Linguaggi formali e automi > Esercizio su CFG (Context Free Grammar)
  Last Thread   Next Thread
Author
Thread    Expand all | Contract all    Post New Thread    Post A Reply
Collapse
Bemipefe
.fedelissimo.

User info:
Registered: Jul 2005
Posts: 44 (0.01 al dì)
Location: P.M.
Corso: Scienze Informatiche
Anno: Secondo (...teoricamente)
Time Online: 2:59:00: [...]
Status: Offline

Post actions:

Edit | Report | IP: Logged
Esercizio su CFG (Context Free Grammar)

Salve!
Sto studiando le CFG (context free grammar) spero di essere nella sezione giusta.

Allora ... riferendomi all'esercizio seguente:

code:
- Costruire una CFG che generi l’insieme di tutte le stringhe di parentesi correttamente annidate.


Per generare tale linguaggio a me era venuto in mente la banale:


code:
S ->(SB | $ /*$ = parola vuota*/ B -> )


Pero come soluzione viene data:

code:
S -> $ | (S)S


Ora tutte e due generano un linguaggio di parentesi correttamente annidate. Nessuna delle due però riesce a generare ad esempio questa stringa : "(()())"

Quindi non ho capito se si richiede un linguaggio che contenga parentesi correttamente annidate o il linguaggio di TUTTE le stringhe fatte da parentesi correttamente annidate.

Grazie!
Buon Lavoro

__________________
_/\/\/\Bemipefe/\/\/\_

10-11-2007 18:49
Click Here to See the Profile for Bemipefe Click here to Send Bemipefe a Private Message Visit Bemipefe's homepage! Find more posts by Bemipefe Add Bemipefe to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
Collapse
Polsy
.arcimaestro.

User info:
Registered: Dec 2003
Posts: 477 (0.06 al dì)
Location:
Corso: Info phd
Anno:
Time Online: 17 Days, 17:11:50 [...]
Status: Offline

Post actions:

Edit | Report | IP: Logged

Veniva richiesta una grammatica che generasse TUTTE le stringhe di parentesi ben annidate, la seconda grammatica è giusta, infatti genera anche (()()):
S => (S)S => (S) => ((S)S) => (()S) => (()(S)S) => (()()S) => (()())

Il problema della prima grammatica è che non ti permette di affiancare parentesi, ma solo di annidarle, infatti visto che B può generare solo ")", è analoga a
S -> (S) | $
aggiungendo una S in fondo invece hai la possibilità di generare un'altra coppia di parentesi dopo quella chiusa.

10-11-2007 20:26
Click Here to See the Profile for Polsy Click here to Send Polsy a Private Message Visit Polsy's homepage! Find more posts by Polsy Add Polsy to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
Collapse
Bemipefe
.fedelissimo.

User info:
Registered: Jul 2005
Posts: 44 (0.01 al dì)
Location: P.M.
Corso: Scienze Informatiche
Anno: Secondo (...teoricamente)
Time Online: 2:59:00: [...]
Status: Offline

Post actions:

Edit | Report | IP: Logged

Grazie!

Tutto chiaro....ma mi rende perplesso il fatto che quando si applica la regola S -> $ la si possa applicare solo per alcune variabili. Io pensavo che applicando quella regola, tutte le variabili venissere automaticamente sostituite da $.

__________________
_/\/\/\Bemipefe/\/\/\_

11-11-2007 11:50
Click Here to See the Profile for Bemipefe Click here to Send Bemipefe a Private Message Visit Bemipefe's homepage! Find more posts by Bemipefe Add Bemipefe to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
All times are GMT. The time now is 20:22.    Post New Thread    Post A Reply
  Last Thread   Next Thread
Show Printable Version | Email this Page | Subscribe to this Thread | Add to Bookmarks

Forum Jump:
Rate This Thread:

Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is OFF
vB code is ON
Smilies are ON
[IMG] code is ON
 

Powered by: vBulletin v2.3.1 - Copyright ©2000 - 2002, Jelsoft Enterprises Limited
Mantained by dsy crew (email) | Collabora con noi | Segnalaci un bug | Archive | Regolamento | Licenze | Thanks | Syndacate
Pagina generata in 0.028 seconds (77.00% PHP - 23.00% MySQL) con 28 query.