AllExperts > Experts 
Search      

Pascal

Volunteer
Answers to thousands of questions
 Home · More Questions · Answer Library  · Encyclopedia ·
More Pascal Answers
Question Library

Ask a question about Pascal
Volunteer
Experts of the Month
Expert Login

Awards

About Us
Tell friends
Link to Us
Disclaimer

 
 
 
 
About daru
Expertise
I started creating programs in Pascal for DOS in 1993 and continue to do it even now (in the era of Delphi). Apart from graphics, I can program anything from simple `15` game to more complicated communication programs (using serial or parallel ports). Turbo Vision was a part of my life some time ago, so please ask your questions in this area too, although I prefer to create DOS filters and other small utilities.

Experience
I wouldn't call it huge, but it's very sound. Enough to say, I can distinguish Turbo Pascal compiler-made binaries from Turbo C-made binaries.

Education/Credentials
Master of Economics

 
   

You are here:  Experts > Computing/Technology > Pascal > Pascal > Pseudo Pascal

Topic: Pascal



Expert: daru
Date: 4/10/2004
Subject: Pseudo Pascal

Question
Hi.
  I have a question that I am struggling with for some time now. I hope you allow me to ask this homework question as I have added my own thoughts on the solution.  Thank you:

a) Each of these definitions of a type is expressed in a PASCAL-like notation. For each right hand side:

1) Express it in terms of set-operations.
2) Indicate one representative member of the set that it defines.
3) Give its size.

TYPE
Colour = (yellow, red, blue, green);
Charr = ['a'..'z'];
Integerr = [1..99];
String = ARRAY[0..10] OF Charr;
Info = RECORD
I : Integerr;
S : String;
C : Colour;
END (*RECORD*);
vrec = RECORD
CASE card : CARDINAL OF
0 : I : Integerr;
|1 : C : Colour;
|2 : CC : Charr;
END (*CASE*);
END (*RECORD*);
hue = SET OF Colour;

================================================
My own comments:
1)Expressing RHS as set-operations:

Colour = { (x1, x2, x3, x4)| x1 belongs to yellow, x2 belongs to red, x3 belongs to blue, x4 belongs to green }


Charr = { x|x belongs to {a,b,c, …, z}}

Integerr = { x|x belongs to {1,2,3, …, 4}}

String = { [x0, x2, …, x10]| xi belongs to Charr}

Info = { I, S, C | I belongs to Integerr, S belongs to String, C belongs to Colour }

vrec = Im stuk with this. Although I have worked out that:
------------------------------
vrec = RECORD
CASE card : CARDINAL OF
0 : I : Integerr;
|1 : C : Colour;
|2 : CC : Charr;
END (*CASE*);
END (*RECORD*);
------------------------------

Is equal to:

------------------------------|
vrec = RECORD
CASE card : CARDINAL OF
0 : I : Integerr;|1 : C : Colour;|2 : CC : Charr;
END (*CASE*);
END (*RECORD*);
------------------------------

The '|' sign is the logical 'or'. I'm also guessing that the CARDINALITY of card is taken and cardinality is the number of members of the set called 'card'. Therefore when the cardinality is worked out, if it's 0 then the variable I is assigned the datatype Integerr, when its 1 the variable C is assigned the datatype Colour, and when its 2 the variable CC is assigned the datatype Charr.

As you can see i can't really answer parts 2 and three if im not sure of part 1.

I'd appreciate any help you can provide.
Thank you.

Answer
That's a strange task, really. IMHO it doesn't really do much to make you understand pascal types. But OK.

I hope they mean sets as they do in Algebra, right?

Colour: (1) {yellow, red, blue, green} - simple as that. (2) A member can be any color, i.e. green. (3) The size is 1 byte.

Charr: (1) {'a','b',...,'z'} (2) 'f' (3) 1 byte

Integerr: (1) {1,...,99} (2) 81 (3) 1 byte

String: (1) {wow, that's cool. any combination of 11 chars} (2) 'q1w2e3r4t5.' (3) 11 bytes

Info: (1) it's a set of three sets explained above (2) (12,'p0o9i8u7y6-',red) (3) 13 bytes

vrec: (1) sth like ({0,{1,...,99}} | {1,{yellow, red, blue, green}} | {2,{set of all 11-char combinations}}) (2) (1,blue) (3) max possible size - 12 bytes.

I hope it helps...

Add to this Answer    Ask a Question



  Rate this Answer
   Was this answer helpful?
Not at allDefinitely              
   12345  

     
About Us | Advertise on This Site | User Agreement | Privacy Policy | Help
Copyright  © 2008 About, Inc. About and About.com are registered trademarks of About, Inc. The About logo is a trademark of About, Inc. All rights reserved.