proquint-parse.tal
A piece of uxntal code to parse a single proquint to a short. It
checks for five characters in a-z
, and each must be a
character that is valid in a proquint. Just like the reference
implementation in C, it is not sensitive to the ordering of consonants
and vowels.
@ppq-table
20 ( a ) 40 ( b ) 00 ( c ) 41 ( d ) 00 ( e ) 42 ( f ) 43 ( g ) 44 ( h )
21 ( i ) 45 ( j ) 46 ( k ) 47 ( l ) 48 ( m ) 49 ( n ) 22 ( o ) 4a ( p )
00 ( q ) 4b ( r ) 4c ( s ) 4d ( t ) 23 ( u ) 4e ( v ) 00 ( w ) 00 ( x )
00 ( y ) 4f ( z )
@ppq [ &val $2 ]
( ptr* - should point to characters terminated by one not in [a-z] )
( value* - the short decoded from the proquint )
( parse-len* - 0 upon failure, 5 if ptr* pointed to a valid proquint )
@parse-proqu ( ptr* -- value* parse-len* )
#0000 ;ppq/val STA2
DUP2 ( ptr* -- ptr* ptr-new* )
&loop1 [
SWP2k SUB2 #0005 EQU2 [ ?parse-proqu/loop1-end ]
LDAk DUP #60 GTH SWP #7b LTH AND [ ?parse-proqu/loop1-incr ]
]
[ !parse-proqu/loop1-end ]
&loop1-incr [ INC2 !parse-proqu/loop1 ] &loop1-end
SWP2 ( ptr* ptr-new* -- ptr-new* ptr* )
SUB2k #0005 EQU2 [ ?parse-proqu/fivealpha ]
POP2 POP2 ( ptr-new* ptr* -- ) [ !parse-proqu/error ]
&fivealpha
&loop2 [ EQU2k [ ?parse-proqu/loop2-end ] ]
LDAk #61 SUB #00 SWP ;ppq-table ADD2 LDA ( -- shift|incr )
DUP #0f AND SWP #f0 AND ( shift|incr -- incr shift )
DUP [ ?parse-proqu/validpchar ]
POP2 ( incr shift -- ) POP2 POP2 ( ptr-new* ptr* -- )
[ !parse-proqu/error ]
&validpchar
;ppq/val LDA2 ROT ( shift -- value* shift ) SFT2
ROT #00 SWP ADD2 ( incr value* -- value* + incr ) ;ppq/val STA2
[ INC2 !parse-proqu/loop2 ] &loop2-end
POP2 POP2 ( ptr-new* ptr* -- )
;ppq/val LDA2 #0005 ( -- value* parse-len* )
JMP2r
&error #0000 #0000 JMP2r
created
modified