Re: Enum?

new topic     » goto parent     » topic index » view thread      » older message » newer message

gshingles wrote:

> I was wondering how you would determine the range of an
> enum from one of its members but if I understand what
> you are proposing, the ^ and $ symbols are valid from
> the start to the end of the enum statement.

I was just 'shooting from the hip'. It was not a thought out proposal or syntax.

> does the entry 'minFILE' count against the value of maxFILE? :)

But now I've got a bit of time I'll flesh it out a bit more...

There are three properies of an enumeration that can be useful to know:
(1) The number of elements in the enumeration.
(2) The value of the lowest item.
(3) The value of the highest item.

All of these are known to the parser. I propose that in addition to setting
values in an enumeration, that three special tokens can be used that denote these
three properities on an enumeration.

The tokens I propose are these below ... (but please feel free to come up with
better ones)
(1) enum:length
(2) enum:min
(3) enum:max

When used in an enumeration declaration, they do not themselves become values in
the enumeration.

Example:

enum
   FILE_NO,
   LINE_NO,
   FILE_PTR,
   FILE_START_SYM,
   OP_WARNING=-1,
   OP_TRACE=-2,
   OP_TYPE_CHECK=0,
   OP_PROFILE_TIME=18,
   OP_PROFILE_STATEMENT=3,
   OP_DEFINES=9,
   minFILE=enum:min,   -- lowest enumeration value
   maxFILE=enum:max,   -- highest enumeration value
   lenFILE=enum:length -- count of items in THIS enumeration


This is equivalent to ...
constant
   FILE_NO = 1,
   LINE_NO = 2,
   FILE_PTR = 3,
   FILE_START_SYM = 4,
   OP_WARNING = -1,
   OP_TRACE = -2,
   OP_TYPE_CHECK = 0,
   OP_PROFILE_TIME = 18,
   OP_PROFILE_STATEMENT = 3,  -- note duplicates are okay
   OP_DEFINES = 9,
   minFILE = -2,   -- lowest enumeration value
   maxFILE = 18,   -- highest enumeration value
   lenFILE = 10 -- count of items in THIS enumeration


If used, the special enumeration values MUST be the last ones in the declaration
and each one can be used any number of times (0 or more) before the end of the
enumeration.

-- 
Derek Parnell
Melbourne, Australia
Skype name: derek.j.parnell

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu