Macro:
Code:
macro enum? enumeration
   local next
   next = 0
   match any, enumeration
      struc (enumerator) ? value := next, empty
         assert ~lengthof `empty
         namespace enumeration
            enumerator :value
            next = enumerator + 1
            enumeration equ enumerator
         end namespace
      end struc
   else
      struc ? value := next, empty
         assert ~lengthof `empty
         . :value
         next = . + 1
      end struc
   end match
   macro end?.enum?!
      restruc ?
      purge end?.enum?
   end macro
end macro

Usage:

Code:
enum NAME
   VALUE0
   VALUE1
   VALUE3 = 3
   VALUE4
   VAL1 = VALUE1
end enum
db NAME.VALUE0, NAME.VALUE1, NAME.VALUE3, NAME.VALUE4, NAME.VAL1 ; same as db 0, 1, 3, 4, 1
irpv each, NAME
   db `each, each
end irpv ; same as db 'VALUE0', 0, 'VALUE1', 1, 'VALUE3', 3, 'VALUE4', 4, 'VAL1', 1

NAME can be ommitted to put the enumerators in the global namespace.
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 1
» All times are GMT - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement