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