scanner.l

Mon, 26 Aug 2002 06:03:55 +0000

author
eric
date
Mon, 26 Aug 2002 06:03:55 +0000
changeset 48
3d0be1c1c1b2
parent 34
8d7bd2fa5db6
child 63
6eddf63aa517
permissions
-rw-r--r--

now use C99 stdint.h and stdbool.h

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