parser.y

Tue, 01 Jan 2002 10:16:50 +0000

author
eric
date
Tue, 01 Jan 2002 10:16:50 +0000
changeset 32
3aac131058da
parent 31
2cec996b38bc
child 48
3d0be1c1c1b2
permissions
-rw-r--r--

added start of page size support.

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