parser.y

Tue, 01 Jan 2002 06:17:39 +0000

author
eric
date
Tue, 01 Jan 2002 06:17:39 +0000
changeset 31
2cec996b38bc
parent 30
35fad7ec7732
child 32
3aac131058da
permissions
-rw-r--r--

eliminate shift/reduce conflicts in output file attributes.

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