%{
/*****************************************************************\
 * FILE: hpgl.l   part of hpgl to X windows                      *
 *                                                               *
 * Written by Randy L. Yach aid by Jackie Harrison               *
 * Some additional rules added by Andrew Gerber                  *
 * (gerber@solbourne.com) during port to X11                     *
 *  Decription:                                                  *
 *    this is the lexical analizer of HPGL syntax.  All action   *
 *    tokens are covered first.                                  *
\*****************************************************************/

#include <stdio.h>
#include "y.tab.h"

#ifdef sgi
#include <math.h>
#endif

#ifdef ULTRIX
#include <math.h>
#endif

/* need this because the sun 386i has a funny location of the atof
   definition */
#ifdef UI38
#include <floatingpoint.h>
#endif

/* need this to keep count of the input lines for error messages */
int hline = 1;
%}
D	[0-9]
R       [0-9\.]
RR      [0-9\.\-]
A	[A-Z]
LBL     [a-z\-\, \.A-Z0-9\:\;\(\)\&\^\%\$\#\@\!\"\'\~\`|?\/\<\>\_\+\-]
DOT     [\.]
COMMA   [\,]
ALT     [A-Z\(\)\@]
G       [A-Z0-9\;]
%%
LT	                        {
                                return(LT);
                                }
LB{LBL}*\n?                      {
                                /* strip off the LB and the ending ^C
                                   from the input line and return it */
			        strcpy(yylval.sb,&yytext[2]);
				yylval.sb[strlen(yylval.sb)-1] = '\0';
				return(LB);
				}
SC                              {
				return(SC);
				}
SP{D}?                          {
                                /* return the pen number */
				yylval.i = yytext[2] - '0';
				return(SP);
				}
PA              		{
				return(PA);
				}
PR              		{
				return(PR);
				}
PU              		{
				return(PU);
				}
PD              		{
				return(PD);
				}
EA              		{
				return(EA);
				}
RA              		{
				return(RA);
				}
UC                              {
                                return(EAT_TO_SEMI);
                                }
\-?{D}+                         {
                                /* integer digit routine */
				yylval.i = atoi(yytext);
				return(DIGIT);
				}
\-?{R}+                         {
                                /* real digit routine */
				yylval.f = atof(yytext);
				return(NUMBER);
				}
\;				{
				return(SEMICOLON);
                                }
\,                              {
				return(COMMA);
                                }
IN\;                            return(RESET);
DF\;                            return(RESET);
[ \t]*			        ;
[\n]                            {
                                hline++;
				}
{DOT}{ALT}({G}+\:)?             ;
C{A}{R}*({COMMA}{D}*)?\;        ;
DI{RR}*({COMMA}{RR}*)?\;        ;
DR{D}*({COMMA}{D}*)?\;          ;
DT{A}\;                         ;
DC\;                            ;
DP\;                            ;
O{A}\;                          ;
IM{D}*({COMMA}{D}*)*\;          ;
IP{D}*({COMMA}{D}*)*\;          ;
IW{D}*({COMMA}{D}*)*\;          ;
SA\;                            ;
SI{R}*{COMMA}{R}*\;             ;
SL{D}*\;                        ;
SM{A}\;                         ;
SR{R}*{COMMA}{R}*\;             ;
SS\;                            ;
SA\;                            ;
TL{R}*({COMMA}{R}+)?\;          ;
VS{D}*\;                        ;
XT\;                            ;
YT\;                            ;
RO{D}\;                         ;
PS{R}\;                         ;
.                               ;
%%
