I have been doing some work recently in PowerBASIC assembler on a line parser that reads comma delimited arguments and loads them into a dynamic array. It is designed to handle quoted text that has embedded commas as a single argument but non quoted text as single arguments as normal.

I developed it using samples fom a resource editor that have both quoted text and ordinary arguments for each line. It treats empty arguments as a seperate argument so if you have the format "text,9,"more text",22, ,16

as 6 arguments that include the empty argument.

The parameters are the dynamic string that holds the line [ a$ ] and a dynamic array that must have enough members to hold all of the arguments [ item$() ]. There is no error testing if the arguments axceed the number of array members.

The return value is the number of arguments on the line passed to the function.

Regards,

hutch@movsd.com



' ?????????????????????????????????????????????????????????????????????????

FUNCTION ParseLine(a$,item$()) as LONG

#REGISTER NONE

LOCAL src as DWORD ' a$ address
LOCAL dst as DWORD ' array item address
LOCAL cnt as DWORD ' array counter

cnt = 0
src = StrPtr(a$)
dst = StrPtr(item$(cnt))
! mov esi, src
! mov edi, dst

lbl1:
! mov al, [esi]
! inc esi
! cmp al, 34 ; test for opening quotation mark
! je nxt2
! cmp al, "," ; test for comma delimiter
! je nxt1
! cmp al, 0 ; test for terminator
! je nxt3
! mov [edi], al
! inc edi
! jmp lbl1

' ------------------------
' increment array counter
' ------------------------
nxt1:
! mov BYTE PTR [edi], 0 ; write zero terminator on last item
! inc cnt
dst = StrPtr(item$(cnt))
! mov edi, dst ; reset address to next item in array
! jmp lbl1

' --------------------
' process quoted text
' --------------------
nxt2: ' handle quoted text
! mov [edi], al ; write first quote
! inc edi
lbl3:
! mov al, [esi]
! inc esi
! cmp al, 0 ; terminator
! je nxt3 ; jump to exit
! mov [edi], al ; write next character
! inc edi
! cmp al, 34 ; jump back on quotation mark
! je lbl1
! jmp lbl3

' --------------------
' exit label and code
' --------------------
nxt3:
! mov BYTE PTR [edi], 0 ; write final terminator

! inc cnt ; correct for base 1
FUNCTION = cnt ' argument count

END FUNCTION

' ?????????????????????????????????????????????????????????????????????????
Posted on 2002-10-28 04:42:02 by hutch--
In case anybody cares, here is the input file for JASG to create a parser for such strings:

, 10

(yes, it's quite complicated ;-)
Posted on 2002-10-28 06:22:28 by Jibz
I am working on an autopilote project. Se my thread 'Communicating with the parallel port?' (I don't know how to link). My application read NMEA sentences from a GPS connected to the serial port. There are appr 10 sentences. Each sentence begins with a ?$? and ends with a carriage return/line feed. The data is contained within this single line with data items separated by commas. The data itself is ascii text. Each sentence is identified by 5 characters after the ?$?. For example ?$GPRMC? = recommended minimum data for GPS. All sentences are updated every two seconds.

My modul ?ReadNMEA.asm? reads the sentences and parse the data to be processed into steering actions. I attach the modul.
Posted on 2002-10-28 11:29:10 by minor28
Jibz,

Nothing appeared in your posting for either the code or a link, could you repost either ?

Regards,

hutch@movsd.com
Posted on 2002-10-28 18:11:53 by hutch--
hutch--,

Nothing appeared in your posting for either the code or a link, could you repost either ?

Actually the single line with a comma, a space, and the number ten was the entire input file needed, i.e.



, 10


of course this only makes the tables -- code for calling the scanner and perform the appropriate code still needs to be written (which is left as an exercise ;-).
Posted on 2002-10-29 04:13:13 by Jibz