parser.y

Mon, 26 Aug 2002 06:03:55 +0000

author
eric
date
Mon, 26 Aug 2002 06:03:55 +0000
changeset 48
3d0be1c1c1b2
parent 32
3aac131058da
child 63
6eddf63aa517
permissions
-rw-r--r--

now use C99 stdint.h and stdbool.h

eric@5 1 %{
eric@48 2 #include <stdbool.h>
eric@48 3 #include <stdint.h>
eric@11 4 #include <stdio.h>
eric@17 5 #include "semantics.h"
eric@5 6 %}
eric@5 7
eric@5 8 %union {
eric@5 9 int integer;
eric@27 10 char character;
eric@5 11 double fp;
eric@5 12 char *string;
eric@18 13 page_size_t size;
eric@18 14 range_t range;
eric@27 15 page_label_t page_label;
eric@5 16 }
eric@5 17
eric@5 18 %token <integer> INTEGER
eric@5 19 %token <fp> FLOAT
eric@5 20 %token <string> STRING
eric@27 21 %token <character> CHARACTER
eric@9 22 %token <size> PAGE_SIZE
eric@5 23
eric@7 24 %token ELIPSIS
eric@7 25
eric@9 26 %token CM
eric@9 27 %token INCH
eric@9 28
eric@5 29 %token EVEN
eric@5 30 %token ODD
eric@5 31 %token ALL
eric@5 32
eric@9 33 %token PORTRAIT
eric@9 34 %token LANDSCAPE
eric@9 35
eric@11 36 %token FILE_KEYWORD
eric@5 37 %token IMAGE
eric@9 38 %token IMAGES
eric@5 39 %token ROTATE
eric@5 40 %token CROP
eric@5 41 %token SIZE
eric@11 42 %token RESOLUTION
eric@5 43 %token INPUT
eric@5 44
eric@27 45 %token LABEL
eric@5 46 %token PAGE
eric@8 47 %token PAGES
eric@5 48 %token BOOKMARK
eric@5 49 %token OUTPUT
eric@5 50
eric@30 51 %token AUTHOR
eric@30 52 %token CREATOR
eric@30 53 %token TITLE
eric@30 54 %token SUBJECT
eric@30 55 %token KEYWORDS
eric@30 56
eric@11 57 %type <range> range
eric@11 58 %type <range> image_ranges
eric@11 59 %type <range> page_ranges
eric@11 60
eric@11 61 %type <fp> unit
eric@11 62
eric@32 63 %type <fp> length
eric@9 64
eric@32 65 %type <integer> orientation
eric@32 66
eric@32 67 %type <size> page_size
eric@5 68
eric@5 69 %%
eric@5 70
eric@9 71 statements:
eric@9 72 statement
eric@9 73 | statements statement ;
eric@5 74
eric@9 75 statement:
eric@9 76 input_statement
eric@9 77 | output_statement ;
eric@5 78
eric@5 79
eric@11 80 range:
eric@11 81 INTEGER ELIPSIS INTEGER { $$.first = $1; $$.last = $3; }
eric@11 82 | INTEGER { $$.first = $1; $$.last = $1; } ;
eric@5 83
eric@9 84 image_ranges:
eric@20 85 range { input_images ($1); }
eric@20 86 | image_ranges ',' range { input_images ($3); } ;
eric@5 87
eric@5 88
eric@12 89 input_file_clause:
eric@17 90 FILE_KEYWORD STRING ';' { input_set_file ($2) } ;
eric@5 91
eric@5 92 image_clause:
eric@20 93 IMAGE INTEGER ';' { range_t range = { $2, $2 }; input_images (range); } ;
eric@9 94
eric@9 95 images_clause:
eric@19 96 IMAGES image_ranges ';' ;
eric@5 97
eric@5 98 rotate_clause:
eric@20 99 ROTATE INTEGER ';' { input_set_rotation ($2) } ;
eric@5 100
eric@9 101 unit:
eric@32 102 /* empty */ /* default to INCH */ { $$ = 1.0; }
eric@32 103 | CM { $$ = (1.0 / 25.4); }
eric@32 104 | INCH { $$ = 1.0; } ;
eric@9 105
eric@9 106 length:
eric@11 107 FLOAT unit { $$ = $1 * $2; } ;
eric@9 108
eric@5 109 crop_clause:
eric@9 110 CROP PAGE_SIZE ';'
eric@9 111 | CROP PAGE_SIZE orientation ';'
eric@9 112 | CROP length ',' length ';'
eric@9 113 | CROP length ',' length ',' length ',' length ';' ;
eric@9 114
eric@9 115 orientation:
eric@32 116 PORTRAIT { $$ = 0; }
eric@32 117 | LANDSCAPE { $$ = 1; } ;
eric@32 118
eric@32 119 page_size:
eric@32 120 PAGE_SIZE { $$ = $1; }
eric@32 121 | PAGE_SIZE orientation { if ($2)
eric@32 122 {
eric@32 123 $$.width = $1.height;
eric@32 124 $$.height = $1.width;
eric@32 125 }
eric@32 126 else
eric@32 127 $$ = $1;
eric@32 128 }
eric@32 129 | length ',' length { $$.width = $1; $$.height = $3; } ;
eric@5 130
eric@5 131 size_clause:
eric@32 132 SIZE page_size ';' { input_set_page_size ($2); } ;
eric@9 133
eric@11 134 resolution_clause:
eric@11 135 RESOLUTION FLOAT unit ;
eric@11 136
eric@9 137 modifier_clause:
eric@11 138 rotate_clause | crop_clause | size_clause | resolution_clause;
eric@9 139
eric@9 140 modifier_clauses:
eric@9 141 modifier_clause
eric@9 142 | modifier_clauses modifier_clause;
eric@9 143
eric@9 144 modifier_clause_list:
eric@9 145 '{' modifier_clauses '}' ;
eric@5 146
eric@5 147 part_clause:
eric@19 148 ODD { input_set_modifier_context (INPUT_MODIFIER_ODD); }
eric@19 149 modifier_clause_list ';'
eric@19 150 { input_set_modifier_context (INPUT_MODIFIER_ALL); }
eric@20 151 | EVEN { input_set_modifier_context (INPUT_MODIFIER_EVEN); }
eric@19 152 modifier_clause_list ';'
eric@19 153 { input_set_modifier_context (INPUT_MODIFIER_ALL); } ;
eric@5 154
eric@5 155 input_clause:
eric@12 156 input_file_clause
eric@9 157 | image_clause
eric@9 158 | images_clause
eric@19 159 | part_clause
eric@9 160 | modifier_clause
eric@7 161 | input_clause_list ;
eric@5 162
eric@5 163 input_clauses:
eric@5 164 input_clause
eric@7 165 | input_clauses input_clause ;
eric@7 166
eric@7 167 input_clause_list:
eric@7 168 '{' input_clauses '}' ;
eric@5 169
eric@5 170 input_statement:
eric@8 171 INPUT input_clauses ;
eric@5 172
eric@30 173 pdf_file_attribute:
eric@30 174 AUTHOR STRING { output_set_author ($2); }
eric@30 175 | CREATOR STRING { output_set_creator ($2); }
eric@30 176 | TITLE STRING { output_set_title ($2); }
eric@30 177 | SUBJECT STRING { output_set_subject ($2); }
eric@30 178 | KEYWORDS STRING { output_set_keywords ($2); } ;
eric@30 179
eric@31 180 pdf_file_attribute_list:
eric@31 181 pdf_file_attribute
eric@31 182 | pdf_file_attribute_list pdf_file_attribute ;
eric@31 183
eric@30 184 pdf_file_attributes:
eric@30 185 /* empty */
eric@31 186 | pdf_file_attribute_list ;
eric@30 187
eric@12 188 output_file_clause:
eric@30 189 FILE_KEYWORD STRING { output_set_file ($2); }
eric@48 190 pdf_file_attributes ';' ;
eric@12 191
eric@27 192 label_clause:
eric@27 193 LABEL ';' { page_label_t label = { NULL, '\0' }; output_set_page_label (label); }
eric@27 194 | LABEL STRING ';' { page_label_t label = { $2, '\0' }; output_set_page_label (label); }
eric@27 195 | LABEL CHARACTER ';' { page_label_t label = { NULL, $2 }; output_set_page_label (label); }
eric@27 196 | LABEL STRING ',' CHARACTER ';' { page_label_t label = { $2, $4 }; output_set_page_label (label); } ;
eric@20 197
eric@9 198 page_ranges:
eric@20 199 range { output_pages ($1); }
eric@20 200 | page_ranges ',' range { output_pages ($3); } ;
eric@9 201
eric@5 202 page_clause:
eric@20 203 PAGE INTEGER ';' { range_t range = { $2, $2 }; output_pages (range); } ;
eric@8 204
eric@8 205 pages_clause:
eric@20 206 PAGES page_ranges ';' ;
eric@20 207
eric@20 208 bookmark_name:
eric@20 209 STRING { output_set_bookmark ($1); } ;
eric@20 210
eric@20 211 bookmark_name_list:
eric@20 212 bookmark_name
eric@20 213 | bookmark_name_list ',' bookmark_name ;
eric@5 214
eric@5 215 bookmark_clause:
eric@27 216 BOOKMARK { output_push_context (); bookmark_level++; }
eric@20 217 bookmark_name_list
eric@27 218 output_clause_list ';' { bookmark_level--; output_pop_context (); } ;
eric@5 219
eric@5 220 output_clause:
eric@12 221 output_file_clause
eric@27 222 | label_clause
eric@12 223 | page_clause | pages_clause
eric@12 224 | bookmark_clause
eric@7 225 | output_clause_list ;
eric@5 226
eric@5 227 output_clauses:
eric@5 228 output_clause
eric@7 229 | output_clauses output_clause ;
eric@7 230
eric@7 231 output_clause_list:
eric@20 232 '{' { output_push_context (); }
eric@20 233 output_clauses '}' { output_pop_context (); } ;
eric@5 234
eric@5 235 output_statement:
eric@8 236 OUTPUT output_clauses ;