parser.y

Tue, 01 Jan 2002 03:46:08 +0000

author
eric
date
Tue, 01 Jan 2002 03:46:08 +0000
changeset 27
7a28031fe457
parent 20
a1cd8cb9d09e
child 30
35fad7ec7732
permissions
-rw-r--r--

change 'format' to 'label', add character type, track bookmark level.

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@11 50 %type <range> range
eric@11 51 %type <range> image_ranges
eric@11 52 %type <range> page_ranges
eric@11 53
eric@11 54 %type <fp> unit
eric@11 55
eric@11 56
eric@9 57
eric@9 58 %type <fp> length
eric@5 59
eric@5 60 %%
eric@5 61
eric@9 62 statements:
eric@9 63 statement
eric@9 64 | statements statement ;
eric@5 65
eric@9 66 statement:
eric@9 67 input_statement
eric@9 68 | output_statement ;
eric@5 69
eric@5 70
eric@11 71 range:
eric@11 72 INTEGER ELIPSIS INTEGER { $$.first = $1; $$.last = $3; }
eric@11 73 | INTEGER { $$.first = $1; $$.last = $1; } ;
eric@5 74
eric@9 75 image_ranges:
eric@20 76 range { input_images ($1); }
eric@20 77 | image_ranges ',' range { input_images ($3); } ;
eric@5 78
eric@5 79
eric@12 80 input_file_clause:
eric@17 81 FILE_KEYWORD STRING ';' { input_set_file ($2) } ;
eric@5 82
eric@5 83 image_clause:
eric@20 84 IMAGE INTEGER ';' { range_t range = { $2, $2 }; input_images (range); } ;
eric@9 85
eric@9 86 images_clause:
eric@19 87 IMAGES image_ranges ';' ;
eric@5 88
eric@5 89 rotate_clause:
eric@20 90 ROTATE INTEGER ';' { input_set_rotation ($2) } ;
eric@5 91
eric@9 92 unit:
eric@11 93 /* empty */ /* default to INCH */ { $$ = 25.4; }
eric@11 94 | CM { $$ = 1.0; }
eric@11 95 | INCH { $$ = 25.4; } ;
eric@9 96
eric@9 97 length:
eric@11 98 FLOAT unit { $$ = $1 * $2; } ;
eric@9 99
eric@5 100 crop_clause:
eric@9 101 CROP PAGE_SIZE ';'
eric@9 102 | CROP PAGE_SIZE orientation ';'
eric@9 103 | CROP length ',' length ';'
eric@9 104 | CROP length ',' length ',' length ',' length ';' ;
eric@9 105
eric@9 106 orientation:
eric@9 107 PORTRAIT
eric@9 108 | LANDSCAPE ;
eric@5 109
eric@5 110 size_clause:
eric@9 111 SIZE PAGE_SIZE ';'
eric@9 112 | SIZE PAGE_SIZE orientation ';'
eric@9 113 | SIZE length ',' length ';' ;
eric@9 114
eric@11 115 resolution_clause:
eric@11 116 RESOLUTION FLOAT unit ;
eric@11 117
eric@9 118 modifier_clause:
eric@11 119 rotate_clause | crop_clause | size_clause | resolution_clause;
eric@9 120
eric@9 121 modifier_clauses:
eric@9 122 modifier_clause
eric@9 123 | modifier_clauses modifier_clause;
eric@9 124
eric@9 125 modifier_clause_list:
eric@9 126 '{' modifier_clauses '}' ;
eric@5 127
eric@5 128 part_clause:
eric@19 129 ODD { input_set_modifier_context (INPUT_MODIFIER_ODD); }
eric@19 130 modifier_clause_list ';'
eric@19 131 { input_set_modifier_context (INPUT_MODIFIER_ALL); }
eric@20 132 | EVEN { input_set_modifier_context (INPUT_MODIFIER_EVEN); }
eric@19 133 modifier_clause_list ';'
eric@19 134 { input_set_modifier_context (INPUT_MODIFIER_ALL); } ;
eric@5 135
eric@5 136 input_clause:
eric@12 137 input_file_clause
eric@9 138 | image_clause
eric@9 139 | images_clause
eric@19 140 | part_clause
eric@9 141 | modifier_clause
eric@7 142 | input_clause_list ;
eric@5 143
eric@5 144 input_clauses:
eric@5 145 input_clause
eric@7 146 | input_clauses input_clause ;
eric@7 147
eric@7 148 input_clause_list:
eric@7 149 '{' input_clauses '}' ;
eric@5 150
eric@5 151 input_statement:
eric@8 152 INPUT input_clauses ;
eric@5 153
eric@12 154 output_file_clause:
eric@17 155 FILE_KEYWORD STRING ';' { output_set_file ($2) } ;
eric@12 156
eric@27 157 label_clause:
eric@27 158 LABEL ';' { page_label_t label = { NULL, '\0' }; output_set_page_label (label); }
eric@27 159 | LABEL STRING ';' { page_label_t label = { $2, '\0' }; output_set_page_label (label); }
eric@27 160 | LABEL CHARACTER ';' { page_label_t label = { NULL, $2 }; output_set_page_label (label); }
eric@27 161 | LABEL STRING ',' CHARACTER ';' { page_label_t label = { $2, $4 }; output_set_page_label (label); } ;
eric@20 162
eric@9 163 page_ranges:
eric@20 164 range { output_pages ($1); }
eric@20 165 | page_ranges ',' range { output_pages ($3); } ;
eric@9 166
eric@5 167 page_clause:
eric@20 168 PAGE INTEGER ';' { range_t range = { $2, $2 }; output_pages (range); } ;
eric@8 169
eric@8 170 pages_clause:
eric@20 171 PAGES page_ranges ';' ;
eric@20 172
eric@20 173 bookmark_name:
eric@20 174 STRING { output_set_bookmark ($1); } ;
eric@20 175
eric@20 176 bookmark_name_list:
eric@20 177 bookmark_name
eric@20 178 | bookmark_name_list ',' bookmark_name ;
eric@5 179
eric@5 180 bookmark_clause:
eric@27 181 BOOKMARK { output_push_context (); bookmark_level++; }
eric@20 182 bookmark_name_list
eric@27 183 output_clause_list ';' { bookmark_level--; output_pop_context (); } ;
eric@5 184
eric@5 185 output_clause:
eric@12 186 output_file_clause
eric@27 187 | label_clause
eric@12 188 | page_clause | pages_clause
eric@12 189 | bookmark_clause
eric@7 190 | output_clause_list ;
eric@5 191
eric@5 192 output_clauses:
eric@5 193 output_clause
eric@7 194 | output_clauses output_clause ;
eric@7 195
eric@7 196 output_clause_list:
eric@20 197 '{' { output_push_context (); }
eric@20 198 output_clauses '}' { output_pop_context (); } ;
eric@5 199
eric@5 200 output_statement:
eric@8 201 OUTPUT output_clauses ;