home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #31 / NN_1992_31.iso / spool / comp / os / coherent / 6488 < prev    next >
Encoding:
Text File  |  1992-12-28  |  4.0 KB  |  137 lines

  1. Path: sparky!uunet!cs.utexas.edu!zaphod.mps.ohio-state.edu!pacific.mps.ohio-state.edu!linac!att!cbnewsm!cbnewsl!att-out!rutgers!micro-heart-of-gold.mit.edu!uw-beaver!uw-coco!mdisea!mdivax1!van-bc!rwsys!root
  2. From: root@rwsys.wimsey.bc.ca (Superuser)
  3. Newsgroups: comp.os.coherent
  4. Subject: Re: Working lex for v4.0?
  5. Message-ID: <9212243066@rwsys.wimsey.bc.ca>
  6. Date: 28 Dec 92 20:53:26 GMT
  7. References: <1992Dec20.120530.16635@iitmax.iit.edu>
  8. Organization: RWSYS Exporter BBS system
  9. Lines: 126
  10.  
  11. pred@iitmax.iit.edu (Predrag S. Bundalo) writes:
  12. > Randy Wright's port of flex is even worse (flex is bad, not the port): it
  13. > creates an ever-growing lex.yy.c file.  Sheesh.
  14. [I deleted the lex code for bandwidth..] 
  15. > Regards,
  16. > Pred Bundalo
  17. > -- 
  18. > :::  Predrag S. Bundalo                  Academic Computing Center
  19. > :::  Illinois Institute of Technology    Chicago, Illinois
  20. > .....................................................................
  21. > :::  Internet:  pred@{iitmax, elof}.iit.edu, syspredrag@minna.iit.edu
  22. > :::  BITNET  :  syspredrag@iitvax.BITNET
  23. Pred, I tried your code. Indeed flex produced >1 megabyte before a stopped
  24. it. It must have the double-per-cent-sign at the end of the spec (%%) or
  25. flex will copy infinitely what ever is actually there ( end of file ). I
  26. think this is a flex bug. At any rate, if you install the "%%", it will
  27. flex up ok.
  28.  
  29. I took the liberty of creating a piece of test data and running your
  30. specification on it. I added a main(), but you don not have to have
  31. a main(), just the %%. I put this spec in a file called spec.l and 
  32. then my input data in a file called test.data. Then I did this:
  33.  
  34. flex spec.l
  35.  
  36. cc lex.yy.c -o hdr
  37.  
  38. hdr test.data >output
  39.  
  40. here's the revised files:
  41. ============file: spec.l===============================
  42. %S REPLY FROM SUBJECT QUIT GET BINARY ASCII HELP CONNECT
  43. %%
  44. <FROM>[^\n]+    printf("FROM: %s\n",yytext);
  45. <FROM>\n    BEGIN 0;
  46. From:" "    BEGIN FROM;
  47.  
  48. <SUBJECT>[^\n]+    printf("SUBJECT: %s\n",yytext);
  49. <SUBJECT>\n    BEGIN 0;
  50. Subject:" "    BEGIN SUBJECT;
  51.  
  52. <REPLY>[^\n]+    printf("REPLY: %s\n",yytext);
  53. <REPLY>\n    BEGIN 0;
  54. [rR][eE][pP][lL][yY]" "    BEGIN REPLY;
  55.  
  56. <QUIT>[^\n]+    printf("QUIT\n");
  57. <QUIT>\n    BEGIN 0;
  58. [qQ][uU][iI][tT]    BEGIN QUIT;
  59.  
  60. <HELP>[^\n]+    printf("HELP\n");
  61. <HELP>\n    BEGIN 0;
  62. [hH][Ee][lL][pP]    BEGIN HELP;
  63.  
  64. <GET>[^\n]+    printf("GET: %s\n",yytext);
  65. <GET>\n    BEGIN 0;
  66. [gG][eE][tT]" "    BEGIN GET;
  67.  
  68. <BINARY>[^\n]+    printf("BINARY\n");
  69. <BINARY>\n    BEGIN 0;
  70. [bB][iI][nN][aA][rR][yY]    BEGIN BINARY;
  71.  
  72. <ASCII>[^\n]+    printf("ASCII\n");
  73. <ASCII>\n    BEGIN 0;
  74. [aA][sS][cC][iI][iI]    BEGIN ASCII;
  75.  
  76. <CONNECT>[^\n]+    printf("CONNECT: %s\n",yytext);
  77. <CONNECT>\n    BEGIN 0;
  78. [cC][oO][nN][nN][Ee][cC][tT]" "    BEGIN CONNECT;
  79. %%
  80. /* these two %'s must be there or flex will loose it's mind */
  81.  
  82. main( argc, argv )
  83. int argc;
  84. char **argv;
  85. {
  86. FILE *infile;
  87.  
  88.     /* should check argc too */
  89. if( (infile = fopen( argv[1], "r" )) == NULL )
  90.     {
  91.     printf( "can't open %s\n", argv[1] );
  92.     exit( 1 );
  93.     }
  94.  
  95. yyin = infile;
  96.  
  97. yylex();
  98.  
  99. }
  100.  
  101. ===== here's the input I fed to the above spec.  file: test.data ======
  102. From: root@rwsys.wimsey.bc.ca (Randy Wright)
  103. Subject: flex stuff.. 
  104. reply root@rwsys.wimsey.bc.ca
  105. quit  
  106. help  
  107. get ./pub/myfile.txt
  108. Binary  
  109. Ascii  
  110. Connect 256.256.256.256
  111.  
  112. ====== here's the output from the above input. file: output ============
  113. FROM: root@rwsys.wimsey.bc.ca (Randy Wright)
  114. SUBJECT: flex stuff.. 
  115. REPLY: root@rwsys.wimsey.bc.ca
  116. QUIT
  117. HELP
  118. GET: ./pub/myfile.txt
  119. BINARY
  120. ASCII
  121. CONNECT: 256.256.256.256
  122. ==================
  123. I think this is probably what you are trying to achieve. BTW, very 
  124. interesting code. Looks useful for parsing ftpmail commands and other
  125. network stuff.
  126.  
  127. Randy Wright
  128.  
  129. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  130. root@rwsys.wimsey.bc.ca (Randy Wright)      | Exporter BBS     2400 bps
  131.                 or                          | (604) 581-0518     8N1
  132.     Randy_Wright@Mindlink.bc.ca             | uucp         ogin: uguest
  133.                                             | interactive login: guest
  134. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  135.