home *** CD-ROM | disk | FTP | other *** search
/ rtsi.com / 2014.01.www.rtsi.com.tar / www.rtsi.com / OS9 / OSK / GRAPHICS / rayshade.lzh / input_lex.l < prev    next >
Text File  |  1990-09-06  |  4KB  |  160 lines

  1. /* input_lex.l                                    */
  2. /*                                        */
  3. /* Copyright (C) 1989, Craig E. Kolb                        */
  4. /*                                        */
  5. /* This software may be freely copied, modified, and redistributed,        */
  6. /* provided that this copyright notice is preserved on all copies.        */
  7. /*                                         */
  8. /* There is no warranty or other guarantee of fitness for this software,    */
  9. /* it is provided solely "as is".  Bug reports or fixes may be sent        */
  10. /* to the author, who may or may not act on them as he desires.            */
  11. /*                                        */
  12. /* You may not include this software in a program or other software product */
  13. /* without supplying the source, or without informing the end-user that the */
  14. /* source is available for no extra charge.                    */
  15. /*                                        */
  16. /* $Id: input_lex.l,v 3.0.1.4 90/03/07 21:26:29 craig Exp $ */
  17. %{
  18. #ifdef SYSV
  19. #include <string.h>
  20. #else
  21. #include <strings.h>
  22. #endif
  23. #include "typedefs.h"
  24. #include "y.tab.h"
  25. double atof();
  26. char *strsave();
  27. %}
  28. alpha    [a-zA-Z]
  29. special    [\.\_-]
  30. digit    [0-9]
  31. exp    [Ee][-+]?{digit}+
  32. string    ({alpha}|"/")({alpha}|{digit}|{special}|"/")*
  33. %p 3000
  34. %%
  35. [ \t\n]            ;
  36. ^#            {handlehash();}
  37. "/*"            {skipcomments();}
  38. adaptive        {return(tADAPTIVE);}
  39. aperture        {return(tAPERTURE);}
  40. background        {return(tBACKGROUND);}
  41. blotch            {return(tBLOTCH);}
  42. box            {return(tBOX);}
  43. bump            {return(tBUMP);}
  44. checker            {return(tCHECKER);}
  45. cone            {return(tCONE);}
  46. contrast        {return(tCONTRAST);}
  47. cutoff            {return(tCUTOFF);}
  48. cylinder        {return(tCYL);}
  49. defend            {return(tENDDEF);}
  50. define            {return(tSTARTDEF);}
  51. directional        {return(tDIRECTIONAL);}
  52. endfile            {return(tENDFILE);}
  53. extended        {return(tEXTENDED);}
  54. eyep            {return(tEYEP);}
  55. fbm            {return(tFBM);}
  56. fbmbump            {return(tFBMBUMP);}
  57. focaldist        {return(tFOCALDIST);}
  58. fog            {return(tFOG);}
  59. fov            {return(tFOV);}
  60. gloss            {return(tGLOSS);}
  61. grid            {return(tGRID);}
  62. heightfield        {return(tHEIGHTFIELD);}
  63. jittered        {return(tJITTERED);}
  64. light            {return(tLIGHT);}
  65. list            {return(tLIST);}
  66. lookp            {return(tLOOKP);}
  67. marble            {return(tMARBLE);}
  68. maxdepth        {return(tMAXDEPTH);}
  69. mist            {return(tMIST);}
  70. object            {return(tOBJECT);}
  71. outfile            {return(tOUTFILE);}
  72. plane            {return(tPLANE);}
  73. point            {return(tPOINT);}
  74. poly            {return(tPOLY);}
  75. resolution        {return(tRESOLUTION);}
  76. rotate            {return(tROTATE);}
  77. samples            {return(tSAMPLES);}
  78. scale            {return(tSCALE);}
  79. screen            {return(tSCREEN);}
  80. sphere            {return(tSPHERE);}
  81. superq            {return(tSUPERQ);}
  82. surface            {return(tSURFACE);}
  83. texture            {return(tTEXTURE);}
  84. transform        {return(tTRANSFORM);}
  85. translate        {return(tTRANSLATE);}
  86. triangle        {return(tTRIANGLE);}
  87. up            {return(tUP);}
  88. wood            {return(tWOOD);}
  89. {string}        {yylval.c = strsave(yytext);
  90.                 return(tSTRING);}
  91. [+-]?{digit}+        {yylval.i = atoi(yytext);
  92.                 return(tINT);}
  93.  
  94. [+-]?{digit}+"."{digit}*({exp})? |
  95. [+-]?{digit}*"."{digit}+({exp})? |
  96. [+-]?{digit}+{exp}        {yylval.d = atof(yytext); return(tFLOAT);}
  97.  
  98. .            {return yytext[0];}
  99.  
  100. %%
  101. yywrap() {return(1);}
  102. /*
  103.  * Skip over comments.
  104.  */
  105. skipcomments()
  106. {
  107.     char c;
  108.  
  109.     while (1) {
  110.         while (input() != '*')
  111.             ;
  112.         if ((c = input()) == '/')
  113.             return;
  114.         unput(c);
  115.     }
  116. }
  117. /*
  118.  * Deal with ccp-produced lines of the form:
  119.  * # n "filename"
  120.  * and
  121.  * # n
  122.  * Where filename is the name of the file being processed, and n is
  123.  * the current line number in that file.
  124.  */
  125. handlehash()
  126. {
  127.     char buf[BUFSIZ];
  128.     int i;
  129.     extern int yylineno;
  130.     extern char yyfilename[];
  131.  
  132.     /*
  133.      * Read the entire line into buf.
  134.      */
  135.     for (i = 0; (buf[i] = input()) != '\n'; i++)
  136.             ;
  137.     unput(buf[i]);        /* To make sure consecutive # lines work. */
  138.     buf[i] = (char)NULL;    /* Replace newline with NULL. */
  139.  
  140.     /*
  141.      * Complain if the line was not of the form #n "filename"
  142.      */
  143.     if ((i = sscanf(buf, "%d \"%[^\"]s\"", &yylineno, yyfilename)) == 0) {
  144.         yyerror("Unknown '#' control.");
  145.         exit(1);
  146.     }
  147.     if (i == 1) {
  148. #ifdef SYSV
  149.         if (strchr(buf, '"') != (char *)0) {
  150. #else
  151.         if (index(buf, '"') != (char *)0) {
  152. #endif
  153.             /*
  154.              * Filename was "", which means stdin.
  155.              */
  156.             strcpy(yyfilename, "stdin");
  157.         }
  158.     }
  159. }
  160.