flat assembler
Message board for the users of flat assembler.
 flat assembler > Macroinstructions > Splitting list of symbols
Author
Tomasz Grysztar
Assembly Artist

Joined: 16 Jun 2003
Posts: 6741
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,    purge splitter    match splitted, list \{ 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 rest, items \\{ listattach list,                                            defsplitter                                            splitter list,separator,                                            restore splitted \\}      match ,splitted \\{ listattach list,                          restore splitted \\} \} }
11 Jul 2005, 07:15
Tomasz Grysztar
Assembly Artist

Joined: 16 Jun 2003
Posts: 6741
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 sym, items    \{ match separator,sym \\{ list equ list>,<                               continue equ \\}       match =continue s, continue sym \\{ list equ list s                                           continue equ \\}       restore continue \}   match params,  \{ 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.
02 Aug 2005, 14:04
 Display posts from previous: All Posts1 Day7 Days2 Weeks1 Month3 Months6 Months1 Year Oldest FirstNewest First

 Jump to: Select a forum Official----------------Blog General----------------MainDOSWindowsLinuxUnixMenuetOS Specific----------------MacroinstructionsCompiler InternalsIDE DevelopmentOS ConstructionNon-x86 architecturesHigh Level LanguagesProgramming Language DesignProjects and IdeasExamples and Tutorials Other----------------FeedbackHeapTest Area

Forum Rules:
 You cannot post new topics in this forumYou cannot reply to topics in this forumYou cannot edit your posts in this forumYou cannot delete your posts in this forumYou cannot vote in polls in this forumYou cannot attach files in this forumYou can download files in this forum