HP Forums

Full Version: [HP48/49] Command Line Parsing
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi,

I'm trying to improve the parsing routines of HPDL using the GetNextToken entry,
and I don't understand how it work, especially on the content of the hxs mask that it expect to find on the stack.

I think each one of the 256 nibbles represent a set of parsing rules to apply to the corresponding ASCII character,
but If I'm right, what is the meaning of each bit ?

Thank you for your help.
(02-16-2015 01:01 PM)Bruno Wrote: [ -> ]Hi,

I'm trying to improve the parsing routines of HPDL using the GetNextToken entry,
and I don't understand how it work, especially on the content of the hxs mask that it expect to find on the stack.

I think each one of the 256 nibbles represent a set of parsing rules to apply to the corresponding ASCII character,
but If I'm right, what is the meaning of each bit ?

Thank you for your help.

GetNextToken is actually a special pointer whose code resides at #1E181h. You can use Jazz on the HP50G to trace the algorithm via SDB and DB to get an idea of what the hxs mask is supposed to be. I haven't looked into the ROM beyond this; my suspicion, however, is that it may not be a mask but is instead a small scratch buffer to be used by the GetNextToken routine. I could very well be wrong.
Ha! Looks like I was wrong about the hxs-mask being a scratch buffer (as clearly explained in the entry description).
Hi Han,

I'm pretty sure that each hxs-mask's nibble represent a set of rules for each characters,
I'm playing with it but it's a little bit harder !
Here's a snippet of ROM from the HP48SX that may give you some insight as to how the nibbles are used.

