home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #31 / NN_1992_31.iso / spool / vmsnet / tpu / 557 < prev    next >
Encoding:
Text File  |  1992-12-30  |  3.7 KB  |  91 lines

  1. Newsgroups: vmsnet.tpu
  2. Path: sparky!uunet!zaphod.mps.ohio-state.edu!pacific.mps.ohio-state.edu!linac!unixhub!slacvx.slac.stanford.edu!fairfield
  3. From: fairfield@slacvx.slac.stanford.edu
  4. Subject: Re: Pattern
  5. Message-ID: <1992Dec30.153721.1@slacvx.slac.stanford.edu>
  6. Lines: 79
  7. Sender: news@unixhub.SLAC.Stanford.EDU
  8. Organization: Stanford Linear Accelerator Center
  9. References: <1hsqeoINNmqe@usenet.INS.CWRU.Edu>
  10. Date: Wed, 30 Dec 1992 23:37:21 GMT
  11.  
  12. In article <1hsqeoINNmqe@usenet.INS.CWRU.Edu>, at913@cleveland.Freenet.Edu (Mirko Vukovic) writes:
  13. > I am converting a fortran code from single to double precision on a VAX.  
  14. > I a TPU routine that searches for constants in the program by using the
  15. > following patterns
  16. >
  17. >         aaaa.bbbbbX
  18. >             .bbbbbX
  19. >         aaaa.X
  20. >
  21. >         aaaa any number of digits
  22. >         bbbb any number of digits
  23. >         X any character except d,D
  24. >
  25. > and puts the cursor on the end of a line where the pattern was found.
  26. >
  27. > I came up with the following patterns:
  28. >
  29. > predig:=span('0123456789');            <--- for aaaa
  30. > posdig:=anchor&span('0123456789');        <--- for bbbb
  31. > per:='.';                    <--- for .
  32. > exp:=anchor&(notany('dD')|line_end);        <--- for X
  33. >
  34. > find :=((predig&per&exp)|(per&posdig&exp)|(predig&per&posdig&exp));
  35. >
  36. > However the above does detect numbers like 123.12D00, ie if I have more than
  37. > one digit after the period followed by D.
  38. >                         
  39. > Is that because in posdig anchor forces the span to match only one character?
  40.  
  41.     No, it's because the first "alternation" in the pattern "find", that is,
  42. "predig&pre&exp" matches the "123.1" in "123.12D00" (the NOTANY('dD') matches
  43. the "1" following the period, see below).  Remember, the order of the alternate 
  44. subpatterns is important.  
  45.  
  46.     Also, I would modify your pattern variables to use concatenation "+" 
  47. rather than linkage "&" (see Section 2.7.3.2, p.2-15, in the VAXTPU manual).
  48. This will remove the need for ANCHOR and make it clear (to yourself) what
  49. you're searching for.  For example:
  50.  
  51.         digits := span('0123456789');
  52.         exp    := notany('dD01234567879') + 
  53.             (span('01234567879') + line_end | line_end);
  54.     patt1  := digits + '.' + digits + exp;
  55.     patt2  :=          '.' + digits + exp;
  56.     patt3  := digits + '.' + exp;
  57.     find   := ( patt1 | patt2, | patt3);
  58.  
  59. A final remark on this pattern: I would think it would be better to use
  60. an ANY('eE') in the "exp" pattern (aren't "E" and "D" the only allowed
  61. exponent characters in VAX Fortran?).  My "extension" to the exp pattern
  62. above won't prevent you from matching any arbitrary other character.
  63. Also, do you really need to match the line_end condition?  If you do, fine,
  64. but you'd better be sure the files you're editing don't have any trailing
  65. tabs or spaces...
  66.  
  67. > Also, how do I put a cursor on the end of a range?
  68.  
  69.     SEARCH returns a range, so just POSITION (END_OF (range)).  For example,
  70. in testing it's nice to see exactly what range SEARCH returned.  You could
  71. do something like this:
  72.  
  73.     r1 := Search_Quietly (find, FORWARD);
  74.     If r1 <> 0 Then
  75.         Position (End_Of (r1));
  76.         r2 := Create_Range (Beginning_Of (r1), Mark (NONE), REVERSE);
  77.         Update (CURRENT_WINDOW);    ! <- not necessary, but could be useful
  78.     Endif;
  79.  
  80. An earlier remark above implies you'd like to leave the cursor at the end of
  81. the line.  In that case, after the Position (r1), or whatever, just do
  82. a Position (LINE_END).
  83.  
  84.         Cheers, Ken
  85. --
  86.  Dr. Kenneth H. Fairfield    |  Internet: Fairfield@Slac.Stanford.Edu
  87.  SLAC, P.O.Box 4349, MS 98   |  DECnet:   45537::FAIRFIELD (45537=SLACVX)
  88.  Stanford, CA   94309        |  BITNET    Fairfield@Slacvx
  89.  ----------------------------------------------------------------------------
  90.  These opinions are mine, not SLAC's, Stanford's, nor the DOE's...
  91.