home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / x / volume4 / xhpgl / part01 / hpgl.l < prev    next >
Encoding:
Lex Description  |  1989-07-16  |  3.2 KB  |  114 lines

  1. %{
  2. /*****************************************************************\
  3.  * FILE: hpgl.l   part of hpgl to X windows                      *
  4.  *                                                               *
  5.  * Written by Randy L. Yach aid by Jackie Harrison               *
  6.  *                                                               *
  7.  * Description:                                                  *
  8.  *    this is the lexical analizer of HPGL syntax.  All action   *
  9.  *    tokens are covered first.                                  *
  10. \*****************************************************************/
  11.  
  12. #include <stdio.h>
  13. #include "y.tab.h"
  14. #include <X/Xlib.h>
  15.  
  16. #ifdef ULTRIX
  17. #    include <math.h>
  18. #endif
  19.  
  20. /* need this because the sun 386i has a funny location of the atof
  21.    definition */
  22.  
  23. #ifdef UI38
  24. #    include <floatingpoint.h>
  25. #endif
  26.  
  27. /* need this to keep count of the input lines for error messages */
  28. int hline = 1;
  29. %}
  30. D    [0-9]
  31. R       [0-9\.]
  32. A    [A-Z]
  33. LBL     [a-z\-\, \.A-Z0-9\:\;\(\)\&\^\%\$\#\@\!\"\'\~\`|?\/\<\>\_]
  34. DOT     [\.]
  35. COMMA   [\,]
  36. ALT     [A-Z\(\)\@]
  37. G       [A-Z0-9\;]
  38. %%
  39. LT                            {
  40.                                 return(LT);
  41.                                 }
  42. LB{LBL}*\                     {
  43.                                 /* strip off the LB and the ending ^C
  44.                                    from the input line and return it */
  45.                     strcpy(yylval.sb,&yytext[2]);
  46.                 yylval.sb[strlen(yylval.sb)-1] = '\0';
  47.                 return(LB);
  48.                 }
  49. SC                              {
  50.                 return(SC);
  51.                 }
  52. SP{D}                           {
  53.                                 /* return the pen number */
  54.                 yylval.i = yytext[2] - '0';
  55.                 return(SP);
  56.                 }
  57. PA                      {
  58.                 return(PA);
  59.                 }
  60. PR                      {
  61.                 return(PR);
  62.                 }
  63. PU                      {
  64.                 return(PU);
  65.                 }
  66. PD                      {
  67.                 return(PD);
  68.                 }
  69. \-?{D}+                         {
  70.                                 /* integer digit routine */
  71.                 yylval.i = atoi(yytext);
  72.                 return(DIGIT);
  73.                 }
  74. \-?{R}+                         {
  75.                                 /* real digit routine */
  76.                 yylval.f = atof(yytext);
  77.                 return(NUMBER);
  78.                 }
  79. \;                {
  80.                 return(SEMICOLON);
  81.                                 }
  82. \,                              {
  83.                 return(COMMA);
  84.                                 }
  85. IN\;                            return(RESET);
  86. DF\;                            return(RESET);
  87. [ \t]*                    ;
  88. [\n]                            {
  89.                                 hline++;
  90.                 }
  91. \{DOT}{ALT}({G}+\:)?          ;
  92. C{A}{D}*({COMMA}{D}*)?\;        ;
  93. DI{D}*({COMMA}{D}*)?\;          ;
  94. DR{D}*({COMMA}{D}*)?\;          ;
  95. DT{A}\;                         ;
  96. DC\;                            ;
  97. DP\;                            ;
  98. O{A}\;                          ;
  99. IM{D}*({COMMA}{D}*)*\;          ;
  100. IP{D}*({COMMA}{D}*)*\;          ;
  101. IW{D}*({COMMA}{D}*)*\;          ;
  102. SA\;                            ;
  103. SI{D}*{COMMA}{D}*\;             ;
  104. SL{D}*\;                        ;
  105. SM{A}\;                         ;
  106. SR{R}*{COMMA}{R}*\;             ;
  107. SS\;                            ;
  108. SA\;                            ;
  109. TL{D}*({COMMA}{D}+)?\;          ;
  110. VS{D}*\;                        ;
  111. XT\;                            ;
  112. YT\;                            ;
  113. %%
  114.