[cpl] [Tema1] Rolul IF / WHILE

Cosmin - Ioan PETRI?OR cosmin_ioan.petrisor at cti.pub.ro
Sat Oct 31 19:08:21 EET 2015


Bun. Deci o constructie var x = expresie <operator> while ... trece cu succes de analiza sintactica.


One more question, though (desi nu are legatura cu while sau if): Am observat, de asemenea, ca in manual operatorul ! are precedenta mai mica decat operatorul unar - toti ceilalti operatori binari. Asta inseamna ca o expresie de genul !5 + 3 va fi evaluata la fel ca si expresia !(5 + 3) si nu (!5) + 3. Care e rezultatul dorit?


Cosmin

________________________________
From: Raluca Grigoras <ralucav at gmail.com>
Sent: Saturday, October 31, 2015 7:01 PM
To: Cosmin - Ioan PETRI?OR; Compilatoare
Subject: Re: [cpl] [Tema1] Rolul IF / WHILE

Dpdv sintactic constructia ar fi corecta.
Raluca

On Oct 31, 2015, at 6:38 PM, Cosmin - Ioan PETRI?OR via cpl <cpl at cursuri.cs.pub.ro<mailto:cpl at cursuri.cs.pub.ro>> wrote:

Salutare,

Ok, dar problema mea este de natura sintactica si nu semantica. Sa inteleg ca si din punct de vedere sintactic o constructie x = 2 + while ... ar fi gresita? As I was saying before, in manual sunt tratate identic cele doua statement-uri, cel putin sintactic vorbind.

Cosmin


________________________________
From: Raluca Grigoras <ralucav at gmail.com<mailto:ralucav at gmail.com>>
Sent: Saturday, October 31, 2015 6:34 PM
To: Cosmin - Ioan PETRI?OR; Compilatoare
Subject: Re: [cpl] [Tema1] Rolul IF / WHILE

Salut,

Tipul unei expresii IF este dat de tipul ultimei instructiuni/expresii din cele doua ramuri. Prin urmare o expresie IF poate avea tipul Int.
Tipul unei expresii WHILE este mereu Void, in cazul in care ar aparea intr-o expresie de genul var x = 2 + while ..., ar fi o eroare semantica, pentru ca tipul Void nu poate fi convertit la Int.

Raluca



On Oct 31, 2015, at 6:23 PM, Cosmin - Ioan PETRI?OR via cpl <cpl at cursuri.cs.pub.ro<mailto:cpl at cursuri.cs.pub.ro>> wrote:

Hello,

Am vazut in manual, pag. 11, ca IF si WHILE sunt considerati operatori (mai mult decat atat, de acelasi rang). Fair enough.

Problema este ca in teste am observat expresii de genul: var = 2 + if ... then ... else ... end; and I'm ok with that. Dar ce nu am reusit sa deslusesc este daca si WHILE are acelasi statut, pentru ca am vazut doar blocuri WHILE independente.

So here comes my question: Putem folosi constructii WHILE in cadrul expresiilor, sau trebuie tratat separat de IF?

Numai bine,
Cosmin
_______________________________________________
cpl mailing list
cpl at cursuri.cs.pub.ro<mailto:cpl at cursuri.cs.pub.ro>
http://cursuri.cs.pub.ro/cgi-bin/mailman/listinfo/cpl

_______________________________________________
cpl mailing list
cpl at cursuri.cs.pub.ro<mailto:cpl at cursuri.cs.pub.ro>
http://cursuri.cs.pub.ro/cgi-bin/mailman/listinfo/cpl

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://cursuri.cs.pub.ro/pipermail/cpl/attachments/20151031/70bf423e/attachment.html>


More information about the cpl mailing list