scanner.l

changeset 15
dda3d673b82b
parent 13
3ab5717225d3
child 17
d4699dfddcc0
     1.1 --- a/scanner.l	Sun Dec 30 04:16:46 2001 +0000
     1.2 +++ b/scanner.l	Sun Dec 30 04:16:46 2001 +0000
     1.3 @@ -1,25 +1,36 @@
     1.4  /*
     1.5 -$Id: scanner.l,v 1.7 2001/12/29 17:54:43 eric Exp $
     1.6 +$Id: scanner.l,v 1.8 2001/12/29 20:16:46 eric Exp $
     1.7  */
     1.8  
     1.9  %option case-insensitive
    1.10  %option noyywrap
    1.11  
    1.12  %{
    1.13 +#include <stdio.h>
    1.14  #include <string.h>
    1.15  #include "parser.tab.h"
    1.16 +#include "type.h"
    1.17 +#include "tiff2pdf.h"
    1.18 +
    1.19 +#ifdef SCANNER_DEBUG
    1.20 +#define LDBG(x) printf x
    1.21 +#else
    1.22 +#define LDBG(x)
    1.23 +#endif
    1.24  %}
    1.25  
    1.26  
    1.27  digit [0-9]
    1.28  alpha [a-zA-Z]
    1.29 +dot [\.]
    1.30  
    1.31  %%
    1.32  
    1.33 -\.\.		{ return (ELIPSIS); }
    1.34 +[\,;{}]		{ return (yytext [0]); }
    1.35 +{dot}{dot}	{ LDBG(("elipsis\n")); return (ELIPSIS); }
    1.36  
    1.37 -{digit}+	{ yylval.integer = atoi (yytext); return (INTEGER); }
    1.38 -{digit}+.{digit}* { yylval.fp = atof (yytext); return (FLOAT); }
    1.39 +{digit}+	{ yylval.integer = atoi (yytext); LDBG(("integer %d\n", yylval.integer)); return (INTEGER); }
    1.40 +{digit}+\.{digit}+ { yylval.fp = atof (yytext); return (FLOAT); }
    1.41  
    1.42  a		{ yylval.size.width = 8.5 * 25.4;
    1.43  		  yylval.size.height = 11.0 * 25.4;
    1.44 @@ -57,12 +68,21 @@
    1.45  rotate		{ return (ROTATE); }
    1.46  size		{ return (SIZE); }
    1.47  
    1.48 -\".*\"		{ yylval.string = strdup (yytext); return (STRING); }
    1.49 +\".*\"		{ 
    1.50 +                  int len = strlen (yytext) - 2;
    1.51 +                  yylval.string = malloc (len + 1);
    1.52 +                  memcpy (yylval.string, yytext + 1, len);
    1.53 +                  yylval.string [len] = '\0';
    1.54 +		  LDBG (("string \"%s\"\n", yylval.string));
    1.55 +                  return (STRING);
    1.56 +                }
    1.57  
    1.58 -[ \t\n]+	/* whitespace */
    1.59 +[ \t]+		/* whitespace */
    1.60 +\n		{ line++; }
    1.61  
    1.62  --.*		/* Ada/VHDL style one-line comment */
    1.63 +#.*		/* shell-style one-line comment */
    1.64  
    1.65 -.		{ printf( "Unrecognized character: %s\n", yytext ); }
    1.66 +.		{ fprintf (stderr, "Unrecognized character: %s\n", yytext); }
    1.67  
    1.68  %%