[CSC467 Type of an expression

43 views
Skip to first unread message

Iftekhar Chowdhury

unread,
Nov 23, 2012, 10:00:16 PM11/23/12
to uoft_csc...@googlegroups.com
Hi Peter,

Consider the following code fragment:

{
   int   a = 1;
   float b = 2.0;
   float c = a + b;
}

Should the expression a + b have type int or float in the printed AST ? How do we determine type of an expression in general ?

Thanks,
Iftekhar


Peter Goodman

unread,
Nov 24, 2012, 11:50:21 AM11/24/12
to uoft_csc...@googlegroups.com

"a + b" is not a typeable expression according to the spec. You need only ensure that you properly print all semantically correct programs. If you want to print incorrect ones, then print out "any" as the result type.

Sent from my mobile device.

--
 
 

Minsoo Jee

unread,
Nov 26, 2012, 12:38:17 PM11/26/12
to uoft_csc...@googlegroups.com
Hi Peter,

float c = 1 + 1.2;

is this a semantically wrong statement?

How about 

if ( 1.1 > 2)..

For binary expressions, both right and left have to match the types?

Thanks.


2012년 11월 24일 토요일 오전 11시 50분 22초 UTC-5, Peter Goodman 님의 말:

Peter Goodman

unread,
Nov 27, 2012, 2:11:00 PM11/27/12
to uoft_csc...@googlegroups.com
Neither are correct.

Best Regards,

Peter Goodman,
http://www.petergoodman.me
65 High Park Ave.,
Toronto, Ontario
M6P 2R7


--
 
 

Reply all
Reply to author
Forward
0 new messages