Author Topic: Parsing text  (Read 214 times)

jj2007

  • Moderator
  • Member
  • *****
  • Posts: 7551
  • 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\MasmBasic.inc      ; download
  SetGlobals destCt, tmp$      ; create two global variables
  Init
  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
      .endif
  Next
  For_ ecx=0 To destCt-1
      PrintLine Str$(ecx), Tb$, "_", dest$(ecx), "_"  ; _delimit line with understroke_
  Next
EndOfCode


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.