scanner.l

Mon, 14 Dec 2009 16:18:21 +0000

author
Philip Pemberton <philpem@philpem.me.uk>
date
Mon, 14 Dec 2009 16:18:21 +0000
changeset 172
2fae6df568f6
parent 125
e2ef1c2f9eca
permissions
-rw-r--r--

remove erroneous 0.33-philpem1 tag

     1 /*
     2  * tumble: build a PDF file from image files
     3  *
     4  * Lexical analyzer
     5  * $Id: scanner.l,v 1.18 2003/03/13 00:57:05 eric Exp $
     6  * Copyright 2001, 2002, 2003 Eric Smith <eric@brouhaha.com>
     7  *
     8  * This program is free software; you can redistribute it and/or modify
     9  * it under the terms of the GNU General Public License version 2 as
    10  * published by the Free Software Foundation.  Note that permission is
    11  * not granted to redistribute this program under the terms of any
    12  * other version of the General Public License.
    13  *
    14  * This program is distributed in the hope that it will be useful,
    15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
    16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    17  * GNU General Public License for more details.
    18  *
    19  * You should have received a copy of the GNU General Public License
    20  * along with this program; if not, write to the Free Software
    21  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA
    22 */
    24 %option case-insensitive
    25 %option noyywrap
    27 %{
    28 #include <stdbool.h>
    29 #include <stdint.h>
    30 #include <stdio.h>
    31 #include <string.h>
    32 #include "semantics.h"
    33 #include "parser.tab.h"
    35 #ifdef SCANNER_DEBUG
    36 #define LDBG(x) printf x
    37 #else
    38 #define LDBG(x)
    39 #endif
    40 %}
    43 digit [0-9]
    44 alpha [a-zA-Z]
    45 dot [\.]
    47 %%
    49 [\,;{}]		{ return (yytext [0]); }
    50 {dot}{dot}	{ LDBG(("elipsis\n")); return (ELIPSIS); }
    52   /* decimal integer */
    53 {digit}+	{ yylval.integer = atoi (yytext); LDBG(("integer %d\n", yylval.integer)); return (INTEGER); }
    55   /* floating point number - tricky to make sure it doesn't grab an integer
    56      followed by an elipsis */
    57 -?{digit}+\.{digit}+ { yylval.fp = atof (yytext); return (FLOAT); }
    58 -?{digit}+\./[^.] { yylval.fp = atof (yytext); return (FLOAT); }
    60 a		{ yylval.size.width = 8.5;
    61 		  yylval.size.height = 11.0;
    62                   return (PAGE_SIZE); }
    63 b		{ yylval.size.width = 11.0;
    64                   yylval.size.height = 17.0;
    65                   return (PAGE_SIZE); }
    66 c		{ yylval.size.width = 17.0;
    67                   yylval.size.height = 22.0;
    68                   return (PAGE_SIZE); }
    69 d		{ yylval.size.width = 22.0;
    70                   yylval.size.height = 34.0;
    71                   return (PAGE_SIZE); }
    72 e		{ yylval.size.width = 34.0;
    73                    yylval.size.height = 44.0;
    74                   return (PAGE_SIZE); }
    76 all		{ return (ALL); }
    77 author		{ return (AUTHOR); }
    78 bookmark	{ return (BOOKMARK); }
    79 cm		{ return (CM); }
    80 creator		{ return (CREATOR); }
    81 crop		{ return (CROP); }
    82 even		{ return (EVEN); }
    83 file		{ return (FILE_KEYWORD); }
    84 image		{ return (IMAGE); }
    85 images		{ return (IMAGES); }
    86 inch		{ return (INCH); }
    87 input		{ return (INPUT); }
    88 keywords	{ return (KEYWORDS); }
    89 label		{ return (LABEL); }
    90 landscape	{ return (LANDSCAPE); }
    91 odd		{ return (ODD); }
    92 output		{ return (OUTPUT); }
    93 page		{ return (PAGE); }
    94 pages		{ return (PAGES); }
    95 portrait	{ return (PORTRAIT) ; }
    96 resolution	{ return (RESOLUTION) ; }
    97 rotate		{ return (ROTATE); }
    98 size		{ return (SIZE); }
    99 subject		{ return (SUBJECT); }
   100 title		{ return (TITLE); }
   102 '[^\n']'	{
   103 		  yylval.character = yytext [1];
   104 		  return (CHARACTER);
   105 		}
   107 \"[^\n"]*\"	{
   108                   int len = strlen (yytext) - 2;
   109                   yylval.string = malloc (len + 1);
   110                   memcpy (yylval.string, yytext + 1, len);
   111                   yylval.string [len] = '\0';
   112 		  LDBG (("string \"%s\"\n", yylval.string));
   113                   return (STRING);
   114                 }
   116 [ \t]+		/* whitespace */
   117 \n		{ line++; }
   119 --.*		/* Ada/VHDL style one-line comment */
   120 #.*		/* shell-style one-line comment */
   122 .		{ fprintf (stderr, "Unrecognized character: %s\n", yytext); }
   124 %%