PATTERNS(2) Icon Program Library PATTERNS(2) NNNNAAAAMMMMEEEE patterns - SNOBOL4-style pattern matching DDDDEEEESSSSCCCCRRRRIIIIPPPPTTTTIIIIOOOONNNN These procedures are adapted from TR 80-25 and TR 81-6. They provide procedural equivalents for most SNOBOL4 patterns and some extensions. SSSSYYYYNNNNOOOOPPPPSSSSIIIISSSS AAAAnnnncccchhhhoooorrrr(((()))) &&&&AAAANNNNCCCCHHHHOOOORRRR ==== 1111 if MMMMooooddddeeee ::::==== AAAAnnnncccchhhhoooorrrr AAAAnnnnyyyy((((ssss)))) AAAANNNNYYYY((((SSSS)))) AAAAppppppppllllyyyy((((ssss,,,,pppp)))) SSSS ???? PPPP AAAArrrrbbbb(((()))) AAAARRRRBBBB AAAArrrrbbbbnnnnoooo((((pppp)))) AAAARRRRBBBBNNNNOOOO((((PPPP)))) AAAArrrrbbbbxxxx((((iiii)))) AAAARRRRBBBB((((IIII)))) BBBBaaaallll(((()))) BBBBAAAALLLL BBBBrrrreeeeaaaakkkk((((ssss)))) BBBBRRRREEEEAAAAKKKK((((SSSS)))) BBBBrrrreeeeaaaakkkkxxxx((((ssss)))) BBBBRRRREEEEAAAAKKKKXXXX((((SSSS)))) CCCCaaaatttt((((pppp1111,,,,pppp2222)))) PPPP1111 PPPP2222 DDDDiiiissssccccaaaarrrrdddd((((pppp)))) ////PPPP EEEExxxxoooogggg((((ssss)))) \\\\SSSS FFFFiiiinnnndddd((((ssss)))) FFFFIIIINNNNDDDD((((SSSS)))) FFFFllllooooaaaatttt(((()))) &&&&AAAANNNNCCCCHHHHOOOORRRR ==== 0000 if MMMMooooddddeeee ::::==== FFFFllllooooaaaatttt LLLLeeeennnn((((iiii)))) LLLLEEEENNNN((((IIII)))) LLLLiiiimmmmiiiitttt((((pppp,,,,iiii)))) PPPP \\\\ iiii LLLLooooccccaaaatttteeee((((pppp)))) LLLLOOOOCCCCAAAATTTTEEEE((((PPPP)))) MMMMaaaarrrrbbbb(((()))) longest-first AAAARRRRBBBB MMMMooooddddeeee(((()))) Anchored or unanchored matching (see AAAAnnnncccchhhhoooorrrr and FFFFllllooooaaaatttt) NNNNoooottttaaaannnnyyyy((((ssss)))) NNNNOOOOTTTTAAAANNNNYYYY((((SSSS)))) PPPPoooossss((((iiii)))) PPPPOOOOSSSS((((IIII)))) RRRReeeeppppllllaaaacccceeee((((pppp,,,,ssss)))) PPPP =_=_=_=_ SSSS RRRRppppoooossss((((iiii)))) RRRRPPPPOOOOSSSS((((IIII)))) RRRRttttaaaabbbb((((iiii)))) RRRRTTTTAAAABBBB((((IIII)))) SSSSppppaaaannnn((((ssss)))) SSSSPPPPAAAANNNN((((SSSS)))) SSSSttttrrrriiiinnnngggg((((ssss)))) SSSS SSSSuuuucccccccceeeeeeeedddd(((()))) SSSSUUUUCCCCCCCCEEEEEEEEDDDD TTTTaaaabbbb((((iiii)))) TTTTAAAABBBB((((IIII)))) XXXXffffoooorrrrmmmm((((ffff,,,,pppp)))) FFFF((((PPPP)))) In addition to the procedures above, the following expres- sions can be used: pppp1111(((()))) |||| pppp2222(((()))) PPPP1111 |||| PPPP2222 vvvv <<<<---- pppp(((()))) PPPP .... VVVV (approximate) vvvv ::::==== pppp(((()))) PPPP $$$$ VVVV (approximate) ffffaaaaiiiillll FFFFAAAAIIIILLLL ====ssss SSSS (in place of SSSSttttrrrriiiinnnngggg((((ssss))))) pppp1111(((()))) |||||||| pppp2222(((()))) PPPP1111 PPPP2222 (in place of CCCCaaaatttt((((pppp1111,,,,pppp2222))))) Using this system, most SNOBOL4 patterns can be satisfac- torily transliterated into Icon procedures and expressions. Version 5.9 The University of Arizona - 7/29/84 1 PATTERNS(2) Icon Program Library PATTERNS(2) For example, the pattern SPAN("0123456789") $ N "H" LEN(*N) $ LITERAL can be transliterated into (n <- Span('0123456789')) || ="H" || (literal <- Len(n)) Concatenation of components is necessary to preserve the pattern-matching properties of SNOBOL4. See the documents listed below for details and limitations. CCCCAAAAVVVVEEEEAAAATTTTSSSS Simulating SNOBOL4 pattern matching using the procedures above is inefficient. SSSSEEEEEEEE AAAALLLLSSSSOOOO Ralph E. Griswold. _P_a_t_t_e_r_n _M_a_t_c_h_i_n_g _i_n _I_c_o_n, TR 80-25, The University of Arizona, 1980. Ralph E. Griswold. _M_o_d_e_l_s _o_f _S_t_r_i_n_g _P_a_t_t_e_r_n _M_a_t_c_h_i_n_g, TR 81-6, Department of Computer Science, The University of Arizona, 1981. Ralph E. Griswold. ``Implementing SNOBOL4 Pattern Matching in Icon'', _C_o_m_p_u_t_e_r _L_a_n_g_u_a_g_e_s, Vol. 8, No. 8 (1983), pp. 77-92. AAAAUUUUTTTTHHHHOOOORRRR Ralph E. Griswold Version 5.9 The University of Arizona - 7/29/84 2