scanner.l

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