Liste des Groupes | Revenir à cl forth |
Hi,
here is another way, which was fun:
\
https://www.novabbs.com/devel/article-flat.php?id=28040&group=comp.lang.forth#28040
VOCABULARY timestamps-parser ALSO timestamps-parser DEFINITIONS
\ Idea: parse backward
VARIABLE a VARIABLE n
: >an n ! a ! ; : /an 0 a ! 0 n ! ;
: ch ( -- c ) a @ n @ + 1- C@ ;
: more? ( -- t/f ) n @ 0<> ;
: ch+ ( -- ) more? NOT ABORT" exceeded string" -1 n +! ;
: colon ( -- ) more? IF ch ':' <> ABORT" Expected colon!" ch+ THEN ;
: d? ( c -- t/f ) '0' '9' 1+ WITHIN ;
: digit? ( c -- t/f ) d? NOT ABORT" Expected a digit!" ;
: d ( -- ) ch digit? ch 48 - ch+ ;
: [d] ( -- n ) ch d? IF ch 48 - ch+ ELSE 0 THEN ;
: hr ( -- n ) [d] [d] 10 * + ; : min ( -- n ) [d] [d] 10 * + ; : sec (
-- n ) d [d] 10 * + ;
: parse ( a n -- s m h ) >an sec colon min colon hr /an ;
...
Les messages affichés proviennent d'usenet.