#] #] ********************* #] "$d_Qtest"'symbols flatliner derivations/symExprExtract_stringPosn- develop.txt' #] to extract a list of [all, known, unkown] symbols from a text file, # with reference to a dictionary, ignoring comments and descriptions # www.BillHowell.ca 17Apr2018 initial # view this file in a text editor, with [constant width font, tab = 3 spaces], no line-wrap 24************************24 # Table of Contents : # $ grep "^#]" "$d_Qtest"'symbols flatliner derivations/symExprExtract_stringPosn- develop.txt' | sed 's/^#\]/ /' ********************* "$d_Qtest"'symbols flatliner derivations/symExprExtract_stringPosn- develop.txt' to extract a list of [all, known, unkown] symbols from a text file, 20May2018 symExprExtract_decisonTable - logic table of expressions 20May2018 symExprExtract_stringPosn - start with code from symExtract_string, but this is non-recursive! 24************************24 08********08 #] 20May2018 symExprExtract_decisonTable - logic table of expressions # (IS" included to put out with grep, actually is ":=") # flags = in_sym in_[chrs_symbols_HFLN,valid_unicode] in_paren symExprExtract_decisonTable := 2 2 2 reshape '(0 0 0) ; null ; ' '(0 0 1) ; write ''symExprExtract_stringPosn ; error with flags@2'' ; ' '(0 1 0) ; symNew := link symNew chr_new ; posnList := link posnList i ; flags@0 := 1 ; ' '(0 1 1) ; write ''symExprExtract_stringPosn ; error with flags@2'' ; ' '(1 0 0) ; symList := link symList (solitary symNew) ; symNew := null ; flags@0 := 0 ; ' '(1 0 1) ; symNew := link symNew chr_new ; ' '(1 1 0) ; symNew := link symNew chr_new ; ' '(1 1 1) ; symNew := link symNew chr_new ; ' ; 08********08 #] 20May2018 symExprExtract_stringPosn - start with code from symExtract_string, but this is non-recursive! # (doesn't list sub-component positions, which it should!) # 02Jun2018 WARNING: if symbol separated from parenthetical expression by blanks, the latter are not treated as arguments! # symExprExtract_stringPosn IS OP symExpr str - extracts [symbols,expressions] from str and lists position of each # - very handy when working with symExtrs and need positions to test operators symExprExtract_stringPosn IS OP symExpr str { LOCAL chr_code chr_code2 chr_new dim_flags flags i jump len n_paren posnList symExStr_List symParenList symList symNew ; NONLOCAL chrs_symbols_HFLN chrs_stop_paren chrs_strt_paren symExprExtract_decisonTable symExtractString_recurLevel ; symExtractString_recurLevel := symExtractString_recurLevel + 1 ; %----------write link 'symExtractString_recurLevel: ' (string symExtractString_recurLevel) ; % ; %------------ ; %stops recursive callS ; IF (isstring str) THEN % ; symNew := '' ; symList := null ; posnList := null ; dim_flags := gage shape shape symExprExtract_decisonTable ; flags := dim_flags reshape 0 ; n_paren := 0 ; len := gage shape str ; i := 0 ; % ; WHILE (i < len) DO chr_new jump := chrStr_get 1 i str ; IF (in_string chr_new chrs_blank) THEN flags@1 := 0 ; execute symExprExtract_decisonTable@(flags) ; ELSEIF (in_string chr_new chrs_symbols_HFLN) THEN flags@1 := 1 ; execute symExprExtract_decisonTable@(flags) ; ELSEIF (in str@i chrs_strt_paren) THEN flags@1 := 0 ; IF (= 1 flags@0) THEN n_paren := n_paren + 1 ; flags@2 := 1 ; ENDIF ; execute symExprExtract_decisonTable@(flags) ; ELSEIF (in str@i chrs_stop_paren) THEN flags@1 := 0 ; execute symExprExtract_decisonTable@(flags) ; IF (= 1 flags@0) THEN n_paren := n_paren - 1 ; IF (0 < n_paren) THEN flags@2 := 1 ; ELSE flags@2 := 0 ; ENDIF ; ENDIF ; ELSE % non-[chrs_blank,chrs_symbols_HFLN,chrs_[strt,stop]_paren] characters ; flags@1 := 0 ; execute symExprExtract_decisonTable@(flags) ; ENDIF ; i := i + jump + 1 ; ENDWHILE ; % ; %capture the symNew at the end of the line (if there is one) ; IF (= 1 flags@0) THEN symList := link symList (solitary symNew) ; ENDIF ; symParenList := syms_inParens symList ; symExStr_List := EACH symExtract_string symParenList ; symList := link symList (link symExStr_List) ; % ; %------------ ; %stops recursive calls ; ELSE symList := null ; %write link 'symExtractstring recurLevel null string input: ' (string symExtractString_recurLevel) ; ENDIF ; % ; chrStrGet_direction := 1 ; symList posnList } # enddoc