flat assembler
Message board for the users of flat assembler.
 Home   FAQ   Search   Register 
 Profile   Log in to check your private messages   Log in 
flat assembler > Macroinstructions > Splitting list of symbols

Author
Thread Post new topic Reply to topic
Tomasz Grysztar
Assembly Artist


Joined: 16 Jun 2003
Posts: 6824
Location: Kraków, Poland

Splitting list of symbols

This is macro which may become useful for those, who write some complex macroinstructions. It may be used just as is, but it can also serve as a reference.

It's purpose is to split given sequence of symbols on boundaries defined by specified separator, and then call the specified macroinstruction with multiple parameters, each being one of the splitted chunks.
For example:

Code:
split mymacro,+, 1+2+3*3


will cause this operation to be performed:

Code:
mymacro 1,2,3*3



When no separator is specified, the sequence is splitted to the single symbols, so this:

Code:
split mymacro,, 1+2+3*3


will be unrolled to:

Code:
mymacro 1,+,2,+,3,*,3



The sequence of symbols can also be the value of symbolic constant, so the above sample is eqivalent to:

Code:
myexpr equ 1+2+3*3
split mymacro,,myexpr



And here is the macro:

Code:
macro split macroname,separator,[items]
common local list
   list equ
   defsplitter
   splitter list,separator,<items>
   purge splitter
   match splittedlist \{ macroname splitted \} }

macro listattach list,item
match any,list \{ list equ list,item \}
  match ,list \{ list equ item \} }

macro defsplitter
local splitted
  macro splitter list,separator,items
  \{ splitted equ
     match first separator restitems \\{ listattach list,<first>
                                           defsplitter
                                           splitter list,separator,<rest>
                                           restore splitted \\}
     match ,splitted \\{ listattach list,<items>
                         restore splitted \\} \} }

Post 11 Jul 2005, 07:15
View user's profile Send private message Visit poster's website Reply with quote
Tomasz Grysztar
Assembly Artist


Joined: 16 Jun 2003
Posts: 6824
Location: Kraków, Poland

The "irps" directive allows to do the same thing much simpler, without recursion:

Code:
macro split macroname*,separator*,items
local list,continue
  list equ
  irps symitems
   \{ match separator,sym \\{ list equ list>,<
                              continue equ \\}
      match =continue scontinue sym \\{ list equ list s
                                          continue equ \\}
      restore continue \}
  match params, <list> \{ macroname params \} }


Note that this macro is better from the above one, as it encloses each parameter to macro within < and > characters, so splitted parts may contain commas. On the other hand it doesn't support an empty separator - but splitting to single symbols can be done with the "irps" directive directly.
Post 02 Aug 2005, 14:04
View user's profile Send private message Visit poster's website Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >

Forum Rules:
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
You cannot attach files in this forum
You can download files in this forum


Main index   Download   Documentation   Examples   Message board
Copyright © 2004-2018, Tomasz Grysztar.
Powered by rwasa.