scanner.l

Fri, 21 Feb 2003 08:49:11 +0000

author
eric
date
Fri, 21 Feb 2003 08:49:11 +0000
changeset 63
6eddf63aa517
parent 48
3d0be1c1c1b2
child 125
e2ef1c2f9eca
permissions
-rw-r--r--

GPL.

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