parser.y

Mon, 31 Dec 2001 02:33:50 +0000

author
eric
date
Mon, 31 Dec 2001 02:33:50 +0000
changeset 19
e9bf1ed4f331
parent 18
3de372e4b230
child 20
a1cd8cb9d09e
permissions
-rw-r--r--

*** empty log message ***

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@5 9 double fp;
eric@5 10 char *string;
eric@18 11 page_size_t size;
eric@18 12 range_t range;
eric@5 13 }
eric@5 14
eric@5 15 %token <integer> INTEGER
eric@5 16 %token <fp> FLOAT
eric@5 17 %token <string> STRING
eric@9 18 %token <size> PAGE_SIZE
eric@5 19
eric@7 20 %token ELIPSIS
eric@7 21
eric@9 22 %token CM
eric@9 23 %token INCH
eric@9 24
eric@5 25 %token EVEN
eric@5 26 %token ODD
eric@5 27 %token ALL
eric@5 28
eric@9 29 %token PORTRAIT
eric@9 30 %token LANDSCAPE
eric@9 31
eric@11 32 %token FILE_KEYWORD
eric@5 33 %token IMAGE
eric@9 34 %token IMAGES
eric@5 35 %token ROTATE
eric@5 36 %token CROP
eric@5 37 %token SIZE
eric@11 38 %token RESOLUTION
eric@5 39 %token INPUT
eric@5 40
eric@5 41 %token PAGE
eric@8 42 %token PAGES
eric@5 43 %token BOOKMARK
eric@5 44 %token OUTPUT
eric@5 45
eric@11 46 %type <range> range
eric@11 47 %type <range> image_ranges
eric@11 48 %type <range> page_ranges
eric@11 49
eric@11 50 %type <fp> unit
eric@11 51
eric@11 52
eric@9 53
eric@9 54 %type <fp> length
eric@5 55
eric@5 56 %%
eric@5 57
eric@9 58 statements:
eric@9 59 statement
eric@9 60 | statements statement ;
eric@5 61
eric@9 62 statement:
eric@9 63 input_statement
eric@9 64 | output_statement ;
eric@5 65
eric@5 66
eric@11 67 range:
eric@11 68 INTEGER ELIPSIS INTEGER { $$.first = $1; $$.last = $3; }
eric@11 69 | INTEGER { $$.first = $1; $$.last = $1; } ;
eric@5 70
eric@9 71 image_ranges:
eric@15 72 range { input_images ($1.first, $1.last); }
eric@15 73 | image_ranges ',' range { input_images ($3.first, $3.last); } ;
eric@5 74
eric@5 75
eric@12 76 input_file_clause:
eric@17 77 FILE_KEYWORD STRING ';' { input_set_file ($2) } ;
eric@5 78
eric@5 79 image_clause:
eric@19 80 IMAGE INTEGER ';' { input_images ($2, $2); } ;
eric@9 81
eric@9 82 images_clause:
eric@19 83 IMAGES image_ranges ';' ;
eric@5 84
eric@5 85 rotate_clause:
eric@19 86 ROTATE INTEGER ';' { input_set_rotation ($2) };
eric@5 87
eric@9 88 unit:
eric@11 89 /* empty */ /* default to INCH */ { $$ = 25.4; }
eric@11 90 | CM { $$ = 1.0; }
eric@11 91 | INCH { $$ = 25.4; } ;
eric@9 92
eric@9 93 length:
eric@11 94 FLOAT unit { $$ = $1 * $2; } ;
eric@9 95
eric@5 96 crop_clause:
eric@9 97 CROP PAGE_SIZE ';'
eric@9 98 | CROP PAGE_SIZE orientation ';'
eric@9 99 | CROP length ',' length ';'
eric@9 100 | CROP length ',' length ',' length ',' length ';' ;
eric@9 101
eric@9 102 orientation:
eric@9 103 PORTRAIT
eric@9 104 | LANDSCAPE ;
eric@5 105
eric@5 106 size_clause:
eric@9 107 SIZE PAGE_SIZE ';'
eric@9 108 | SIZE PAGE_SIZE orientation ';'
eric@9 109 | SIZE length ',' length ';' ;
eric@9 110
eric@11 111 resolution_clause:
eric@11 112 RESOLUTION FLOAT unit ;
eric@11 113
eric@9 114 modifier_clause:
eric@11 115 rotate_clause | crop_clause | size_clause | resolution_clause;
eric@9 116
eric@9 117 modifier_clauses:
eric@9 118 modifier_clause
eric@9 119 | modifier_clauses modifier_clause;
eric@9 120
eric@9 121 modifier_clause_list:
eric@9 122 '{' modifier_clauses '}' ;
eric@5 123
eric@5 124 part_clause:
eric@19 125 ODD { input_set_modifier_context (INPUT_MODIFIER_ODD); }
eric@19 126 modifier_clause_list ';'
eric@19 127 { input_set_modifier_context (INPUT_MODIFIER_ALL); }
eric@19 128 | EVEN { input_set_modifier_context (INPUT_MODIFIER_ODD); }
eric@19 129 modifier_clause_list ';'
eric@19 130 { input_set_modifier_context (INPUT_MODIFIER_ALL); } ;
eric@5 131
eric@5 132 input_clause:
eric@12 133 input_file_clause
eric@9 134 | image_clause
eric@9 135 | images_clause
eric@19 136 | part_clause
eric@9 137 | modifier_clause
eric@7 138 | input_clause_list ;
eric@5 139
eric@5 140 input_clauses:
eric@5 141 input_clause
eric@7 142 | input_clauses input_clause ;
eric@7 143
eric@7 144 input_clause_list:
eric@7 145 '{' input_clauses '}' ;
eric@5 146
eric@5 147 input_statement:
eric@8 148 INPUT input_clauses ;
eric@5 149
eric@12 150 output_file_clause:
eric@17 151 FILE_KEYWORD STRING ';' { output_set_file ($2) } ;
eric@12 152
eric@9 153 page_ranges:
eric@15 154 range { output_pages ($1.first, $1.last); }
eric@15 155 | page_ranges ',' range { output_pages ($3.first, $3.last); } ;
eric@9 156
eric@5 157 page_clause:
eric@15 158 PAGE INTEGER ';' { output_pages ($2, $2); }
eric@15 159 | PAGE STRING ',' INTEGER ';' { output_pages ($4, $4); } ;
eric@8 160
eric@8 161 pages_clause:
eric@9 162 PAGES page_ranges ';'
eric@9 163 | PAGES STRING ',' page_ranges ';' ;
eric@5 164
eric@5 165 bookmark_clause:
eric@8 166 BOOKMARK INTEGER ',' STRING ';'
eric@8 167 | BOOKMARK STRING ';' ;
eric@5 168
eric@5 169 output_clause:
eric@12 170 output_file_clause
eric@12 171 | page_clause | pages_clause
eric@12 172 | bookmark_clause
eric@7 173 | output_clause_list ;
eric@5 174
eric@5 175 output_clauses:
eric@5 176 output_clause
eric@7 177 | output_clauses output_clause ;
eric@7 178
eric@7 179 output_clause_list:
eric@7 180 '{' output_clauses '}' ;
eric@5 181
eric@5 182 output_statement:
eric@8 183 OUTPUT output_clauses ;