scanner.l

Fri, 14 Mar 2003 08:56:38 +0000

author
eric
date
Fri, 14 Mar 2003 08:56:38 +0000
changeset 132
ccf1c28a2940
parent 125
e2ef1c2f9eca
permissions
-rw-r--r--

remove debug output.

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