Author Topic: Parsing text  (Read 218 times)


  • Moderator
  • Member
  • *****
  • Posts: 7552
  • Assembler is fun ;-)
    • MasmBasic
Parsing text
« on: June 02, 2017, 06:56:40 PM »
A very simple example how to parse text: This snippet loads a text file into an array, and then strips comments and white space, e.g. to prepare the text for compiling.

include \masm32\MasmBasic\      ; download
  SetGlobals destCt, tmp$      ; create two global variables
  Dim dest$()
  Recall "\Masm32\examples\exampl07\shuflarr\unique_riched\txtfnd.asm", L$()
  For_ ecx=0 To eax-1
      Let tmp$=Trim$(Left$(L$(ecx), Instr_(L$(ecx), ";")-1))
      .if Len(tmp$)
            Let dest$(destCt)=tmp$
            inc destCt
  For_ ecx=0 To destCt-1
      PrintLine Str$(ecx), Tb$, "_", dest$(ecx), "_"  ; _delimit line with understroke_

Project attached.
To test it, open the *.asc in RichMasm and hit F6.
To learn more about each command, move the mouse over e.g. Recall, and right-click when the cursor turns into a ?
To compare the output (PrintLine...) to the original, open txtfnd.asm in Notepad or RichMasm and arrange the console and editor windows accordingly.