scanner.l

Wed, 02 Jan 2002 10:17:24 +0000

author
eric
date
Wed, 02 Jan 2002 10:17:24 +0000
changeset 34
8d7bd2fa5db6
parent 32
3aac131058da
child 48
3d0be1c1c1b2
permissions
-rw-r--r--

improve floating point literal handling.

     1 /*
     2 $Id: scanner.l,v 1.15 2002/01/02 02:17:24 eric Exp $
     3 */
     5 %option case-insensitive
     6 %option noyywrap
     8 %{
     9 #include <stdio.h>
    10 #include <string.h>
    11 #include "type.h"
    12 #include "semantics.h"
    13 #include "parser.tab.h"
    15 #ifdef SCANNER_DEBUG
    16 #define LDBG(x) printf x
    17 #else
    18 #define LDBG(x)
    19 #endif
    20 %}
    23 digit [0-9]
    24 alpha [a-zA-Z]
    25 dot [\.]
    27 %%
    29 [\,;{}]		{ return (yytext [0]); }
    30 {dot}{dot}	{ LDBG(("elipsis\n")); return (ELIPSIS); }
    32   /* decimal integer */
    33 {digit}+	{ yylval.integer = atoi (yytext); LDBG(("integer %d\n", yylval.integer)); return (INTEGER); }
    35   /* floating point number - tricky to make sure it doesn't grab an integer
    36      followed by an elipsis */
    37 -?{digit}+\.{digit}+ { yylval.fp = atof (yytext); return (FLOAT); }
    38 -?{digit}+\./[^.] { yylval.fp = atof (yytext); return (FLOAT); }
    40 a		{ yylval.size.width = 8.5;
    41 		  yylval.size.height = 11.0;
    42                   return (PAGE_SIZE); }
    43 b		{ yylval.size.width = 11.0;
    44                   yylval.size.height = 17.0;
    45                   return (PAGE_SIZE); }
    46 c		{ yylval.size.width = 17.0;
    47                   yylval.size.height = 22.0;
    48                   return (PAGE_SIZE); }
    49 d		{ yylval.size.width = 22.0;
    50                   yylval.size.height = 34.0;
    51                   return (PAGE_SIZE); }
    52 e		{ yylval.size.width = 34.0;
    53                    yylval.size.height = 44.0;
    54                   return (PAGE_SIZE); }
    56 all		{ return (ALL); }
    57 author		{ return (AUTHOR); }
    58 bookmark	{ return (BOOKMARK); }
    59 cm		{ return (CM); }
    60 creator		{ return (CREATOR); }
    61 crop		{ return (CROP); }
    62 even		{ return (EVEN); }
    63 file		{ return (FILE_KEYWORD); }
    64 image		{ return (IMAGE); }
    65 images		{ return (IMAGES); }
    66 inch		{ return (INCH); }
    67 input		{ return (INPUT); }
    68 keywords	{ return (KEYWORDS); }
    69 label		{ return (LABEL); }
    70 landscape	{ return (LANDSCAPE); }
    71 odd		{ return (ODD); }
    72 output		{ return (OUTPUT); }
    73 page		{ return (PAGE); }
    74 pages		{ return (PAGES); }
    75 portrait	{ return (PORTRAIT) ; }
    76 resolution	{ return (RESOLUTION) ; }
    77 rotate		{ return (ROTATE); }
    78 size		{ return (SIZE); }
    79 subject		{ return (SUBJECT); }
    80 title		{ return (TITLE); }
    82 '[^\n']'	{
    83 		  yylval.character = yytext [1];
    84 		  return (CHARACTER);
    85 		}
    87 \"[^\n"]*\"	{
    88                   int len = strlen (yytext) - 2;
    89                   yylval.string = malloc (len + 1);
    90                   memcpy (yylval.string, yytext + 1, len);
    91                   yylval.string [len] = '\0';
    92 		  LDBG (("string \"%s\"\n", yylval.string));
    93                   return (STRING);
    94                 }
    96 [ \t]+		/* whitespace */
    97 \n		{ line++; }
    99 --.*		/* Ada/VHDL style one-line comment */
   100 #.*		/* shell-style one-line comment */
   102 .		{ fprintf (stderr, "Unrecognized character: %s\n", yytext); }
   104 %%