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