Code:
*******************************************************************************
* #next points the next word. Gives "" if at the end
* (3:HxsMask 2:$ 1:#start -> 4:Hxsmask 3:$ 2:#next 1:$token)
* Gets the word starting at #nth char, strips spaces
*******************************************************************************
RPL
26162   LABEL GetNextToken
26162   LOCALLABEL L_26162
26162 D9D20   ::
26167 99016     DUP4UNROLL
2616C FB761     DPRADIX?
26171 E5362     FindTokEnd
26176 DA162     GetNextSub
2617B 26162     GetNextToken
26180 DA916     NOTcase
26185 FD550     NULL$
2618A D7C26     ROT2DUP
2618F 40926     SWP1+
26194 4C016     5UNROLL
26199 4C016     5UNROLL
2619E CAF06     UNROT
261A3 33750     SUB$
261A8 B2130   ;
*******************************************************************************
ASSEMBLE
261AD   =GetNextSub    ( Unsupported )
261AD   L_261AD
261AD 2B162   CON(5)  (*)+5
261B2 143     A=DAT1  A
261B5 340CA30 LC(5)   =FALSE
261BC 8A2     ?A=C    A
261BF 56      GOYES   L_26224
261C1 174     D1=D1+  5
261C4 147     C=DAT1  A
261C7 137     CD1EX
261CA 174     D1=D1+  5
261CD 143     A=DAT1  A
261D0 135     D1=C
261D3 179     D1=D1+  10
261D6 147     C=DAT1  A
261D9 137     CD1EX
261DC 06      RSTK=C
261DE 174     D1=D1+  5
261E1 147     C=DAT1  A
261E4 137     CD1EX
261E7 1C4     D1=D1-  5
261EA 07      C=RSTK
261EC 137     CD1EX
261EF C4      A=A+A    A
261F1 8BE     ?C<=A   A
261F4 D2      GOYES   L_26221
261F6 15B9    A=DAT1  10
261FA 174     D1=D1+  5
261FD 1599    DAT1=A  10
26201 1C4     D1=D1-  5
26204 1CE     D1=D1-  15
26207 15BE    A=DAT1  15
2620B 174     D1=D1+  5
2620E 159E    DAT1=A  15
26212 E7      D=D+1    A
26214 34D4170 LC(5)   =SKIP
2621B   L_2621B
2621B DA      A=C     A
2621D 808C    PC=(A)
26221   L_26221
26221 1CE     D1=D1-  15
26224   L_26224
26224 34F2262 LC(5)   =?FillNext
2622B 6FEF    GOTO    L_2621B
*******************************************************************************
RPL
2622F   LABEL ?FillNext    ( Unsupported )
2622F   LOCALLABEL L_2622F
2622F D9D20   ::
26234 79E60     '
26239 E7832     IOLAM
2623E 34970     @LAM
26243 DA916     NOTcase
26248 39262     Back&Skip
2624D DA916     NOTcase
26252 39262     Back&Skip
26257 46BF2     FillRecv
2625C 39916     case
26261 BB262     FillNext
26266 0CA30     FALSE
2626B 6B936     FALSE'
26270 E7832     IOLAM
26275 B1D70     STOLAM
2627A 98262     ##CFF
2627F A3836     ERROROUT
26284 B2130   ;
*******************************************************************************
26289   LABEL ##CFF    ( Unsupported )
26289   LOCALLABEL L_26289
26289 11920FF   # CFF
      C00
*******************************************************************************
26293   LABEL Back&Skip    ( Unsupported )
26293   LOCALLABEL L_26293
26293 D9D20   ::
26298 88130     DUP
2629D B2040     SIX
262A2 12040     FIVE
262A7 3C070     RPITE
262AC 98F26     ROLLDROP
262B1 2B336     COLASKIP
262B6 B2130   ;
*******************************************************************************
262BB   LABEL FillNext    ( Unsupported )
262BB   LOCALLABEL L_262BB
262BB D9D20   ::
262C0 39916     case
262C5 10362     Join&Cola
262CA 6B936     FALSE'
262CF E7832     IOLAM
262D4 B1D70     STOLAM
262D9 39916     case
262DE 39262     Back&Skip
262E3 0CA30     FALSE
262E8 0CA30     FALSE
262ED 18A30     TRUE
262F2 98262     ##CFF
262F7 A3836     ERROROUT
262FC B2130   ;
*******************************************************************************
26301   LABEL Join&Cola    ( Unsupported )
26301   LOCALLABEL L_26301
26301 D9D20   ::
26306 32230     SWAP
2630B 8DA16     ITE
26310 A2116     UNROT2DROP
26315 B9F06     SWAPDROP
2631A 32230     SWAP
2631F BBF06     4ROLL
26324 22650     OVERLEN$
26329 33750     SUB$
2632E FE226     SWAP&$
26333 9FF30     ONE
26338 D6926     COLACOLA
2633D B2130   ;
*******************************************************************************
* Pops stk1 flag to ST 2
*******************************************************************************
ASSEMBLE
26342   =popflag->2    ( Unsupported )
26342 852     ST=1    2
26345 143     A=DAT1  A
26348 174     D1=D1+  5
2634B E7      D=D+1    A
2634D 3418A30 LC(5)   =TRUE
26354 8A2     ?A=C    A
26357 00      RTNYES
26359 842     ST=0    2
2635C 03      RTNCC
*******************************************************************************
2635E   =FindTokEnd    ( Unsupported )
2635E   L_2635E
2635E 36362   CON(5)  (*)+5
26363 7BDF    GOSUB   =popflag->2
26367 853     ST=1    3
2636A 143     A=DAT1  A
2636D 174     D1=D1+  5
26370 E7      D=D+1    A
26372 8FB9760 GOSBVL  =SAVPTR
26379 130     D0=A
2637C 164     D0=D0+  5
2637F 142     A=DAT0  A
26382 D8      B=A     A
26384 143     A=DAT1  A
26387 174     D1=D1+  5
2638A 132     AD0EX
2638D 164     D0=D0+  5
26390 143     A=DAT1  A
26393 133     AD1EX
26396 179     D1=D1+  10
26399 D4      A=B     A
2639B C4      A=A+A    A
2639D 560     GONC    L_263A4
263A0   L_263A0
263A0 6490    GOTO    L_26435
263A4   L_263A4
263A4 3430000 LC(5)   3
263AB CA      A=A+C    A
263AD 42F     GOC     L_263A0
263B0 146     C=DAT0  A
263B3 E2      C=C-A    A
263B5 4AE     GOC     L_263A0
263B8 D7      D=C     A
263BA 136     CD0EX
263BD C2      C=C+A    A
263BF 40E     GOC     L_263A0
263C2 134     D0=C
263C5 137     CD1EX
263C8 D0      A=0     A
263CA 540     GONC    L_263CF
263CD   L_263CD
263CD E5      B=B+1    A
263CF   L_263CF
263CF 8AB     ?D=0    A
263D2 36      GOYES   L_26435
263D4 14A     A=DAT0  B
263D7 135     D1=C
263DA C2      C=C+A    A
263DC 137     CD1EX
263DF 1574    C=DAT1  S
263E3 8E3510  GOSUBL  L_2653C
263E9 161     D0=D0+  2
263EC CF      D=D-1    A
263EE CF      D=D-1    A
263F0 94A     ?C=0    S
263F3 AD      GOYES   L_263CD
263F5 8AB     ?D=0    A
263F8 65      GOYES   L_2644E
263FA 80DF    P=C     15
263FE 893     ?P=     3
26401 D4      GOYES   L_2644E
26403 894     ?P=     4
26406 84      GOYES   L_2644E
26408 895     ?P=     5
2640B 34      GOYES   L_2644E
2640D 897     ?P=     7
26410 95      GOYES   L_26469
26412 DD      BCEX    A
26414 108     R0=C
26417 DD      BCEX    A
26419 896     ?P=     6
2641C 60      GOYES   L_26422
2641E 6890    GOTO    L_264B7
26422   L_26422
26422 AC2     C=0     S
26425 B46     C=C+1   S
26428 CF      D=D-1    A
2642A CF      D=D-1    A
2642C 161     D0=D0+  2
2642F E5      B=B+1    A
26431 6580    GOTO    L_264B7
26435   L_26435
26435 D4      A=B     A
26437 100     R0=A
2643A 8F73560 GOSBVL  =PUSH#
26441 340CA30 LC(5)   =FALSE
26448 DA      A=C     A
2644A 808C    PC=(A)
2644E   L_2644E
2644E 20      P=      0
26450 D4      A=B     A
26452 100     R0=A
26455 8F73560 GOSBVL  =PUSH#
2645C 345C562 LC(5)   =DUPTRUE
26463 DA      A=C     A
26465 808C    PC=(A)
26469   L_26469
26469 20      P=      0
2646B D4      A=B     A
2646D 100     R0=A
*******************************************************************************
26470   =PUSH#+1TLoop    ( Unsupported )
26470 8F73560 GOSBVL  =PUSH#
26477 349D562 LC(5)   =#1+TRUE
2647E DA      A=C     A
26480 808C    PC=(A)
26484   L_26484
26484 20      P=      0
26486 D4      A=B     A
26488 101     R1=A
2648B 8F73560 GOSBVL  =PUSH#
26492 8FB9760 GOSBVL  =SAVPTR
26499 111     A=R1
2649C 100     R0=A
2649F 8F73560 GOSBVL  =PUSH#
264A6 3418A30 LC(5)   =TRUE
264AD DA      A=C     A
264AF 808C    PC=(A)
264B3   L_264B3
264B3 20      P=      0
264B5   L_264B5
264B5 E5      B=B+1    A
264B7   L_264B7
264B7 8AB     ?D=0    A
264BA AC      GOYES   L_26484
264BC 14A     A=DAT0  B
264BF 135     D1=C
264C2 C2      C=C+A    A
264C4 137     CD1EX
264C7 1534    A=DAT1  S
264CB ACE     ACEX    S
264CE 8EB800  GOSUBL  L_2655F
264D4 ACE     ACEX    S
264D7 CF      D=D-1    A
264D9 CF      D=D-1    A
264DB 161     D0=D0+  2
264DE 942     ?A=C    S
264E1 4D      GOYES   L_264B5
264E3 80DF    P=C     15
264E7 892     ?P=     2
264EA B0      GOYES   L_264F5
264EC 891     ?P=     1
264EF 91      GOYES   L_26508
264F1 629F    GOTO    L_26484
264F5   L_264F5
264F5 ACE     ACEX    S
264F8 80DF    P=C     15
264FC ACE     ACEX    S
264FF 89F     ?P=     15
26502 62      GOYES   L_26528
26504 6F7F    GOTO    L_26484
26508   L_26508
26508 ACE     ACEX    S
2650B 80DF    P=C     15
2650F ACE     ACEX    S
26512 892     ?P=     2
26515 E9      GOYES   L_264B3
26517 89F     ?P=     15
2651A 99      GOYES   L_264B3
2651C 886     ?P#     6
2651F 50      GOYES   L_26524
26521 560     GONC    L_26528
26524   L_26524
26524 6F5F    GOTO    L_26484
26528   L_26528
26528 20      P=      0
2652A 8AB     ?D=0    A
2652D B0      GOYES   L_26538
2652F CF      D=D-1    A
26531 CF      D=D-1    A
26533 161     D0=D0+  2
26536 E5      B=B+1    A
26538   L_26538
26538 6C7F    GOTO    L_264B5
2653C   L_2653C
2653C 80FF    CPEX    15
26540 89D     ?P=     13
26543 A4      GOYES   L_2658D
26545 89E     ?P=     14
26548 24      GOYES   L_2658A
2654A 863     ?ST=0   3
2654D 53      GOYES   L_26582
2654F 89F     ?P=     15
26552 50      GOYES   L_26557
26554 5E0     GONC    L_26563
26557   L_26557
26557 21      P=      1
26559 80FF    CPEX    15
2655D 01      RTN
2655F   L_2655F
2655F 80FF    CPEX    15
26563   L_26563
26563 898     ?P=     8
26566 71      GOYES   L_2657D
26568 899     ?P=     9
2656B 33      GOYES   L_2659E
2656D 89A     ?P=     10
26570 B3      GOYES   L_265AB
26572 89B     ?P=     11
26575 34      GOYES   L_265B8
26577 80FF    CPEX    15
2657B 01      RTN
2657D   L_2657D
2657D 872     ?ST=1   2
26580 32      GOYES   L_265A3
26582   L_26582
26582 20      P=      0
26584 80FF    CPEX    15
26588 01      RTN
2658A   L_2658A
2658A 843     ST=0    3
2658D   L_2658D
2658D 863     ?ST=0   3
26590 80      GOYES   L_26598
26592 843     ST=0    3
26595 5CE     GONC    L_26582
26598   L_26598
26598 853     ST=1    3
2659B 46E     GOC     L_26582
2659E   L_2659E
2659E 872     ?ST=1   2
265A1 1E      GOYES   L_26582
265A3   L_265A3
265A3 22      P=      2
265A5 80FF    CPEX    15
265A9 01      RTN
265AB   L_265AB
265AB 872     ?ST=1   2
265AE 5F      GOYES   L_265A3
265B0   L_265B0
265B0 25      P=      5
265B2 80FF    CPEX    15
265B6 01      RTN
265B8   L_265B8
265B8 872     ?ST=1   2
265BB 5F      GOYES   L_265B0
265BD 22      P=      2
265BF 80FF    CPEX    15
265C3 01      RTN

They are used mainly in FindTokEnd and GetNextSub
Here are part of the truth (from BNF.doc) :

The ttt is a a hxs containing 256 elements, one for each char. The table
gives an implicit correspondence between ASCII characters and their TYPE,
which is one of 16 values:
0 - neutral character
1 - normal character
2 - digit
3 - left delimiter
4 - right delimiter
5 - self delimiter
6 - escape character
7 - diphthong start

[Not described in the ERS, but built-in in the HP48 GetNextToken: ]

8 - ?
9 - ?
10 - ?
11 - ?
12 - ?
13 - comment toggle
14 - comment off
15 - ?
Many thanks Han !!
The defined types are
0 - neutral character
1 - normal character
2 - digit
3 - left delimiter
4 - right delimiter
5 - self delimiter
6 - escape character
7 - diphthong start
8 - radix/separator 1
9 - radix/separator 2
10 - radix/separator 3
11 - radix/separator 4
12 - other (used in symbolics)
13 - comment toggle
14 - comment off
15 - exponent separator

HTH,
Andreas
Super, Thank you Andreas !
RPL is always more fascinating each time I discover another thing...
Reference URL's