home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-385-Vol-1of3.iso / x / xcu16.zip / wlmCompiler / wlc.l < prev    next >
Text File  |  1991-10-03  |  4KB  |  193 lines

  1. %{
  2.  
  3. /*
  4.  * Copyright 1991 Cornell University
  5.  *
  6.  * Permission to use, copy, modify, and distribute this software and its
  7.  * documentation for any purpose and without fee is hereby granted, provided
  8.  * that the above copyright notice appear in all copies and that both that
  9.  * copyright notice and this permission notice appear in supporting
  10.  * documentation, and that the name of Cornell U. not be used in advertising
  11.  * or publicity pertaining to distribution of the software without specific,
  12.  * written prior permission.  Cornell U. makes no representations about the
  13.  * suitability of this software for any purpose.  It is provided "as is"
  14.  * without express or implied warranty.
  15.  *
  16.  * CORNELL UNIVERSITY DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  17.  * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
  18.  * EVENT SHALL CORNELL UNIVERSITY BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  19.  * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
  20.  * USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
  21.  * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  22.  * PERFORMANCE OF THIS SOFTWARE.
  23.  *
  24.  * Author:  Gene W. Dykes, Program of Computer Graphics
  25.  *          580 Theory Center, Cornell University, Ithaca, NY 14853
  26.  *          (607) 255-6713   gwd@graphics.cornell.edu
  27.  */
  28.  
  29. #define ManageContext 1
  30. #define DirectiveContext 2
  31. static int oops_context ;
  32.  
  33. static    void convert_nl () ;
  34. static    void convert_numeric () ;
  35.  
  36. static Boolean    first_time = True ; /* recognizes the first time for yylex()*/
  37. static Boolean    nested_args = False ; 
  38.  
  39. static char *ttt ;
  40.  
  41. #undef input
  42. #undef unput
  43. #define YYLMAX 1000
  44. %}
  45.  
  46. %START    string
  47.  
  48. %%
  49.  
  50. "/*"  /* look for start of comment */
  51.     {
  52.     char c ;
  53.     for (;;)
  54.     {
  55.     while ((c = input()) != '*')
  56.         ;
  57.     if ((c = input()) == '/')
  58.         break ;
  59.     unput (c) ;
  60.     }
  61.     }
  62.  
  63. ["]["]  /* look for start of string */
  64.     {
  65.     Cu_copy_ds (&ttt, "") ;
  66.     yylval.s_val = ttt ;
  67.     return STRING ;
  68.     }
  69.  
  70. ["]  /* look for start of string */
  71.     {
  72.     BEGIN string ;
  73.     }
  74.  
  75. <string>[^"]*\"  /* anything but another quote */
  76.     {
  77.     yytext[yyleng-1] = '\0' ; /* trash the trailing quote */
  78.     Cu_copy_ds (&ttt, yytext) ;
  79.     convert_nl (ttt) ;    /* convert '\' 'n' to '\n' and remove '\' '\n' */
  80.     convert_numeric (ttt) ;/* convert '\xxx' to number */
  81.     yylval.s_val = ttt ;
  82.  
  83.     BEGIN 0 ;
  84.     return STRING ;
  85.     }
  86.  
  87. if        /* if keyword */
  88.     {
  89.     return IF_KEY ;
  90.     }
  91.  
  92. XtSetValues    /* set_values keyword */
  93.     {
  94.     return SET_VALUES_KEY ;
  95.     }
  96.  
  97. \#include|include        /* include keyword */
  98.     {
  99.     return INCL_KEY ;
  100.     }
  101.  
  102. manage        /* manage keyword */
  103.     {
  104.     return MANAGE_KEY ;
  105.     }
  106.  
  107. [^ \t\n\{\}\:\(\)\[\]\"\,\=\&\!\<\>\*]*    /* item (anything but punctuation) */
  108.     {
  109.     Cu_copy_ds (&ttt, yytext) ;
  110.     yylval.s_val = ttt ;
  111.     return WORD ;
  112.     }
  113.  
  114. [\{\}\<\>\(\)\[\]\:\,\=\&\!\*]                /* punctuation */
  115.     {
  116.     return (yytext[0]) ;
  117.     }
  118.  
  119. [ \n\t]        /* white space    */
  120.     {
  121.     ;
  122.     }
  123.  
  124. .    {
  125.     sprintf (error_text, "LEX returning ERROR on char (%c)\n", *yytext) ;
  126.     XtWarning (error_text) ;
  127.     return ERROR ;
  128.     }
  129. %%
  130.  
  131. static void
  132. convert_nl (text)
  133.     char *text ;
  134. {
  135. Cardinal i ;
  136. for (i=0;  i < strlen (text);  i++)
  137.     {
  138.     if (text[i] == '\\' && text[i+1] == 'n')
  139.         {
  140.         Cardinal j ;
  141.         text[i] = '\n' ;
  142.         j = i+1 ;
  143.         while (text[j] != 0)
  144.             {
  145.             text[j] = text[j+1] ;
  146.             j++ ;
  147.             }
  148.         }
  149.     else
  150.     if (text[i] == '\\' && text[i+1] == '\n')
  151.         {
  152.         Cardinal j = i ;
  153.         while (1)
  154.             {
  155.             text[j] = text[j+2] ;
  156.             if (text[j] == '\0')
  157.                 break ;
  158.             j++ ;
  159.             }
  160.         }
  161.     }
  162. return ;
  163. }
  164.  
  165. static void
  166. convert_numeric (text)
  167.     char *text ;
  168. {
  169. Cardinal i ;
  170. for (i=0;  i < strlen (text);  i++)
  171.     {
  172.     if (text[i] == '\\' &&  isdigit(text[i+1]) &&
  173.                 isdigit(text[i+2]) &&
  174.                 isdigit(text[i+3]))
  175.         {
  176.         Cardinal j = i+1 ;
  177.         int ival ;
  178.         char save = text[i+4] ;
  179.         text[i+4] = '\0' ;
  180.         sscanf (&text[j], "%o", &ival) ;
  181.         text[i] = ival ;
  182.         text[i+4] = save ;
  183.         do
  184.             {
  185.             text[j] = text[j+3] ;
  186.             }
  187.             while (text[j++] != '\0') ;
  188.         }
  189.     }
  190. return ;
  191. }
  192.  
  193.