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