home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / pascal / compcomp / tpyacc / magic.l < prev    next >
Text File  |  1991-04-30  |  1KB  |  59 lines

  1.  
  2. %{
  3.  
  4. (* Lex demonstration program for the use of start states, taken from the UNIX
  5.    manual. This program copies standard input to standard output, and changes
  6.    the word `magic' to `first', `second' or `third' on any line that starts
  7.    with the letter a, b or c, respectively.
  8.  
  9.    Try it out, e.g., by issuing the command `magic' and typing in the following
  10.    lines:
  11.  
  12.      This is a magic word.
  13.      a This is a magic word.
  14.      b This is a magic word.
  15.      c This is a magic word.
  16.  
  17.    The respond should be:
  18.  
  19.      This is a magic word.
  20.      a This is a first word.
  21.      b This is a second word.
  22.      c This is a third word.
  23.  
  24.    To compile this program: lex magic
  25.                             tpc magic
  26.  
  27. *)
  28.  
  29. uses LexLib;
  30.  
  31. %}
  32.  
  33. %S AA BB CC
  34.  
  35. %%
  36.  
  37. ^a        begin
  38.           echo; start(AA);
  39.         end;
  40. ^b        begin
  41.           echo; start(BB);
  42.         end;
  43. ^c        begin
  44.           echo; start(CC);
  45.         end;
  46. \n        begin
  47.           echo; start(0);
  48.         end;
  49. <AA>magic    write('first');
  50. <BB>magic    write('second');
  51. <CC>magic    write('third');
  52. .        echo;
  53.  
  54. %%
  55.  
  56. begin
  57.   if yylex=0 then ;
  58. end.
  59.